Jeremy Ahn
Jeremy Ahn

Reputation: 335

Facebook Like button doesn't align with other social buttons. Used CSS to fix that but breaks in other browsers

CSS:

.share {
    width: 150px;
    height: 20px;
    background: #000;
    float: right;
    white-space: nowrap;
    padding-top: 5px;
    padding-bottom: 5px;
    padding-left: 3px;
    background-color:rgba(255, 255, 255, 0.5);
    border-bottom-left-radius: 5px;
    box-shadow: 0px 0px 10px #888;
    vertical-align: top;
}

HTML:

<div class="share">
    <div class="fb-like" data-href="http://bronies.info/" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true" style="width:47px; overflow:hidden; top:-3px; left:3px;"></div>
    <a href="https://twitter.com/share" class="twitter-share-button" data-text="Wondered what the bronies were all about?" data-count="none">Tweet</a>
    <div class="g-plusone" data-size="medium" data-annotation="inline" data-width="300" style="width:32px; overflow:hidden;"></div>
</div>

Chrome, Safari:

Chrome and Safari

Internet Explorer, Firefox, and Opera:

Internet Explorer, Firefox, and Opera

If you can see what I did in my HTML style property, I used top:-3px, and I did this before testing my website out on other browsers (Chrome is my primary web browser). I used top because a quick Google search led me a page instructing me to do so. Now that this solution doesn't work, how would I adjust it to align and work on all web browsers?

Upvotes: 12

Views: 13688

Answers (10)

David
David

Reputation: 4847

I was having the same problem with mobile browsers and solved it with the following:

.fb-like span{
    vertical-align: initial !important;
}

Upvotes: 0

Văn Quyết
Văn Quyết

Reputation: 2526

This is my solution: Wrap each social button by an inline-block element. And each social button has display attribute is block

HTML

<div class="social-share clearfix">
    <div class="social-share-item">
        <div id="fb-like" class="fb-like" data-href="{url}" data-layout="button_count" data-size="small" data-action="like" data-show-faces="true" data-share="true"></div>
    </div>
    <div class="social-share-item">
        <a class="twitter-share-button" href="https://twitter.com/intent/tweet">Tweet</a>
    </div>
    <div class="social-share-item">
        <div class="g-plus" data-action="share"></div>
    </div>
</div>

CSS

.social-share {
    display: block;
    background: #f9f9f9;
    padding: 0.2em 0.4em;
    margin-top: 1em;
}
.social-share-item > * {
    display: block;
    float: left;
}
.social-share-item {
    display: inline-block;
}

Upvotes: 0

Jimbo Jones
Jimbo Jones

Reputation: 563

Adding the following style to my css aligned the facebook share button with other social icons.

 .fb_iframe_widget{vertical-align:top;}

Upvotes: 0

jruzafa
jruzafa

Reputation: 4276

My solution is:

.fb-like.fb_iframe_widget span{
  vertical-align: top !important;
}

Upvotes: 12

uowaep
uowaep

Reputation: 41

Try adding this to your "share" div. I don't know how it looks on other browsers but it seems to make things line up in Chrome.

font-size: 0.1px;

Upvotes: 1

Peter
Peter

Reputation: 1

I ended up wrapping each button in their own div, and setting the div to

display:inline-block; white-space: nowrap; vertical-align:top;

and then added the following to the facebook specific div:

#facebookButton > div > span {vertical-align:baseline;}

Upvotes: 0

Holly
Holly

Reputation: 3739

I added vertical-align: text-bottom; to the <span> enclosing each button (to match what Facebook does), and everything lines up perfectly in Chrome, Firefox, and IE. (My spans also have display: inline-block if that matters.)

Upvotes: 1

jimp
jimp

Reputation: 17477

You should remove top:-3px; completely. Because you don't have position:relative;, which is required (something other than static) to activate positioning, then Webkit (Chrome, Safari) is correctly ignoring it, but Internet Explorer, Firefox, and Opera are mistakenly honoring it (-3px shift).

EDIT:

From the comments...
Facebook's script adds a <span> inside your <div> which then triggers a CSS rule they also provide: .fb_iframe_widget span { vertical-align: text-bottom; }. I suggest adding float: left; to all three of your <div> tags so they will not share a common flow (or baseline).

Upvotes: 10

syrkull
syrkull

Reputation: 2344

try using top: auto and look at the result, check and see if it is in the same position in all browsers. If it needs to be aligned virtually then use bottom: 3px; (or any appropriate value that suites your need)

  • do not forget you have to position:relative; to your code

so the final styling for the facebook button should look something like this :

width:47px; overflow:hidden;position:relative; top:auto;  bottom:3px; left:3px;

Upvotes: 3

Night2
Night2

Reputation: 1153

I suggest using display: inline-block; and vertical-align: middle; for container of Facebook button ...

Upvotes: 1

Related Questions