How to lessen CSS


Tags: css

Problem :

<div id="tt">test1</div>
    <div id="blabla">test2</div>
<div id="test">
    <div id="blabla">test3</div>
    <div id="tt">test4</div>
</div>
<style>
    #tt {color:blue;}
    #blabla {color:green;}
    #test #tt, #test #blabla etc... {color:red;}
</style>

Is there a way to avoid repeating #test?

Thanks ;)



Solution :

Depends on what you want to do. If you want all the text nodes to be red and the parent element is #test, then you just need #test {color:red}. If you need to be more specific, and give a color only for a child, then you can use .child {color:blue}, but if you want to color a child of #test, then you will need to specify the ancestor descendant, in other words #test .child {color:green}


Edit

Example according my comment http://jsbin.com/udoya3


    CSS Howto..

    how to apply conditional stylesheet $this->headLink()->appendStylesheet('css/css.css') with zend-framework

    CSS question how to make one div appear over another?

    How prevent inheriting “position: relative” CSS

    How to stop divs moving in browser when zoom in/out?

    How to include css and jquery in joomla component

    How to draw a line from the middle of the page to the right side?

    How to define an elements style using CSS to be on top of an other? Why in my case z-index isn't effective?

    How can I animate a table row with a single column that spans multiple columns?

    How to reduce size of a text with police roboto on a small scren

    How to read CSS Content value with jQuery?

    How can I convince Firefox to redraw CSS Pseudo-elements?

    how to get both icon and heading in same line in css

    How to have an unlimited amount of divs shown next to each other

    How to get a list of css attributes of an element with jquery

    How can I make jQuery's draggable function expand the container?

    Blogger Template: how to change the color of the border css

    How to apply custom CSS on Facebook comment box plugin

    CSS: How to set a fallback for bold font families?

    How to make this CSS into a responsive one? [closed]

    How to blur a banner photo in CSS Style?

    How do I remove the blue border when I click on a hotspot mapped to my image in HTML/CSS?

    CSS Flex Box — flex-wrap:wrap; How to style a specific line?

    How does jQuery affect CSS structure

    how to select last element in the page?

    how to create circle image wrapper

    How to Display a div on mouse-over using jquery ?

    how to invoke css file in jquery

    How to apply css to only one level of list items (not to child elements)

    How to set up a correct cascade with label statement

    Selecting an adjacent's child… how?