To change the background color of a div in HTML using CSS, you can use the background-color property. The property can be set either in the style attribute of the div element or in a separate CSS stylesheet.
Here's an example of setting the background color in the style attribute:
css<div style="background-color: blue;">
This div has a blue background color.
</div>
And here's an example of setting the background color in a CSS stylesheet:
css<style>
.my-class {
background-color: blue;
}
</style>
<div class="my-class">
This div has a blue background color.
</div>
In this example, the CSS class .my-class is defined in the stylesheet, and the class is applied to the div element using the class attribute. You can replace "blue" with any valid CSS color value, such as a named color (e.g. "red"), a hexadecimal color value (e.g. "#ff0000"), or an RGB color value (e.g. "rgb(255, 0, 0)").
إرسال تعليق