Basic question regarding class and id in html


#1

<-style>
.bgcolor1{
background-color:blue;
}

  • #bgcolor2{
    background-color:green;
    }
    <-/style>
    <-div class=“bgcolor1” id=“bgcolor2”>
    ,<-p> what will be the back ground color?
    <-/p>
    <-/div>

please ignore all the hyphens
what will be the back ground color and please explain why


#2

Try it on Codepen and you’ll see!

As to why that’s the case, it’s to do with a concept in CSS called specificity. At the most basic level, this means that IDs take precedence over classes, which take precedence over tags.


#3

Hi,

Use the preformatted text option (from the top tool box in chat box)

or use:

```
     type in your code here
```

Then your code will be visible.


#4

Thank you. i have just started html 5


#5

That’s Great!!! Don’t be afraid to ask questions, like you just did :thumbsup: as long as you learn something then you’ll be closer to your goal of being a HTML MASTER!!!!!! :fireworks: