"; 2. Use the ".class" selector to select all elements with the specified class value. And set a unified style, the syntax is ".value{css style code;}"."/> "; 2. Use the ".class" selector to select all elements with the specified class value. And set a unified style, the syntax is ".value{css style code;}".">

Home >Web Front-end >CSS Tutorial >How to set a unified style for elements in css

How to set a unified style for elements in css

WBOY
WBOYOriginal
2021-11-30 15:44:445652browse

Method: 1. Use the class attribute to set a unified class value for multiple elements. The syntax is ""; 2. Use the ".class" selector to select the band There are all elements with specified class values, and a unified style is set. The syntax is ".value{css style code;}".

How to set a unified style for elements in css

The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.

How to set a unified style for elements in css

In css, you can set a unified style for elements through the class attribute. The

.class selector selects all elements with the specified class.

class refers to the class attribute of an HTML element. The

class attribute is used to set specific styles for multiple HTML elements.

Let’s see how to set a unified style for elements by setting the styles of two divs. 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>
</head>
<body>
    <style>
    .mydiv{
        width:100px;
        height:100px;
        background-color:red;
}
    </style>
<div class="mydiv"></div>
<p>同一个class</p>
<div class="mydiv"></div>
</table>
</body>
</html>

Output result:

How to set a unified style for elements in css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set a unified style for elements in css. 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