i have class call "example1"
this class defines a background, and i want to create another class call "example2"
to u开发者_StackOverflow中文版ses the same background on each <li>
of class called "example1"
how can i make it. My goal it's use the class like this
<ul class="example2">
<li>some text</li>
<li>another text</li>
</ul>
i tried like this
example2, .example1 li{
}
but it doesn't work Thansk for your help
UPDATE
I modified the question because my question it not was what i want. I want to use the same background of example1 in each <li>
of example 2
You can't apply the concept of inheritance for CSS classes as we do in OOP. See this question as I think it's the same thing you want to do. One way to use a single background declaration is:
.example1, .example1 li { /* define only the background here */ }
.example1 { /* everything but the background */ }
.example2 { /* anything */ }
EDIT: If you are going to use CSS3, then you can use SASS. Good luck with IE for that matter. That's one navigator I learned to hate over the years.
You can put a background on the <li>
elements in your example like this:
ul.example2 li {
/* your background settings */
}
the above targets only <li>
elements inside an <ul>
having class example2. If you want to use the same style on multiple elements you can separate them using comma's like this:
.example1,
ul.example2 li {
/* your background settings */
}
Use .class for classes in css
.example2, .example1 li{ }
You just forgot to add a dot in front of your example2-class
If I am not wrong, what you meant is you want the background image assigned to the class example1
to be assigned to those <li>
who are the children of an element assigned the class example2
?
If that's the case, use:
.example1, .example2 li {
background-image: url('/image/url/here/');
}
If I understand your question correctly, you have a background property defined in class example1
and you want that same background property to apply to li
elements of class example2
. Is that correct?
If so, then this may be what you're looking for:
.example1, .example2 li {
background: ....;
}
Please clarify if I am still misunderstanding the question.
精彩评论