Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of these CSS rules? [duplicate]

Tags:

css

so I have been trying to find out for myself what the following code actually does to everyting, but I just haven't been able to fully understand.

/*Global Style*/
*,
*::before,
*::after{
    margin: 0;
    padding: 0;
    box-sizing: inherit;
}

I copied it from a video and so it didn't really explain it all to me. If you can explain this code to me, I would highly appreciate it!

like image 858
KrapnixTheFootballer Avatar asked Nov 21 '19 18:11

KrapnixTheFootballer


1 Answers

* is a global selector for all elements in an HTML file.

*::before inserts something before the content has selected

*::after inserts something after the content has selected

To answer your question, all the elements in the HTML will have 0 padding, 0 margins and box-sizing: inherit

*,
*::before,
*::after{
    margin: 0;
    padding: 0;
    box-sizing: inherit;
}

Running example. Hopefully it made sense.

Reference: https://www.w3schools.com/cssref/sel_after.asp

Reference: https://www.w3schools.com/cssref/sel_before.asp

p::after { 
  content: " - Remember this";
  background-color: yellow;
  color: red;
  font-weight: bold;
}

p::before { 
  content: " - Remember this";
  background-color: pink;
  color: red;
  font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p>My name is Donald</p>
<p>I live in Ducksburg</p>

</body>
</html>
like image 174
MTBthePRO Avatar answered Sep 23 '22 23:09

MTBthePRO