Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display icons and text on the same line

Tags:

html

css

I'm trying to get the text (Home, About Us, Cheese) etc to display to the right of the social media icons, so that the base of the text is aligned with the base of the icons and they appear on the same line.

How do I do this?

My code is in fiddle here http://jsfiddle.net/pnX3d/

    <div class="grid_5" id="social_icons">
        <a href="http://www.facebook.com/print3dexpert" target="blank"><img src="img/facebook.png" alt="Click to visit us on Facebook"></a>
        <a href="http://www.twitter.com/print3dexpert" target="blank"><img src="img/twitter.png" alt="Click to visit us on Twitter"></a>
        <a href="http://pinterest.com/print3dexpert" target="blank"><img src="img/pinterest.png" alt="Click to visit us on Pininterest"></a>
        <a href="#"><img src="img/email.png" title="Click to contact us" alt="Contact us"></a>

    </div>

    <nav class="topmenu omega">
        <ul>
        <li><a href="#">Home</a> |</li>
        <li><a href="#">About Us</a> |</li>
        <li><a href="#">Cheeses</a></li>
        </ul>
    </nav>
like image 830
Dano007 Avatar asked Sep 14 '13 06:09

Dano007


People also ask

How do I align text and icons on the same line?

If you want to make a text appear vertically aligned next to a Font Awesome icon, you can use the CSS vertical-align property set to “middle” and also, specify the line-height property. Change the size of the icon with the font-size property.

How do I put text and icons side by side?

display: To display text and icons side by side, we will use the display: flex property. float: To set the icon on the right side of the div, we use float: right property.

How do I display a picture and text in the same line?

Entire trick is to use float: left; CSS property on the img element and all the text will automatically wrap around that image. So if you want to align text and image in the same line in HTML like this... In short that is it.

How do I display content on the same line?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.


2 Answers

I have achieved that with the following code:

.container-header{
    line-height: 1.22;
}
#social_icons {
    padding: .5em;
    display: inline-block;
}

.topmenu li {
     display:inline-block;
     font-size: 1.5em;
     text-align: right;
}
.topmenu.omega{
     float:right;
}
ul{
     margin: 0;
}
li>a
{
    font-size: 20px;
}
<div class="container-header">
  <div class="grid_5" id="social_icons">
	<a href="http://fontawesome.io/icon/address-book/" target="blank"><img src="img/facebook.png" alt="Facebook"></a>
	<a href="http://www.twitter.com/print3dexpert" target="blank"><img src="img/twitter.png" alt="Twitter"></a>
	<a href="http://pinterest.com/print3dexpert" target="blank"><img src="img/pinterest.png" alt="Pininterest"></a>
	<a href="#"><img src="img/email.png" title="Click to contact us" alt="Contact us"></a>

  </div>

  <nav class="topmenu omega">
	<ul>
	<li><a href="#">Home</a> |</li>
	<li><a href="#">About Us</a> |</li>
	<li><a href="#">Cheeses</a></li>
	</ul>
  </nav>
</div>
like image 121
Mamun Avatar answered Sep 23 '22 05:09

Mamun


Add float: left to #social_icons and .topmenu li.

Here's a demo: http://jsfiddle.net/ZsJbJ/.

Hope that helps!

like image 22
Kai Feller Avatar answered Sep 23 '22 05:09

Kai Feller