R3y R3y - 3 months ago 6
CSS Question

How to add background-color in a section part?

Is there any other way to add background color in section tag? Except using

body {background-color: blue;}
, what is are other ways to add background color into section?

I am trying to add the section background color like this:

<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<style>
#ABC {
background-color: blue;
}
</style>
</head>
<body>
<section id="ABC">
</section>
</body>
</html>


There is no color showing on my browser.

Answer

Its because #ABC does not have any content or does not have a height!

See below what happened when I have set a height to it.

<!DOCTYPE html>
<html>
  <head>
    <title>Testing</title>

    <style>

    #ABC {
      background-color: blue;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
    }

    body{
      background: grey;
      margin: 0;
    } 

    </style>

  </head>

  <body>

<section id="ABC">


</section>

  </body>
</html>

Comments