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!
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.
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% .
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.
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.
use nowrap
ul {
white-space: nowrap;
width: 100%;
list-style-type: none;
margin: auto;
overflow-x: scroll;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With