I'm trying to spread a list of <li>
's aligned horizontally using float:left
across my <ul>
.
Does anyone have any idea how this is done?
I'm trying to spread a list of <li>
's aligned horizontally using float:left
across my <ul>
.
Does anyone have any idea how this is done?
Is there some reason why you can't just set them to display: inline;
(or inline-block
)? For example:
inline-block
instead! "awkward space between items" is caused by not re-setting margins and paddings… –
Tess The answer is to use display: table;
on the <ul>
element and display: table-cell;
on the <li>
elements.
You can use display: inline-block;
it works in modern browsers.
Example: http://jsfiddle.net/joar/ELpDD/
As feela said in the comments to #7131346,
[…] "awkward space between items" is caused by not re-setting margins and paddings…
Float left and divide the width of the ul
over de number of li
s I think is what you are after. Have a look here: http://jsfiddle.net/b2nsW/
HTML:
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
CSS:
ul {
width: 250px;
background: red;
padding: 0;
margin: 0;
overflow: auto;
}
li {
width: 20%;
float: left;
background: green;
margin: 2.5%;
}
li {
display: inline-block;
}
ul{
text-align: center;
}
Then adjust the padding or margins of the li elements to spread them across less or more across the ul.
© 2022 - 2024 — McMap. All rights reserved.
float: left;
sounds good. What HTML/CSS do you have so far? – Brigandage