How to style a DIV using CSS: Select the DIV element: Use a CSS selector (ID, class, or element type) to select the DIV you want to style. Set style properties: Inside the selector, specify the CSS style properties and their values (separated by colons). Apply styles: Add CSS code to the <head> section of your HTML document or to an external CSS file.
Style DIV with CSS
CSS (Cascading Style Sheet) is a method used to style HTML A language for document elements that can be used to customize the appearance and behavior of DIVs (block-level elements).
How to use CSS to style DIV:
Select the DIV: Use the CSS selector to select the style to be set DIV element. The selector can be an ID, class, or element type.
<code class="css">#myDiv { } /* 根据 ID 选择 */ .myClass { } /* 根据类选择 */ div { } /* 选择所有 DIV 元素 */</code>
Set style properties:Inside the selector you can set the required CSS style properties. Each attribute corresponds to a value, separated by a colon (:).
<code class="css">#myDiv { background-color: red; width: 200px; height: 100px; }</code>
<head>
section of the HTML document or to an external CSS file. The style will be applied to the selected DIV element. Example:
The following code will set a red background to the DIV with the ID "myDiv", with a width of 200px and a height of 100px:
<code class="html"><head> <style> #myDiv { background-color: red; width: 200px; height: 100px; } </style> </head> <body> <div id="myDiv">这是我的 DIV</div> </body></code>
Note:
The above is the detailed content of How to style div using css. For more information, please follow other related articles on the PHP Chinese website!