2013-10-19 28 views
0

我有一个广泛的图像,我想绝对定位一个透明的div在它的底部。如何让一个绝对定位的div占用所有可用的宽度空间?

<div class="background"> 

<img src="background.jpg" class="image"> 
<div class="box"> 
<p>paragraph</p> 
</div> 

</div> 

CSS:

.background { 
Position: relative; 
} 

.image { 
width: 100%; 
display: block; 
} 

.box { 
background: #CC333F; 
color: white; 
position: absolute; 
bottom: 0; 
} 

问题是.box的似乎显示为inline-block的,我希望它采取网页上的所有可用的宽度,但结束正确的地方不段。

回答

0

您还可以 只需添加宽度:100%; 在

.box { 
background: #CC333F; 
color: white; 
position: absolute; 
bottom: 0; 
width:100%; 
} 
1

编辑.box这样的:

.box { 
background: #CC333F; 
color: white; 
position: absolute; 
bottom: 0; 
right:0; /* added */ 
left:0; /* added */ 
} 
+0

是的,这样做,谢谢。 –

+0

@MagdiGamal:您的欢迎 –

相关问题