Style is overwritable : Selector priority « Style Basics « HTML / CSS






Style is overwritable

 

<html>
<head>
<title>Practice</title>
<style>
body {
  font-size: 2em;
}

p {
  color: blue;
}

p {
  color: red;
}

p {
  color: green;
}

p {
  color: magenta;
}
</style>
<body>
<p>This is magenta colored text</p>
</body>
</html>

 








Related examples in the same category

1.Selectors choose the element to apply formatting to
2.Six selector groups listed from highest to lowest priority:
3.Specificity means that more specific selectors are given priority over less specific selectors
4.Cascade Order
5.select elements by type, class, and/or ID
6.Specificity, !important
7.!important has higher priority
8.Latter one overwrite the former one
9.the id selector is more specific than the element selector
10.Some properties in CSS are inherited to children elements