【问题标题】:How to make an absolutely positioned div take all the available width space?如何使绝对定位的 div 占据所有可用的宽度空间?
【发布时间】:2013-10-19 20:44:53
【问题描述】:

我有一个宽图像,我想在其底部绝对定位一个透明 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 似乎显示为内联块,我希望它占据页面的所有可用宽度,但它在段落所在的位置结束。

【问题讨论】:

    标签: html css


    【解决方案1】:

    像这样编辑.box

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

    【讨论】:

    • 是的,成功了,谢谢。
    【解决方案2】:

    你也可以 只需添加宽度:100%; 如

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

    【讨论】:

      猜你喜欢
      • 2017-07-03
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多