2014-09-01 30 views
1

我希望保持文本的位置,但是,DIV徘徊時,文下降如何在高度過渡期間保持文本的位置?

HTML

<!DOCTYPE html> 
<html> 
<head> 
<link href="site.css" rel="stylesheet" type="text/css" media="screen"/> 
</head> 
<body> 
<div></div> 
<p>hover over the div element above, and the text goes down</p> 
</body> 
</html> 

CSS

div { 
width: 100px; 
height: 100px; 
background: red; 
-webkit-transition: height 1s; 
} 

div:hover { 
height: 300px; 
} 
+0

'位置:absolute'? – qtgye 2014-09-01 09:31:13

+0

@jacelysh我試過了,但沒有奏效 – Akshay 2014-09-01 09:32:10

+0

即使絕對定位,文本仍然會移動?奇怪的。 – qtgye 2014-09-01 09:33:16

回答

2

添加以下到你的CSS:

p { 
    position:absolute; 
    top:100px; 
} 

See DEMO here

+1

謝謝我從來沒有這樣想過 – Akshay 2014-09-01 09:34:30

+1

@Akshay歡迎:) – Hiral 2014-09-01 09:40:19

1

添加這個..

p 
{ 
    position: fixed; 
    top: 125px; 
} 

DEMO