2011-11-01 72 views
1

我有一个问题...我想创建一个名为拇指W /所有必要的信息为每个项目和悬停。然后,我希望它们在父节点内具有自己的特定行为。这是我到目前为止,并没有工作。分层样式语法?

.thumb 
{ 
    display:block; 
    float:left; 
    width:10px; 
    height:10px; 
    margin:5px 10px 5px 10px; 
} 

.thumb:hover 
{ 
    border:solid 1px #F00; 
} 


#commercial 
{ 
    margin:0 auto; 
    width:100px 
} 

#commercial.thumb 
{ 
    background-color:#0A0; 
} 

#wedding 
{ 
    margin:0 auto; 
    width:100px 
} 

#wedding.thumb 
{ 
    background-color:#00F; 
} 

#fashion 
{ 
    margin:0 auto; 
    width:100px 
} 
#fashion.thumb 
{ 
    background-color:#F0F; 
} 

我也试着声明的ID内的拇指作为

#id > a.thumb 

#id > .thumb 

似乎没有任何工作。我认为这将是一个更有效的设置,因为它可以让我改变每一个拇指,而不管父母分隔符是多少,而只是一个代码块而不是3个,非常感谢任何见解。

感谢, 布罗迪

回答

2

#fashion.thumb意味着你要像一个元素匹配:

<div id="fashion" class="thumb"> 

分割它分成#fashion .thumb(注意空格)是“带班‘拇指’的任何元素与ID fashion元素的下降,which'd是:

<div id="fashion"> 
    <span class="thumb"></span> 
</div> 
1

在我看来,外核层你必须修改y事情是这样的:

.thumb 
{ 
    display:block; 
    ... 
} 

#commercial .thumb 
{ 
    background-color:#0A0; 
} 

来表达.thumb元素必须是一个孩子的#commercial(直接或间接),必须有2对

之间的空间