Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inline-block aligning vertical by default

I am making a social media bar at the bottom of a website and would like for all of the social media icons to line up horizontally. I have a parent div that encases the social media icon divs. I am trying to not only center the parent div on the page but also center all of the social media icons within that div.

When I use the inline-block tag all of my social media icons align vertically in the middle of the parent div. I have also tried floating them but cannot seem to figure out how to center them with that format either.

Any help would be greatly appreciated.

HTML:

<div id="socialcontainer">
    <div class="facebook"><a href="https://facebook.com/"></a></div>
    <div class="twitter"><a href="https://twitter.com/"></a></div>
    <div class="google"><a href="https://google.com/"></a></div>
    <div class="linkedin"><a href="https://linkedin.com/"></a></div>
</div>

CSS:

#socialcontainer {
width: 100%;
margin: 0px auto;
text-align: center;
}


.facebook a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/facebook_dark.png');
}

.facebook a:hover {
background: url('../img/socialicons/facebook_active.png');
}

.twitter a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/twitter_dark.png');
}


.twitter a:hover {
    background: url('../img/socialicons/twitter_active.png');
}

.google a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/google_dark.png');
}    

.google a:hover {
    background: url('../img/socialicons/google_active.png');
}

.linkedin a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/in_dark.png');
}

.linkedin a:hover {
    background: url('../img/socialicons/in_active.png');
}
like image 467
Hunter Sneed Avatar asked May 06 '26 12:05

Hunter Sneed


2 Answers

You need to assign the inline-block to the DIV tags that enclose the a tags like the below:

#socialcontainer > div{ display: inline-block;}

like image 143
Harry Avatar answered May 08 '26 09:05

Harry


Try this: add to the CSS of each enveloping <div> the following attribute: display:inline.

like image 22
ygesher Avatar answered May 08 '26 11:05

ygesher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!