1

I have a group of LinkedIn share buttons (supplied via LinkedIn) throughout my blog pages, that I am trying to align horizontally inline with other share buttons. I have tried most everything so far, and have decided to - ineffectively - try attribute selectors to make the buttons do what I want. Here is the button code:

<script src="//platform.linkedin.com/in.js" type="text/javascript">
  <span class="IN-widget" style="line-height: 1; vertical-align: baseline; display: inline-block; text-align: center;">

And the attempted CSS:

span[class="IN-widget"] { display: inline-block; }

Can anyone tell me if I'm misstepping here? To my knowledge, every share button has this common class as part of its source code, so this should do the trick in introducing the desired styling. Any help would be much appreciated!

Preview
  • 35,317
  • 10
  • 92
  • 112
TCharb
  • 444
  • 1
  • 6
  • 15
  • What type of display property your parent element has? – karthick May 19 '17 at 02:34
  • Can you post some more markup? – karthick May 19 '17 at 02:35
  • @karthick oddly enough, the display by default is already "inline-block." However, leaving this alone and taking the code out entirely (assuming the element should align itself properly) does not work. I'm absolutely puzzled. The vertical-align value is "baseline", should that make a difference? – TCharb May 19 '17 at 02:37
  • @TCharb markup means HTML which is what we need to assess your situation otherwise this is a crapshoot. If you have any doubts as to what constitutes a proper demo, refer to this [mcve]. – zer00ne May 19 '17 at 02:40
  • What is the inline `style=` property on the element (that you've shown as "....")? – nnnnnn May 19 '17 at 02:43
  • @nnnnnn added the styling, and hopefully enough markup for this specific example – TCharb May 19 '17 at 02:45
  • what is the display property of the parent element ? and what is the style of the children element?. If your parent is a flex element with column flow even if you put display:inline-block; it wont work. Like @zer00ne mentioned the code doesn't reveal much info. – karthick May 19 '17 at 02:50
  • Why would you use attribute selectors to match the element's class? There's a syntax specifically for that: `span.IN-widget`. – JLRishe May 19 '17 at 02:57
  • @JLRishe - I've tried that and it has no effect, unfortunately. As for the button elements, the solution I have currently (that is stripped during testing) is compiling of list of ID's for each share button, displaying them inline-block. THIS works. On the topic of additional markup, I myself am still learning and not the best at discerning HTML right now. I'm working with a supplied template, and using Web Inspector seems to reveal that the parent element is in a column flow. If someone could confirm that (www.tylercharboneauprofessional.com), I'd appreciate it. – TCharb May 19 '17 at 03:07
  • @TCharb As far as I can tell, that page doesn't contain any of the markup from your question. – JLRishe May 19 '17 at 04:38
  • @JLRishe oops, sorry about that. For yourself and anyone interested, here is the updated URL: https://tylercharboneauprofessional.com/international-pulse/your-guide-to-the-french-election – TCharb May 19 '17 at 17:08

2 Answers2

1

Edit

Second Edit: .IN-widget is dynamically generated and doesn't exist in markup. So use 'script[type^=IN]' as your selector see edited code below

Having one per page and using the id would be inefficient, so we need to use JavaScript/jQuery instead of CSS. One major limitation of CSS is it's inability to control a selected element's parent and ancestors.

Details are commented in demo

Demo

/* The selector means:
|| Find a <script> tag that has a [type] attribute 
|| that's value begins ^= with the string of "IN"
*/
/* The .closest() method will find the ancestor closest 
|| to the targeted selector. So here it's saying:
|| (Previous comment here)
|| Find the closest ancestor of the selected element 
|| which has the classes .sqs-block, .code-block, 
|| and .sqs-block-code.(grandma)
|| Use .css() method to change grandma's styles.
|| The extra style top:3px is just to push the icon down
|| down so that it is inline with FB and Twit icons.
*/

$('script[type^=IN]').closest('.sqs-block.code-block.sqs-block-code').css({
  'display': 'inline-block',
  'top': '3px'
});

$('.fb-share-button').closest('.sqs-block.code-block.sqs-block-code').css('display', 'inline-block');

$('.twitter-share-button').closest('.sqs-block.code-block.sqs-block-code').css('display', 'inline-block');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="sqs-block code-block sqs-block-code">
  <div class="sqs-block-content">
    <div class="fb-share-button fb_iframe_widget"><span style="vertical-align: bottom; width: 58px; height: 20px;"><iframe width="1000px" height="1000px" frameborder="0" allowtransparency="true" allowfullscreen="true" scrolling="no" src="https://www.facebook.com/v2.8/plugins/share_button.php?app_id=&amp;channel=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F0F7S7QWJ0Ac.js%3Fversion%3D42%23cb%3Df836e17d67a66%26domain%3Dtylercharboneauprofessional.com%26origin%3Dhttps%253A%252F%252Ftylercharboneauprofessional.com%252Ff23efc0724f4838%26relation%3Dparent.parent&amp;container_width=39&amp;href=https%3A%2F%2Fwww.tylercharboneauprofessional.com%2Finternational-pulse%2Fyour-guide-to-the-french-election%2F&amp;layout=button&amp;locale=en_US&amp;mobile_iframe=false&amp;sdk=joey" style="border: none; visibility: visible; width: 58px; height: 20px;" class=""></iframe></span>
    </div>
  </div>
</div>

<div class="sqs-block code-block sqs-block-code">
  <div class="sqs-block-content">

    <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" class="twitter-share-button twitter-share-button-rendered twitter-tweet-button" style="position: static; visibility: visible; width: 60px; height: 20px;" src="https://platform.twitter.com/widgets/tweet_button.5b6375bb17bd9edb2f4e7f8f12971999.en.html#dnt=true&amp;id=twitter-widget-0&amp;lang=en&amp;original_referer=https%3A%2F%2Ftylercharboneauprofessional.com%2Finternational-pulse%2Fyour-guide-to-the-french-election&amp;size=m&amp;text=Your%20Guide%20to%20the%20French%20Presidential%20Election%2C%20and%20Why%20it%20Matters%20%E2%80%94%20Tyler%20Charboneau&amp;time=1495223324688&amp;type=share&amp;url=https%3A%2F%2Ftylercharboneauprofessional.com%2Finternational-pulse%2Fyour-guide-to-the-french-election"></iframe>

  </div>
</div>

<div class="sqs-block code-block sqs-block-code">
  <div class="sqs-block-content">

    <span class="IN-widget" style="line-height: 1; vertical-align: baseline; display: inline-block; text-align: center;"><span style="padding: 0px !important; margin: 0px !important; text-indent: 0px !important; display: inline-block !important; vertical-align: baseline !important; font-size: 1px !important;">
<span><a href="javascript:void(0);"><span>in</span><span><span></span><span>Share</span></span>
    </a>
    </span>
    </span>
    </span>
    <script type="IN/Share"></script>
  </div>
</div>

Each share button has been stripped of ids and are as generic as they could be for demonstration purposes. On each page, include the jQuery inside <script> tags and place that <script> block before the closing </body> tag. Any other modification to HTML is unnecessary. A better way is to use an external script and have each page point to that .js file. To save a http request you could add that those 3 lines to an existing .js script but you'll need to be familiar with jQuery/JavaScript to do so safely.

Explination

This template (like all templates of this nature, Squarespace, Word-Press, etc.) is a cluster-fu#@ of HTML. If you find a particular element and you need to actually move it, or behave in layout, or adhere to a flow, you'll need to move up the DOM hierarchy until you find the ancestor that has siblings. For example:

 <div class='great-great-great-aunt'>
     <!--Many levels of cousins-->
        <span class='fb'>Facebook I need to liked!</span>
     <!--...</div>...-->
   </div>
   <div class='great-great-grandma'>
      <div class='great-grandma'>  
         <div class='grandma'>
            <div class='mom'>
               <span class='linkedIn'>Hey I'm a corporate clone! How about you?</span>
            </div>
          </div>
       </div>
     </div>

The target element in this example is .linkedIn (Note the . preceding the className, that is the proper syntax for a class selector in CSS and jQuery.) On the surface, that is the element you see in the browser. It's "cousin" icon is .fb, meaning that as far as relations go they are not siblings as it appears so when rendered in browser. They do not share the same parents as siblings would so styles that concern position, flow, layout, etc. will not affect a cousin. Cousins are isolated from each other because they are nested within their own parent element as well as any ancestor elements. Therefore you must find the ancestor of .linkedIn that has a sibling that is the ancestor of .fb. Confused? Me too.

Solution

Here is grandma:

 #block-yui_3_17_2_1_1493318168221_183886

A # means id which is by far the easiest and most accurate way of locating a specific element. The reason id is the best means of selecting an element is because an id is unique on any given document (i.e. single webpage).

This is the ruleset that should bring that linkedIn icon inline with the Twitter and Facebook icons:

 #block-yui_3_17_2_1_1493318168221_183886 { display: inline-block; top:3px}
zer00ne
  • 41,936
  • 6
  • 41
  • 68
  • Thanks for your answer. Actually, that's the exact same thing I'm doing right now (although the code is presently removed). I have an exhaustive list of ID's for every LinkedIn button present throughout the blog posts, and targeting those are sufficient in positioning the element. But sadly, it is a cluster fu@$ of bloated code. I don't want the browser parsing all of that – TCharb May 19 '17 at 19:27
  • One share button per page, about 15 or so ID's in one list in the CSS, for that one styling rule. Looks ugly, even if it's seemingly the only thing getting the job done – TCharb May 19 '17 at 19:39
  • @TCharb ok review the edit and try the script on your site. If you have any questions I'll be back later, good luck. – zer00ne May 19 '17 at 20:37
  • it seems to work for the Twitter and Facebook buttons, but doesn't for the LinkedIn buttons. I did notice that the script for the LinkedIn portion has some different syntax (brackets, colons, plus the 'top' rule) from the other script portions. Is there a reason for this? Thanks! – TCharb May 20 '17 at 02:46
  • @TCharb When mentioned LinkedIn being different you reminded me that some widgets do not exist until latter. It appears that the element `.IN-widget` doesn't exist yet. See second edit and new code and comments. – zer00ne May 20 '17 at 03:45
  • oddly enough with the edited scripts put into place (and I assume they were in the right place, tried them in the head and the end of the body), nothing was effected. They remained displayed in a vertical column. Thoughts? I do have to add script tags in around the code, will one set suffice for all three scripts? – TCharb May 20 '17 at 23:38
  • I take that back, we're absolutely good to go! Thank you a ton for providing this to me, really consolidates my CSS file. I had to add quotes around the IN, and took the top rule away, and that did that trick. Thrilled :) – TCharb May 21 '17 at 00:58
  • Great! I'm glad you got that irritating icon inline, happy coding, sir. – zer00ne May 21 '17 at 01:04
0

Linkedin Share Example Check this jsfiddle: https://jsfiddle.net/wrahvvr2/

JS:

<script src="//platform.linkedin.com/in.js" type="text/javascript">
  lang: en_US
</script>
<script type="IN/Share" data-counter="top"></script>

CSS(this should target the share button):

span[class="IN-widget"] {
  display: inline-block;
  background: red;
}

BTW:

You have an open script tage:

<script src="//platform.linkedin.com/in.js" type="text/javascript">

You should close it:

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
Community
  • 1
  • 1
Dalin Huang
  • 11,212
  • 5
  • 32
  • 49
  • Definitely true, but would this cause the issue OP is describing? – JLRishe May 19 '17 at 04:37
  • @JLRishe yes, I updated with a example, been work with linkedin share many time, never had an issue – Dalin Huang May 19 '17 at 05:50
  • @Daniel H - no dice, unfortunately. However, making the background red did act as a proof of concept that the selector was valid. It altered the color accordingly on all pages. However, those puppies aren't movin' into position. – TCharb May 19 '17 at 17:36