Here is an example code for what I mean:
HTML
<ul class="table">
<li class="table-cell"></li>
<li class="table-cell"></li>
<li class="table-cell"></li>
<li class="table-cell"></li>
</ul>
CSS:
.table {
display: table;
}
.table-cell {
display: table-cell;
width: 25%;
}
Q: How can I make the third and forth <li>
(table cells) display on new row with width: 50% each?
Q: Is there a way using only CSS and not jQuery or Javascript?
Setting display to table makes the element behave like a table. So you can make a replica of an HTML table without using the table element and corresponding elements such as tr and td . For example, in HTML, you can make a table with the <table> element and also a <div> , or any container of your choice.
<tr>: The Table Row element. The <tr> HTML element defines a row of cells in a table.
An inline element will accept margin and padding, but the element still sits inline as you might expect. Margin and padding will only push other elements horizontally away, not vertically.
Double-click the table name in the grid. Select names of tables in the grid, then right-click and select Display Rows from the shortcut menu, or select Display Rows from the File menu.
The simple answer is: you can't, at least not with lists. Adjacent elements with their display set to table-cell
are treated as belonging to the same row (even if a row element is not provided, an anonymous one will be created for you). Since lists aren't allowed to contain any other tags between the ul and the li, this simply isn't possible with lists. You'll have to use either different markup or different styling.
Here are your options if you don't want to modify the markup.
Inline-block on the list items: http://jsfiddle.net/XNq74/1/
li {
display: inline-block; /* could use floats here instead */
width: 40%;
}
CSS columns would be a reasonable choice: http://jsfiddle.net/XNq74/
ul {
columns: 2;
}
http://caniuse.com/#feat=multicolumn
Flexbox would also work and can be used in combination with inline-block: http://jsfiddle.net/XNq74/2/
ul {
display: flex;
flex-flow: row wrap;
}
li {
flex: 1 1 40%;
}
http://caniuse.com/#search=flexbox
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