list items horizontally rather than vertical using <ul><li> tags

css
11,543

Solution 1

.jobs {
list-style-type: none;
padding:0;
margin:0;
}

.jobs > li {
display: inline-block;
}

Something like that perhaps?

Solution 2

You can make your list elements align horizontally by specifying the display property with inline.

An example of this below:

li{display:inline}
<ul>
   <li>1</li>
   <li>2</li>
   <li>3</li>
</ul>

Solution 3

You can use float but you need to clear after it or will have layout problems.

Example :

.jobs {
  list-style: none;
}

.jobs li {
  float: left;
  margin-left: 12px;
}

.jobs::after {
  content: "";
  display: table;
  clear: both;
}
<ul class="jobs">
  <li>
    <img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />

    <div class="company">desc1</div>
  </li>

  <li>
    <img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />

    <div class="company">desc2</div>
  </li>
</ul>

Solution 4

use

li {
    float: left;
}

for floating the list elements to the left.

Share:
11,543
Venkat
Author by

Venkat

A Tech life never ends....Learn till you die.

Updated on November 28, 2022

Comments

  • Venkat
    Venkat over 1 year

    I have this web page

    http://hashgurus.com/htmlpage7.html which lists items in

    <li>    </li>  
    

    vertically. But I need it to display horizontally. Which element in css should I use to display items horizontally rather than vertically?

    this is the code:

    <ul class="jobs">
            <li>
                <img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
    
                    <div class="company">desc1</div></li>
    
            <li>
                <img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
    
                    <div class="company">desc2</div></li>
        </ul>
    

    demo page: http://hashgurus.com/htmlpage7.html

  • Vitorino fernandes
    Vitorino fernandes almost 9 years
    first thing you have not closed ul tag and second the inline elements gives extra whitespace between them jsfiddle.net/vg1f4nku so it will not work if OP gives width:50%