The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Styling all elements before an element

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #37457

    Hi folks. New to the forum, and have a tough one.

    I’m working on a mobile fitness app for a gym. On one of the pages, there is a section where you select the number of glasses of water you’ve drank in a day from a list. When you select one, that number’s color is supposed to change, as well as all of the numbers previous to it. Here’s an example of how it’s supposed to look when the user has selected 4 glasses of water:

    I have the first part of the equation working (the selected number changes color). But for the life of me, I can’t figure out how to change the color of the previous ones. Ideally, I would like a css only solution, rather than a javascript one. Here is the working page in progress:

    One note: the reason I am styling the labels rather than the radio buttons is because this is a mobile site, and Windows 7 phones will allow you to style the labels to look like the comp, but not the radio buttons.

    Any help is greatly appreciated.


    Hmm, I tried to get it to work using the ~ css selector, but no luck. So maybe the best solution would be to use a small piece of code. Here’s a demo of it.

    var li = $('.water li');

    and a bit of css

    .water .hilight label {
    border:2px solid #2397de;

    OK… I’ve been thinking for a very long time… I had never put it in practice until now… TADA! The Previous Element Selector!!
    It is fake of course… But it does the trick…
    And also it probably won’t work on ie…

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.