How to set a unified style for elements in css

WBOY
Release: 2021-11-30 15:46:11
Original
5611 people have browsed it

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>
Copy after login

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!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!