I have following HTML code:
<ul data-links="6">
<li><a href="settings/_users.php">Users</a></li>
<li><a href="settings/_flows.php">Flows</a></li>
<li><a href="settings/_file_syncing.php">File syncing</a></li>
<li><a href="settings/_profile.php">Profile</a></li>
<li><a href="settings/_billings.php">Billings</a></li>
<li><a href="settings/_notifications.php">Notifications</a></li>
</ul>
and simplified version of CSS:
ul {
width: 600px;
height: 100px;
list-style: none;
padding: 0; margin: 0;
border: 1px solid #000;
}
li {
float: left;
width: calc(600px / 6); /* yes, it gives 100px */
height: 100px;
}
li:nth-child(2n) {
background: rgba(0,0,0,0.25);
}
Here's demo.
Depending on user's role I show only some of the <li>
elements on this list, so it's not always 6 of them. I can show "data-links" attribute with actual number of list elements I show to user.
Anyway, the thing is that I want to make it flexible, that's why I used calc()
for setting <li>
width. So probably you already know what I'm trying to have: instead of showing there a number I want do something like this:
width: calc(600px / attr(data-links));
Yes, I know this is wrong becuase IF I ever wanted to use attr()
in CSS it would get this attribute from this specific element, not from parent as in my example above. However I just wanted to show you what I'm trying to achieve. Obviously I can have data-links
attribute on every <li>
element instead of <ul>
but this is clearly less clean solution (and btw. doesn't work as well)