0

I'm wondering if there is a pure CSS way to add a class to elements of another class. The problem I'm trying to solve is below, which is also an example.

Using bootstrap, I have a number of elements that look like this:

<li class="nav-item">
  <a class="nav-link" href="#">Law</a>
</li>

What I would like to do is add the pull-right class to each element with the class nav-item (I think), in order to make the nav items all float to the right.

Is there a pure CSS way to do this? I think the answer is no, at least without LESS/SASS/JS, but I'd love to be disabused of that notion.

Community
  • 1
  • 1
NotAnAmbiTurner
  • 2,553
  • 2
  • 21
  • 44
  • 1
    Yea sorry to say, you can't add a class without JS. The closest functionality that I know of that is CSS only is to use the pseudo-class hover or focus or something like that. – Saliel Irizarry Feb 13 '17 at 21:41

1 Answers1

1

No, if you are wanting to add a class to the CSS you would need to use either JavaScript or Jquery. I would recommend Jquery because IMO it is a little easier to work with when adding classes.

Or you could just add the class to each nav-item:

<li class="nav-item pull-right">