Languages
[Edit]
EN

CSS - set color as element background

0 points
Created by:
Palpys
464

In this article, we would like to show you how to set color as element background using CSS.

Quick solution:

body {
  background: yellow;
}

or

div {
  background: yellow;
}

 

Practical example

1. In this example, we color the background of the body element using background property.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    body { 
      background: yellow;
    }

  </style>
</head>
<body>
  <span>Example text...</span>
</body>
</html>

2. In this example, we color the background of the body element and div element inside with a different color.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
  <head>
    <style>

      body { 
        background: yellow;
      }

      div { 
        background: yellowgreen;
      }

    </style>
  </head>
  <body>
    <div>Example text...</div>
  </body>
</html>
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join