Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I keep a horizontal unordered list from breaking?

Tags:

html

css

I'm trying to create a list of thumbnails that I can scroll horizontally, but it breaks no matter what I do.

This is what I have now

http://jsfiddle.net/EXCf3/

ul{
    width: 100%;
     list-style-type: none;
    margin: auto;
    overflow-x: scroll;
}
li{
    height: 100px;
    width: 100px;
    border: 1px solid red;
    display: inline-block;

}

Any ideas on what I'm doing wrong? Thanks!

like image 699
Smeegs Avatar asked Jul 18 '13 13:07

Smeegs


People also ask

How do I display an unordered list horizontally?

If you want to make this navigational unordered list horizontal, you have basically two options: Make the list items inline instead of the default block. .li { display: inline; } This will not force breaks after the list items and they will line up horizontally as far as they are able. Float the list items.

How do you horizontally align a UL item?

The steps are as follows: Float the wrapper to the left and give it a width of 100% to make it take up the full viewport width. Float both the ul and the li to the left and don't give them any width to make them adjust to their content. Give the ul a position: relative of left: 50% .

How do you make Li appear on the same line?

If you want to align list items(li) horizontally without affecting list style use below mentioned properties. ul{ display:flex; gap:30px; } gap:30px this used to set the gap between the list items. Show activity on this post.


2 Answers

Add white-space: nowrap on the ul:

ul {
    width: 100%;
    list-style-type: none;
    margin: auto;
    overflow-x: scroll;
    white-space: nowrap;
}

Demonstration.

Explanation:

I used the white-space property because it gives me the potential to handle what to do with the white space left in the object so I said it to make no wrap of that white space occuring the ul and display all of them in one line.

like image 95
Mohammad Areeb Siddiqui Avatar answered Sep 28 '22 10:09

Mohammad Areeb Siddiqui


use nowrap

ul {

white-space: nowrap;
width: 100%;
list-style-type: none;
margin: auto;
overflow-x: scroll;

   }
like image 25
Hafiz Mohammed Avatar answered Sep 28 '22 12:09

Hafiz Mohammed