Avoid using the wildcard selector in your CSS. It is too broad and generally not recommended:
.secciones input[type=text],
.subsecciones input[type=text] {
border: none transparent;
background-color: white;
}
CSS processes selectors from right to left. For example, in this code snippet .secciones input[type=text]
:
- All input[type=text]
elements are selected
- Each match is checked to see if it is a (grand) child of .secciones
<div class="secciones">
<div>
<input type="text" placeholder="I will be matched as one of my parents is .secciones" />
</div>
<input type="text" placeholder="I will be matched as one of my parents is .secciones" />
</div>
Using the wildcard selector means "check if input[type=text]
is a child of any element. Starting with *
selects everything, which can lead to unintended consequences.
To target only the direct children of a selector, use .secciones >input[type=text]
:
- Selects all input[type=text]
- Filters out those that are not direct children of .secciones
<div class="secciones">
<div>
<input type="text" placeholder="I will NOT match, my direct parent is NOT .secciones" />
</div>
<input type="text" placeholder="I will match, my DIRECT parent is .secciones" />
</div>
An instance where you may want to use a *
: .hideNextElement + *
:
<div class="hideNextElement">click me to show next</div>
<div>I can be ANY element. With some JS I can become visible.</div>