-1

I have an un-ordered list like so:

<ul>
    <li class="active">40' Singles</li>
        <li>46' Singles</li>
        <li>50' Singles</li>
        <li>Custom Lots</li>
</ul>

each list item is 50% in width, are floating left and have a background-color:

ul li {
 float: left; width: 50%; background-color: rgba(255, 255, 255, 0.7); 
}

Looks okay, so far, I have two list items per a line which is what I want, now I am trying to add padding to each list item so the background-colors are not touching..I have tried adding a padding of 20px and that did not work, added the padding, but now my list items are on their own line, I also tried with a margin of 20px, same result, what am I doing wrong here?

user979331
  • 11,039
  • 73
  • 223
  • 418

1 Answers1

1

You need to add box-sizing: border-box to your li styles. The reason, is padding is not included in the width by default.

ul.calc li {
  float: left;
  width: calc( 50% - 20px);
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20px;
  margin: 10px;
  box-sizing: border-box;
}

ul.background-clip li {
  float: left;
  width: 50%;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20px;
  box-sizing: border-box;
  background-clip: content-box;
}
<ul class="calc">
  <li class="active">40' Singles</li>
  <li>46' Singles</li>
  <li>50' Singles</li>
  <li>Custom Lots</li>
</ul>

<ul class="background-clip">
  <li class="active">40' Singles</li>
  <li>46' Singles</li>
  <li>50' Singles</li>
  <li>Custom Lots</li>
</ul>
disinfor
  • 10,865
  • 2
  • 33
  • 44