0

I'm making a list, and I'm using :nth-of-type(odd) to give the odd ones a background.

.item {
  padding: 8px 8px;
  margin: 0px 0;
}
.item:nth-of-type(odd){
  background: #fff;
}

HTML

<p class="text-right">
  <small>
    <a href="./?action=edit">Edit Info</a>
  </small>
</p>
  <p class="item">
    <b>Name</b>
    <span class="value"><?= $user["f_name"]; ?> <?= $user["l_name"]; ?></span>
  </p>
  <p class="item">
    <b>Email</b>
    <span class="value"><?= $user["email"] ? $user["email"] : "-"; ?></span>
  </p>
  <p class="item">
    <b>Phone</b>
    <span class="value"><?= $user["phone"] ? phone_format($user["phone"]) : "-"; ?></span>
  </p>

When I tried this, the first p (with .text-right) was included in the :nth-of-type so that the first .item was counted as second.

I managed to fix it by wrapping the .items in a div, but this won't work with my layout. Is there a way that I can do this while still having all of the ps in the same parent container?

yaakov
  • 4,568
  • 4
  • 27
  • 51

0 Answers0