October 14, 201115 yr Hi, I browse a lot of websites and I always look at he source to see what is going on and how other ppl out ther build their sites. Anyway to cut a long story short I came across the following CSS .listB > li > a > img { border: solid 3px #e5e5e5; } .listB > li > a > .overlay { left: 3px; right: 3px; bottom: 3px; padding: 5px; background: #000; } .listB > li > a:hover > .overlay, .listB > li.on > a > .overlay { background-color: #f5a600; color: #000; } I noticed the ">" and was wondering what it does? If you style with CSS like this I would love to know what it does and why its being used. Thanks
October 14, 201115 yr The > indicates that there should only be a match when an element is the direct child of another element. It might be easier to explain the differences with a bit of code. <body> <div> <div> <p>Hello</p> </div> </div> </body> Here are four different lines of CSS and how they affect the output; body > div > p { color: red;} = Hello (no match, color not applied) body div p { color: red;} = Hello (it matches regardless of the second div before the p) body div div p {color: red;} = Hello body > div > div > p {color: red;} = Hello Edited October 14, 201115 yr by Dcruize
October 14, 201115 yr Author Here ya go. http://www.w3.org/TR/CSS21/selector.html#child-selectors Thanks for the link, bookmarked! The > indicates that there should only be a match when an element is the direct child of another element. It might be easier to explain the differences with a bit of code. <body> <div> <div> <p>Hello</p> </div> </div> </body> Here are four different lines of CSS and how they affect the output; body > div > p { color: red;} = Hello (no match, color not applied) body div p { color: red;} = Hello (it matches regardless of the second div before the p) body div div p {color: red;} = Hello body > div > div > p {color: red;} = Hello Brilliant explanation thank you!
October 14, 201115 yr There is a good article here on 30 of these selectors here: http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/ There are plans to introduce more of these in the future. Which means they won't work in earlier IEs. This may help with that though. http://code.google.com/p/ie7-js/
October 15, 201115 yr Ideally you should write your CSS with as little specificity as possible, to ease maintenance. Stay clear of child selectors if you can do the job with plain descendant selectors.
October 15, 201115 yr Author There is a good article here on 30 of these selectors here: http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/ There are plans to introduce more of these in the future. Which means they won't work in earlier IEs. This may help with that though. http://code.google.com/p/ie7-js/ wow brilliant stuff, the tutsplus article went down well with my morning coffee. It also answered questions I am sure I would be asking in the future. Thanks for the links! Ideally you should write your CSS with as little specificity as possible, to ease maintenance. Stay clear of child selectors if you can do the job with plain descendant selectors. Thank you for the advice. I have been really lucky to get a job updating websites without having prior experience or knowledge. The coder that builds all the websites is always to specific with his selectors that its so hard to "recycle" the code from one page onto another page. I am self thought(with lots of help from WDF) and always worked thinking about how to use as little css and html as possible and still achieve the best results. so "recycle recycle recycle"... Thanks for your comments
Create an account or sign in to comment