0

I'm trying to set the left border of the list item with Link text to red on active, and when the user clicks another list item, the previous border is set to the original and the successive list item is then set to a red left border. I tried with an :active class, but that is not working correctly:

      <ul class="list-group">
        <li class="2" data-toggle="collapse" data-target="#2" aria-expanded="false">Link</li>
      </ul>

CSS

li {
  list-style-type: none;
}

.list-group li:active {
  border-left: 3px solid #ce2523;
  padding-left: 7px;
  color: #000000;
}

JSFIDDLE: LINK

Matt
  • 1,561
  • 5
  • 26
  • 61
  • Your HTML markup is completely invalid, whether that factors in to what you're attempting at all. The only element that's an acceptable child to `
      ` is `
    • - not `
      `. I'd suggest putting your `
      ` in an `
    • ` and straightening out any HTML issues before moving on to addressing CSS
– Tyler Roper Apr 14 '17 at 21:16
  • No, the left border flashed red when clicking the link, but I need it to stay red when active. – Matt Apr 14 '17 at 21:17
  • ...And what I'm saying is that before you start moving on to CSS, you should correct your HTML. Wouldn't you rather fix the foundation before building a house on it? – Tyler Roper Apr 14 '17 at 21:19
  • I've simplified the markup, so its just a matter of how to set the `li` left border to red on click (not just hover). – Matt Apr 14 '17 at 21:20
  • like this? https://jsfiddle.net/vxz7zrg9/3/ - And as a supplement to what I mentioned above, take a look at this: [Can I use DIV as a direct child of UL?](http://stackoverflow.com/questions/11755628/can-i-use-div-as-a-direct-child-of-ul). – Tyler Roper Apr 14 '17 at 21:24