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