I want to make an ul
that breakes into a few lines with flex-wrap
. So far so good but, if there are multiple lines, I want all lines exept the last one to take the rest of the width of the line. So I used flex-grow: 1;
on the li
's. However as the last line shouldn't have flex-grow
I just put an empty li
after all the others an gave it flex-grow: 9999;
, so that they don't take the whole width. (See Example for better understanding)
ul {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
li {
flex-grow: 1;
}
li:last-of-type {
flex-grow: 9999;
}
/* Unimportant */
ul {
list-style-type: none;
text-align: center;
width: 400px;
}
li {
padding: 0.5em;
background: blue;
}
li:hover {
background: red;
}
<ul>
<li>abcdefghijklm</li>
<li>abcdefghijklm</li>
<li>abcdefghijklm</li>
<li>abcdefghijklm</li>
<li>abcdefghijklm</li>
<li></li>
</ul>
Now, I have the question: Does HTML5 allow to just put an li
at the end only for styling reasons?
(If there exists another CSS function for using flex-grow on these lines, I would be very happy, but I don't think so.)
I already searched for this, but I didn't realy know how to search, so I couldn't find something.
` or `
` for example) then html has nothing to say about whether you use empty elements for styling purposes. Semantically it feels wrong to me, but it’s opinion based, so it only matters whether you’re happy to have empty elements as hooks for presentational styling.