-2

I'm trying to learn and I came by something I don't understand.

So I have this line of code in html:

<ul class="weblist">
    <li>Coffee Brur</li>
    <li>Taco Finder</li>
    <li>CSS Selector Finder</li>
    <li>HTML Formatter</li>
</ul>

And this line in file:

.weblist ul {
  color: red;
}

And I wonder why it doesn't do anything. From what I get, it should take all the descendants of the unordered list with the weblist class, and apply them the red color, but it does nothing. I would like it to make all the list elements of this particular unordered list to appear red.

letsintegreat
  • 3,328
  • 4
  • 18
  • 39
gesp
  • 23
  • 4

4 Answers4

1

Use the following css

ul.weblist{
  color: red;
}
Laura Landuyt
  • 116
  • 1
  • 8
0

You should apply it on the list item if you want to change the color of the text.

.weblist li {
color: red;
}

Edit: In this case it works, but the other solution to wrap another div around your list is maybe a better solution :)

Wimanicesir
  • 4,606
  • 2
  • 11
  • 30
0

.weblist ul means means that your ul is nested in an element that have weblist class. So to make your css work you need to write following HTML

your css:

.weblist ul {
      color: red;
    }

and HTML

<div class="weblist">
     <ul>
        <li>Coffee Brur</li>
        <li>Taco Finder</li>
        <li>CSS Selector Finder</li>
        <li>HTML Formatter</li>
      </ul>
    </div>
Ans Bilal
  • 987
  • 1
  • 10
  • 28
0

.weblist ul means to be apply to an ul element INSIDE a .weblist class element (here in my example, it's test)

.weblist ul {
  color: red;
}

ul.weblist { /* <- This is what you want */
  color: blue;
}
<ul class="weblist">
    <li>Coffee Brur</li>
    <li>Taco Finder</li>
    <li>CSS Selector Finder</li>
    <li>HTML Formatter</li>
    <li>
      <ul>
        <!-- here you have a <ul> inside weblist class element -->
        test
      </ul>
    </li>
  </ul>
And this line in css file:
Hearner
  • 2,711
  • 3
  • 17
  • 34