I researched on SO about *
(Asterisk) and I have found that it selects all elements and applies styles to them.
I followed this link, Use of Asterisk and I noticed that this code will apply border
to all of the elements.
* {
border: 1px solid red;
}
Now, my concern is that what does *:before
and *:after
do in CSS?
*:before,
*:after {
box-sizing: border-box;
}
Save this answer. Show activity on this post. :before selector inserts something before the content of each selected element(s). :after selector inserts something after the content of each selected element(s).
A CSS pseudo-element is used to style specified parts of an element. For example, it can be used to: Style the first letter, or line, of an element. Insert content before, or after, the content of an element.
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
Like their name said it, :before & :after are used to apply css properties JUST before/after the content WITHIN the matching element.
One day, a wise man said 'One fiddle is worth thousands words', so :
div {
border: solid 1px black;
padding: 5px;
}
div:before {
content: "Added BEFORE anything within the div!";
color:red;
}
div:after {
content: "Added AFTER anything within the div!";
color:green;
}
<div>Div 1</div>
<div>Div 2</div>
<div>Div 3</div>
<div>Div 4</div>
:before selector inserts something before the content of each selected element(s). :after selector inserts something after the content of each selected element(s).
so *:before like Dan White said would be before all elements and *:after will be after all elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With