What does ::before mean in css
"::before" in css means "before...". It is a pseudo-class element used to create a pseudo-element and set it as the first child element of the selected element. , inserted before other content of the element, the syntax is "element::before{style code}".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
What does ::before mean in css
In css, ::before is a pseudo-class element that represents the generated content element , represents the first child element of the corresponding element's abstractable style, that is: the first child element of the selected element.
Use::before to insert the content to be inserted before other content of the element, and it will be displayed inline by default. ::before requires the content attribute to specify the value of the content.
::befor usage scenarios (such as adding an icon in front of an element)
<p class="test"> 2019/11/29 15:35:51 </p>//在这前面加一个小闹钟的图标就可使用::befor
.test::before { content: url(./1597910280\(1\).png); }
Same points:
1. Pseudo-class object, used to set the content before the object
2.::before and :before writing methods are equivalent
Differences:
: before is the way of writing Css2, ::before is the way of writing Css3
:before has better compatibility than ::before, but it is recommended to use ::before in H5 development
Instructions:
1. Pseudo-class elements must be used together with the content attribute
2. Pseudo-class elements are added by the css rendering layer and cannot be operated through js
3. Pseudo-class object special effects are usually activated through: hover pseudo-class style
I think this is a bit useless, you can use it or not.
The difference between pseudo elements and pseudo classes
- Pseudo classes
Pseudo classes are used to select between DOM trees information outside the scope, or information that cannot be represented by simple selectors. The former includes those elements that match the specified state, such as :visited, :active; the latter includes those elements in the DOM tree that meet certain logical conditions, such as :first-child, :first-of-type, :target. CSS pseudo-classes are used to add special effects to certain selectors.
- Pseudo elements
Pseudo elements are virtual elements that are not defined in the DOM tree. Unlike other selectors, it does not take the element as the smallest selection unit, it selects the specified content of the element. For example::before means the previous content of the selected element, that is, ""; ::selection means the selected content of the selected element. CSS pseudo-elements are used to set special effects to certain selectors.
::. However, due to historical reasons, browsers continue to support pseudo-elements starting with
:, but it is recommended to write them in the standard format starting with
::.
Select the element being activated | 1 | |
Select the element being hovered by the mouse | 1 | |
Select unvisited elements | 1 | |
Select The visited element | 1 | |
Select the element that is the first child element of its parent element | 2 | |
Select elements with the specified lang attribute | 2 | |
Select elements with keyboard input focus | 2 | |
Select each enabled Element | 3 | |
Select each disabled element | 3 | |
Select each selected element | 3 | |
Select the current anchor Point element | 3 |
1 | ::first-line | |
1 | ::after | |
2 | ::before | |
2 | ::selection | |
3 |
The pseudo-class has the same priority as the class, and the pseudo-element has the same priority as the label. By the way, how to judge the priority is generally !important > inline style > ID selector > class selector > label > wildcard > inheritance > browser default attribute. There is also a simple calculation method. The weight of the inline style sheet is 1000, the weight of the ID selector is 100, the weight of the Class selector is 10, the weight of the HTML tag selector is 1, and the weight is actually It is not calculated in decimal. The numerical representation is just to illustrate the idea. We can add the rules in the selector and compare the weights. The larger the weight, the higher the priority. If the weights are the same, the previous styles will be replaced by the later ones. cover. (Learning video sharing: css video tutorial) |
The above is the detailed content of What does ::before mean in css. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
