Home > Article > Web Front-end > What are the methods to set the background color of DIV?
There are two ways to set the background color of a DIV. One is to set the background color directly within the div tag, and the other is to set the div background color using external CSS. Today I will explain these two methods in detail.
1. Set the background color directly in the div tag
<div style="background:#000; color:#FFF">背景为黑色</div>
Set the background color in the DIV tag to black and the font color to white
Setting the background color of div
Screenshot of setting the background color in the div tag
Set the background color and other CSS styles by setting the style in the div tag.
2. Set the div background color with external css
Here is a objectThe CSS is named ".divcss5", and the background color of the DIV object is set by creating an external selector
CSS code:
.divcss5{ background:#F00; color:#FFF} html源代码: <div class="divcss5">背景色为红色</div>
These are the two ways to set the background color of DIV. Friends in need can save it. Please also continue to pay attention to other updates on this site .
Related reading:
The above is the detailed content of What are the methods to set the background color of DIV?. For more information, please follow other related articles on the PHP Chinese website!