| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Which CSS selector?|
| 4:33 am on Mar 29, 2014 (gmt 0)|
Sometimes I find it difficult to choose the right CSS selector. Consider this, for example:
<title>Which CSS selector</title>
outline: 1px solid red;
<input type="text" id="name">
<input type="checkbox" id="married">
I can get the same result with:
#name + label
I can even give the element an ID and get it directly. But isn't it better to keep your HTML tidier/smaller?
| 6:18 am on Mar 29, 2014 (gmt 0)|
I would avoid nth child as it is harder to maintain - it breaks more easily if you make minor changes to your HTML - e.g. change the order of the inputs.
I think [for=married] is fine as there is no reason it should change. unless you completely redo the form.
| 3:24 pm on Apr 1, 2014 (gmt 0)|
According to sitepoint, #name + label would give you the best backwards compatibility with old browsers.
If all available solutions achieve my goal without any compromises, then "how many people will this serve?" is my go-to decider.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved