Home >Web Front-end >CSS Tutorial >How to get an element with an id value in css and change its style
In CSS, you can use the "#id" selector to select the specified HTML element object based on the id value, and add a new style code to the element object. The syntax is "#id value {css style code; }".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to get an id value element in css and change the style
We can get a specified id value through the #id selector Element and change the style, the #id selector sets the style for the element with the specified id.
The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #id1{ background-color:yellow; } #id2{ background-color:green; } </style> </head> <body> <p id="id1">argargargaegaeg</p> <p id="id2">agrwargarwgarg</p> </body> </html>
Output result:
(Learning video sharing: css video tutorial)
The above is the detailed content of How to get an element with an id value in css and change its style. For more information, please follow other related articles on the PHP Chinese website!