2014-02-07 70 views
0

由于某些原因,当我设置一个转换,以便当我的鼠标悬停在一个元素上时,背景会改变颜色,它只能使用一个elemtn,但它们都共享同一个类?任何帮助 我的CSScss div:悬停与转换只适用于一个元素?

.outer_ad 
{ 
    position:relative; 
    background:#E6E6E6;; 
    display:inline-block; 
    border: 1px solid black; 
    z-index:0; 
    transition: background 1s; 
    -webkit-transition: background 1s; /* Safari */ 
} 

.outer_ad:hover 
{ 
    z-index:1; 
    background: blue; 
} 

小提琴http://jsfiddle.net/P26tf/

回答

1

目标的<div>标签更具体。见http://jsfiddle.net/P26tf/1/

#main .outer_ad 
{ 
    position:relative; 
    background:#E6E6E6;; 
    display:inline-block; 
    border: 1px solid black; 
    z-index:0; 
    transition: background 1s; 
    -webkit-transition: background 1s; /* Safari */ 
} 

#main .outer_ad:hover 
{ 
    z-index:1; 
    background: blue; 
} 
+0

哎呀我的错误,我误解了一秒钟,谢谢! –

1

这是因为:

#outer_biz_pers 
    { 
    background:#E6E6E6; 
    } 

尝试,而是执行此操作:

background: blue !important; 
1

一些悬停的正在被其他类重写,加入!重要的标签固定在你的小提琴上

.outer_ad:hover { z-index:1; 背景:蓝色!重要; }

+0

Micallef击败我哈哈 – Zach

1

特殊照顾的overridding背景悬停设置与您的型动物设置好的其他CSS的那些:

 .outer_ad:hover 
     { 
      z-index:1; 
      background: blue ; 
     } 

     #outer_price 
     { 
      top:-83px; 
      background:#E6E6E6; 
     } 

这里你的背景蓝色永远不会被使用,因为#outer_price具有更高的重要性范围比你的。 outer_ad:悬停

你可以做

 body div#main div.outer_ad:hover 
     { 
      z-index:1; 
      background: blue ; 
     } 

 .outer_ad:hover 
     { 
      z-index:1; 
      background: blue !important ; 
     } 

强制您的悬停类比#号“更重要”。 CSS指层叠样式表,级联是关键;)

http://monc.se/kitchen/38/cascading-order-and-inheritance-in-css