I have 5 buttons without any Class or ID. Here's my code:
HTML
<button>Btn1</button>
<button>Btn2</button>
<button>Btn3</button> <!-- I don't want this elem to get the CSS styles -->
<button>Btn4</button>
<button>Btn5</button>
CSS
button {
width: 100px;
height: 45px;
background-color: #12aeef;
border: none;
box-shadow: 0px 5px 3px #888888;
}
Demo on jsFiddle.
How can I make the 3rd element not get the CSS styles?
As an alternative to Mihai's answer, if you'd like to be able to use it on more than element, add a class
to any appropriate button
:
<button class="nostyle">
Then in your CSS, simply change button
to button:not(.nostyle)
.
That's it! ...what, you were expecting more work?
Here's the updated code:
button:not(.nostyle) {
width: 100px;
height: 45px;
background-color: #12aeef;
border: none;
box-shadow: 0px 5px 3px #888888;
}
<button>Btn1</button>
<button>Btn2</button>
<button class="nostyle">Btn3</button>
<button>Btn4</button>
<button>Btn5</button>
We want to remove styling (i.e.: the styling was already applied to the element and we want it removed) without any Classes or ID (i.e.: HTML must not be touched).
This requires some knowledge of the defaults ex.:
width: auto; // the default for sizes is auto
But also some investigation regarding the rest of your css because you may have some reset stylesheet included into your project which tells all elements everywhere to have behave diferently (this usually applies to paddings / margins / borders etc.).
We can use :nth-child()
, a CSS3 pseudo selector that finds child elements which ocupy the nth offset within the parent regardless of element type.
button:nth-child(3) {
width: auto;
height: auto;
background: none;
/* ... */
}
Try Connors last fiddle for the most efficience and elegance, or his first for full compatibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With