2014-11-21 294 views
2

問題是在代碼中有2格,當鼠標進入第一個div的背景顏色是變化的,當進入第二個div兩個背景顏色,現在我想的是改變的時候進入第一div的背景色都是變化的!1 DIV DIV同時改變背景顏色懸停

.aboutboth { 
 
\t width: 370px; 
 
\t margin: 0 auto; 
 
} 
 

 
.about-mohamad { 
 
\t margin: 0 auto; 
 
\t width: 170px; 
 
\t height: 230px; 
 
\t background: #666666; 
 
\t float: left; 
 
\t text-align: center; 
 
\t margin-right: 30px; 
 
\t -webkit-transition: all .5s linear ; 
 
\t -moz-transition: all .5s linear ; 
 
\t -o-transition: all .5s linear ; 
 
\t transition: all .5s linear ; 
 
\t position: relative; 
 
} 
 

 
.about-mohamad:hover { 
 
\t background: #e9e9e9; 
 
} 
 

 
.about-mohamad div { 
 
\t margin: 0 auto; 
 
\t width: 150px; 
 
\t height: 150px; 
 
\t background: white; 
 
\t margin-top: 10px; 
 
\t margin-bottom: 25px; 
 
\t -webkit-transition: all .5s linear ; 
 
\t -moz-transition: all .5s linear ; 
 
\t -o-transition: all .5s linear ; 
 
\t transition: all .5s linear ; 
 
} 
 

 
.about-mohamad div:hover { 
 
\t background: #2d3030; 
 
} 
 

 
.about-mohamad span { 
 
\t display: inline; 
 
\t font-size: 13px; 
 
\t display: inline-block; 
 
\t color: white; 
 
} 
 

 
.about-mohamad p { 
 
\t font-size: 10px; 
 
} 
 

 
.about-mohamad div img { 
 
\t margin-top: 25px; 
 
} 
 

 
.about-mohamad span#abouthovera { 
 
    display:inline; 
 
    text-transform: uppercase; 
 
    font-size: 10px; 
 
} 
 
.about-mohamad:hover span#abouthovera { 
 
    display:none; 
 

 
} 
 
.about-mohamad span#abouthoverb { 
 
    display:none; 
 
} 
 
.about-mohamad:hover span#abouthoverb { 
 
    display:inline; 
 
    color: #666666; 
 
    text-transform: uppercase; 
 
    font-size: 10px; 
 
}
<div class="aboutboth"> 
 
    <div class="about-mohamad"> 
 
     <div><img src="http://rezaaria.com/1.png"></div> 
 
\t \t <span id="abouthovera">job</span> 
 
\t \t <span id="abouthoverb">name</span> 
 
\t </div> 
 
</div>

回答

1

你必須首先目標懸停<div>改變兩個背景。

.aboutboth { 
 
\t width: 370px; 
 
\t margin: 0 auto; 
 
} 
 

 
.about-mohamad { 
 
\t margin: 0 auto; 
 
\t width: 170px; 
 
\t height: 230px; 
 
\t background: #666666; 
 
\t float: left; 
 
\t text-align: center; 
 
\t margin-right: 30px; 
 
\t -webkit-transition: all .5s linear ; 
 
\t -moz-transition: all .5s linear ; 
 
\t -o-transition: all .5s linear ; 
 
\t transition: all .5s linear ; 
 
\t position: relative; 
 
} 
 

 
.about-mohamad:hover { 
 
\t background: #e9e9e9; 
 
} 
 

 
.about-mohamad div { 
 
\t margin: 0 auto; 
 
\t width: 150px; 
 
\t height: 150px; 
 
\t background: white; 
 
\t margin-top: 10px; 
 
\t margin-bottom: 25px; 
 
\t -webkit-transition: all .5s linear ; 
 
\t -moz-transition: all .5s linear ; 
 
\t -o-transition: all .5s linear ; 
 
\t transition: all .5s linear ; 
 
} 
 

 
.about-mohamad:hover div { 
 
\t background: #2d3030; 
 
} 
 

 
.about-mohamad span { 
 
\t display: inline; 
 
\t font-size: 13px; 
 
\t display: inline-block; 
 
\t color: white; 
 
} 
 

 
.about-mohamad p { 
 
\t font-size: 10px; 
 
} 
 

 
.about-mohamad div img { 
 
\t margin-top: 25px; 
 
} 
 

 
.about-mohamad span#abouthovera { 
 
    display:inline; 
 
    text-transform: uppercase; 
 
    font-size: 10px; 
 
} 
 
.about-mohamad:hover span#abouthovera { 
 
    display:none; 
 

 
} 
 
.about-mohamad span#abouthoverb { 
 
    display:none; 
 
} 
 
.about-mohamad:hover span#abouthoverb { 
 
    display:inline; 
 
    color: #666666; 
 
    text-transform: uppercase; 
 
    font-size: 10px; 
 
}
<div class="aboutboth"> 
 
    <div class="about-mohamad"> 
 
     <div><img src="http://rezaaria.com/1.png"></div> 
 
\t \t <span id="abouthovera">job</span> 
 
\t \t <span id="abouthoverb">name</span> 
 
\t </div> 
 
</div>

+0

你如何解決這個問題?請你解釋一下。 – 2014-11-22 10:45:28

+1

你只需要改變'。關於-穆罕默德格:hover'爲'。關於-穆罕默德:懸停div'。 – emmanuel 2014-11-22 10:46:25

+0

[鏈接](http://stackoverflow.com/questions/27769432/position-fixed-with-100-height)能不能幫我找到解決辦法嗎? – 2015-01-06 11:06:03

0
.aboutboth:hover { 
    background: #e9e9e9; 
} 

.aboutboth:hover ~ .about-reza { 
    background: #ccc 
} 
.aboutboth:hover { 
    background: #ccc} 

試試這個

+1

這是一個英文網站,如果你用其它語言編寫,有正派翻譯。 – 2014-11-21 19:06:21

+0

Ashkufaraz我需要同時改變背景顏色爲約·禮薩·格和aboutboth!當鼠標繼續左右div! 檢查這個! http://jsfiddle.net/6t1u3wsr/當鼠標繼續文字「工作」背景顏色變化!但是當鼠標上的圖像約-reza div背景顏色變化!當鼠標移動文本時,我怎麼能改變背景顏色! – 2014-11-21 19:18:38

+0

約 - 穆罕默德和有關-穆罕默德DIV改變鼠標懸停後兩者背景顏色有關,穆罕默德 – 2014-11-21 19:33:52