Why can't the div nested in div set background-color? in the stylesheet?

like this:

<div id="container">
    <div id="1st">1</div>
    <div id="2nd">2</div>
    <div id="3rd">3</div>
</div>

when setting the background color through the stylesheet, only the background color of the parent element is displayed

-sharpcontainer{
        width: 100%;
        height: 100%;
        background-color: red;
    }

and no matter how you set the background color of the child element, it doesn"t work:

-sharp1st{
        display: block;
        width: 100px;
        height: 100px;
        background-color: black;
    }

the results are as follows:

clipboard.png

clipboard.png

stylebackgound-color:


clipboard.png

Why is this?

Css
Mar.02,2021

https://jsfiddle.net/zhc23bz9/5/

there is a problem with the name of your id. You can change the first id to first.

-sharpcontainer {
  width: 100%;
  height: 100%;
  background-color: yellow;
}

-sharpfirst {
  display: block;
  width: 100px;
  height: 100px;
  background-color: red;
}

-sharp2nd {
  display: block;
  width: 100px;
  height: 100px;
  background-color: black;
}
<div id="container">
    <div id="first">1</div>
    <div id="2nd">2</div>
    <div id="3rd">3</div>
</div>

in CSS naming conventions, names cannot start with numbers, but only with letters, hyphens, and underscores. It can be followed by letters, hyphens, underscores, or numbers.

Menu