Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make div fill remaining width with list-style-position: inside

Tags:

html

css

I'm trying to get another div fill the remaining space in the numerical li with list-style-position: inside but I can't seem to get it working.

Although I could use list-style-position: outside and add spacing because it overlaps other elements on the page, I would much prefer positioning it inside if that is possible. I plan on the list going past 100 items.

body { margin: 0; padding: 0; }

ul {
  list-style-position: inside;
  list-style-type: decimal;
  margin: 0;
  padding: 0;
}

li {
  width: 100%;
}

.myClass {
  display: inline-block;
  width: 100%; /* fill remaining space in the li */
  height: 20px;
  background: #000;
}
<ul>
  <li><div class="myClass"></div></li>
</ul>
like image 536
Andy Huynh Avatar asked Sep 05 '25 03:09

Andy Huynh


1 Answers

You can use flex on the li, use css counter on a pseudo element for the number, then set .myClass to flex-grow: 1

body { margin: 0; padding: 0; }

ul {
  list-style-position: inside;
  list-style-type: none;
  margin: 0;
  padding: 0;
  counter-reset: section;       
}

li {
  width: 100%;
  display: flex;
}

li:before {
  counter-increment: section;
  content: counter(section) ". ";
}

.myClass {
  display: inline-block;
  height: 20px;
  background: rgba(0,0,0,0.5);
  flex-grow: 1;
}
<ul>
  <li><div class="myClass"></div></li>
</ul>
like image 70
Michael Coker Avatar answered Sep 07 '25 23:09

Michael Coker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!