2014-09-19 39 views
3

我對不同的元素有多個css轉換。多個元素的css轉換

在我的示例中,如果將鼠標懸停在圓形部分上,則會在圓形和底部的框顏色變化上進行轉換。不過,如果你走出圈子,進入箱形截面,圓形過渡,不會發生

爲完整的例子見琴:http://jsfiddle.net/Lsnbpt8r/

繼承人我的html:

div class="row">    
     <div class="col-sm-4 text-center transistion"> 
      <div class="box"> 
      <i class="circle-pos circle glyphicon glyphicon-home icon"></i> 
       <h3 class="heading"> 
       Construction 
       </h3> 
       <p>This is how we do it</p> 
      </div> 
     </div> 

     <div class="col-sm-4 text-center transistion"> 
      <div class="box"> 
      <i class="circle-pos circle glyphicon glyphicon-wrench icon"></i> 
       <h3 class="heading"> 
       Interior Design 
       </h3> 
       <p>This is how we do it</p> 
      </div> 
     </div> 

     <div class="col-sm-4 text-center transistion"> 
      <div class="box"> 
      <i class="circle-pos circle glyphicon glyphicon-thumbs-up icon"></i> 
       <h3 class="heading"> 
       Service 
       </h3> 
       <p>This is how we do it</p> 
      </div> 
     </div> 
     </div> 

下面是我的一些CSS:

.circle { 
     width: 120px; 
     height: 120px; 
     -moz-border-radius: 50%; 
     -webkit-border-radius: 50%; 
     border-radius: 50%; 
     background: #f3f3f3; 
      -webkit-transition: all 300ms linear; 
     -moz-transition: all 300ms linear; 
     -o-transition: all 300ms linear; 
     -ms-transition: all 300ms linear; 
     transition: all 300ms linear; 

    } 
     .circle:hover{ 
     width: 100px; 
     height: 100px; 
     background: #f7f7f7; 
     } 
    .box{ 
     border: 0px 1px 2px 1px solid #f1f1f1; 
     border-top: 5px solid #003176; 
     height: 200px; 
     -webkit-transition: all 300ms linear; 
     -moz-transition: all 300ms linear; 
     -o-transition: all 300ms linear; 
     -ms-transition: all 300ms linear; 
     transition: all 300ms linear; 
    } 
    .box:hover{ 
     background-color: #135379; 

    } 

我怎樣才能讓這個無論段的一部分懸停在所有元素的轉變將發生?

提前歡呼。

+0

與此問題無關,但在div類名稱中存在小錯字。如果您在代碼中的其他地方使用該類,它應該是「轉換」而不是「轉換」 – mc01 2014-09-19 16:40:48

回答

4

這是因爲效果應用到每個元素的:hover

.circle:hover{ 
     width: 100px; 
     height: 100px; 
     background: #f7f7f7; 
} 

... 

.circle-pos:hover{ 
     margin-top: -50px; 
} 

所以,如果你懸停框,但不圓,也不會產生任何影響。相反,過渡設置爲共同的父容器的:hover,在這種情況下,.box DIV:

Updated Fiddle

.box:hover .circle{ 
    width: 100px; 
    height: 100px; 
    background: #f7f7f7; 
} 

.... 

.box:hover .circle-pos{ 
    margin-top: -50px; 
} 

編輯

用,如果你想在.icon:hover {同樣,它可以是.box:hover .icon{http://jsfiddle.net/Lsnbpt8r/3/

+0

您忘記了將圖標包含在轉換中。 – Koralarts 2014-09-19 16:26:23

+0

@Koralarts,它在更新的答案...;) – LcSalazar 2014-09-19 16:27:51

+0

偉大的東西,非常感謝你:) – JamesP 2014-09-21 12:30:32