Let's say I have code like this:
<html>
<head>
<style>
div {
background: yellow;
}
.px-0 {
padding-left: 0;
padding-right: 0;
}
.px-10 {
padding-left: 2.5rem;
padding-right: 2.5rem;
}
</style>
</head>
<body>
<div class="px-10 px-0">
text that should have 0 padding
</div>
</body>
</html>
My question is - why padding for div is not 0? I always thought that rules should be applied based on order of classes used - in this case there is px-10
(with paddings) and then px-0
(with no paddings) so final result should be no padding.
It also seems the order of rules defines in CSS matters in this case - when I put .px-10
before .px-0
then result is as expected (but of course it will cause problem when using class="px-0 px-10"
).
Just in case above code is just simplified to scenario I have - use Tailwind CSS
and I have some component that have set px-10
class (let's say I cannot remove it) and I was pretty sure that adding also px-0
after it would cause element won't have any padding but it seems I was wrong.
Additional question - is the only possible solution is writing additional CSS like this:
.px-10.px-0 {
padding-left: 0;
padding-right: 0;
}
to make it working?