2015-09-04 55 views
0

Css初学者问!!当我试图悬停的文本有绝对的位置,悬停不见了。不能解决它。也许z指数解决问题,但我不能it.Thanks你的帮助提前。 Fiddle当悬停与绝对位置的div让悬停关闭

*{ 
 
    padding:0; 
 
    margin:0; 
 
} 
 
body { 
 
    background:#eee; 
 
    font-family:helvetica; 
 
    font-weight:bold; 
 
} 
 
.news { 
 
    position:relative; 
 
    left:50%; 
 
    margin-left:-300px; 
 
    margin-top:50px; 
 
    width:600px; 
 
    height:300px; 
 
    border-top:3px solid #f26222; 
 
    overflow:hidden; 
 
    z-index:1; 
 
} 
 
.news img { 
 
    cursor:pointer; 
 
} 
 
.text { 
 
    position:absolute; 
 
    top:85%; 
 
    transition:all 0.3s ease; 
 
    
 
} 
 
.text h2 { 
 
    margin-bottom:20px; 
 
    text-align:center; 
 
} 
 
.text p { 
 
    margin-left:10px; 
 
    margin-right:10px; 
 
    font-weight:normal; 
 
} 
 
.news img:hover + .text { 
 
    top:65%; 
 
} 
 
span { 
 
    position:absolute; 
 
    top:0; 
 
    background:#f26222; 
 
    color:#eee; 
 
    padding:3px; 
 
}
<div class="news"> 
 
    <span>Technology</span> 
 
<img src="http://i.imgur.com/YlkCC9u.jpg" height=300 , width=600> 
 
    <div class="text"> 
 
    <h2>LOREM IPSUM ETIAM EST</h2> 
 
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat</p> 
 
    </div> 
 
</div>

+0

你是说,当你将鼠标悬停你想要的东西发生的文本? – cocoa

+0

当你将鼠标悬停在文本上时,你正在改变文本的位置,那么为什么当你将鼠标悬停在文本上时它会“离开”呢? –

+0

当悬停img文本显示比悬停文本文本不显示。 – Norx

回答

2

更换

.news img:hover + .text { 
    top:65%; 
} 


.news:hover .text { 
    top:65%; 
} 

试试这个。

<div class="news"> 
    <span>Technology</span> 
<img src="http://i.imgur.com/YlkCC9u.jpg" height=300 , width=600> 
    <div class="text"> 
    <h2>LOREM IPSUM ETIAM EST</h2> 
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat</p> 
    </div> 
</div> 

*{ 
    padding:0; 
    margin:0; 
} 
body { 
    background:#eee; 
    font-family:helvetica; 
    font-weight:bold; 
} 
.news { 
    position:relative; 
    left:50%; 
    margin-left:-300px; 
    margin-top:50px; 
    width:600px; 
    height:300px; 
    border-top:3px solid #f26222; 
    overflow:hidden; 
} 
.news img { 
    cursor:pointer; 
} 
.text { 
    position:absolute; 
    top:85%; 
    transition:all 0.3s ease; 

} 
.text h2 { 
    margin-bottom:20px; 
    text-align:center; 
} 
.text p { 
    margin-left:10px; 
    margin-right:10px; 
    font-weight:normal; 
} 
.news:hover .text { 
    top:65%; 
} 
span { 
    position:absolute; 
    top:0; 
    background:#f26222; 
    color:#eee; 
    padding:3px; 
} 


- 编辑 -
JSFiddle

+1

谢谢。我知道解决方案很简单。 – Norx

+0

不客气。 – Aakash