Languages
[Edit]
EN

CSS - overwrite style

0 points
Created by:
Walter
586

In this article, we would like to show you how to overwrite style in CSS.

Quick solution:

div {
  background: blue;  /* common style */
}

Use inline style to overwrite the common style: 

<div style="background: orange;">Background changed.</div>

 

Practical example

In this example, we use the inline style to overwrite the div element's background color.

// ONLINE-RUNNER:browser;

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

    body {
      display: flex;
    }

    div {
      height: 75px;
      width: 75px;
      text-align: center;
      background: deepskyblue;
      border: 1px solid black;
    }

  </style>
</head>
<body>
  <div>div-1</div>
  <div>div-2</div>
  <div style="background: orange;">div-3</div>
  <div>div-4</div>
</body>
</html>

Alternative titles

  1. CSS - override style
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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