Home  >  Article  >  Web Front-end  >  How to get an element with an id value in css and change its style

How to get an element with an id value in css and change its style

WBOY
WBOYOriginal
2021-12-01 15:22:254492browse

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; }".

How to get an element with an id value in css and change its style

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:

How to get an element with an id value in css and change its style

(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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn