Optimizing style rules
css
In this style css
I can replace 7 lines and lower a rule.
.showing h1 {
font-size: 30px;
padding-bottom: 10px;
font-family: "raleway";
font-weight: 300;
}
.showing h2 {
font-size: 30px;
padding-bottom: 10px;
font-family: "raleway";
font-weight: 300;
}
.showing h3 {
font-size: 20px;
padding-bottom: 10px;
font-family: "raleway";
font-weight: 300;
}
Optimized the rule in this way:
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
height: 100%;
color: #222222;
font-size: 13px;
font-family: 'OpenSans', Roboto, Lato;
background-color: #fff;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 500;
}
#showing {
height: 150px;
width: 100%;
padding-left: 40px;
padding-top: 20px;
}
/*Regla optimizada*/
.showing h1, h2, h3 {
font-size: 30px;
padding-bottom: 10px;
font-family: "raleway";
font-weight: 300;
}
.showing h3 {
font-size: 20px;
}
/*Esta es una regla de prueba*/
#prueba {
height: 150px;
width: 100%;
background-color: #ccc;
padding-left: 40px;
padding-top: 20px;
}
<div id="showing">
<div class="container">
<div class="showing">
<h1>Contenido de prueba</h1>
<h2>Segundo contenido de prueba</h2>
<h3>Último contenido de prueba</h3>
</div>
</div>
</div>
<!-- Aquí surge el problema -->
<div id="prueba">
<div class="container">
<div class="sinestilo">
<h1>Contenido de prueba</h1>
<h2>Segundo contenido de prueba</h2>
<h3>Último contenido de prueba</h3>
</div>
</div>
</div>
The problem is that by optimizing this rule .showing h1, h2, h3 {}
changes are applied to the other tags h1, h2, h3
with the same rules.
I assumed that it should only be applied to the dependency of the class .showing h1, h2, h3 {}
and not apply changes to the other h1, h2, h3
tags not bound to the rule .showing
Due to the error, I was questioned about the correct use of the rules css
.estilo.otroestilo{} <- o -> .estilo, .otroestilo{}
.estilo>h1>h2 <- o -> .estilo h1>h2
.estilo, h1, h2, h3 <- o -> .estilo h1, h2, h3
#estilo#otroestilo{} <- o -> #estilo, #otroestilo{}