I have a parent <ol>
and couple of <li>
items in that.
<ol style='width=800px;display :block;float:left;'> <li style='display :block;float:left;'> Item 1 </li> <li style='display :block;float:left;'> Item 2 </li> <li style='display :block;float:left;'> Item 3 </li> <li style='display :block;float:left;'> Item 4 </li> </ol>
Is there any way my list item can be arranged in a way where it will equally divide the parent width (800px), and each item will have the same amount of width? I.e. each <li>
will take 200px width.
I don’t want to hardcode the value. Is there any style attribute which will do that?
I dont want to hardocode the width like 20 % or something because the list items are dynamically added.it may be 4 or 5 or 6 sometimes
17. Bookmark this question. Show activity on this post. My understanding is that width: 100% lets the element's width be the same as its parent's, whereas width: inherit does that only when the parent's width is explicitly specified.
What should be the table width, so that the width of a table adjust to the current width of the browser window? The table width should be 100% so that the width of a table adjusts to the current width of the browser window.
Try this: http://jsfiddle.net/QzYAr/
display: table-cell
: Is there a disadvantage of using `display:table-cell`on divs? table-layout: fixed
ensures equal width li
elements.CSS:
ol { width: 400px; /*width: 800px;*/ display: table; table-layout: fixed; /* the magic dust that ensures equal width */ background: #ccc } ol > li { display: table-cell; border: 1px dashed red; text-align: center }
HTML:
<ol> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> </ol>
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