I have used the :root
selector to apply a margin
to all the elements on the page; while the color
and font-family
properties work,the margin
property doesn't. Am i making a mistake?
I have refered to the following site https://www.digitalocean.com/community/tutorials/css-root-pseudo-class on using the :root
CSS selector and in the examples it verifies the usage of a margin
property.
:root {
margin: 0;
color: red;
font-family: Arial;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p class="new">Lorem.</p>
<p class="title">Lorem ipsum</p>
<p class="desc">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid, saepe animi? </p>
<p class="price">1$</p>
<button>Buy</button>
</body>
</html>
` element in your HTML, you'll get that same vertical spacing for free, because `
` elements have default margins. When you assign `margin:0` to everything, you lose that "for free" behaviour. Similar applies to a number of other elements.
– Alohci Aug 16 '22 at 13:27