css – 拉伸div以适应绝对定位的内容

前端之家收集整理的这篇文章主要介绍了css – 拉伸div以适应绝对定位的内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法做到这一点,只需css和没有脚本?我有一个最小宽度的div,其内部是一个绝对定位的内部div,动态生成的可变宽度的内容.有时,内容超出了包含的div,但是由于它绝对定位它不会拉伸包含div.我如何让它拉伸包含div?谢谢

解决方法

尝试引用我这个JSfiddle. http://jsfiddle.net/gA7mB/
如果我正确地阅读它,那根本就是你正在寻找的东西.

HTML

<div class="container" >
<div class="relative" >
    <div class="absolute" >

        <h1>I am Content i can be as long as you wish. t is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters,as opposed to using 'Content here,content here',making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text,and a search for 'lorem ipsum' will uncover many web sites still in their infancy. VarIoUs versions have evolved over the years,sometimes by accident,sometimes on purpose (injected humour and the like).</h1>

    </div>
</div>

CSS

.container{
    width: 500px;            
}

.relative{
    position: relative;
    background: #666;
    min-width: 200px;
    min-height: 200px;
}

.absolute{
    position: absolute;
    background: #999;
    top: 20px; //not important,just to show absolute position
    left: 20px; //not important,just to show absolute position    
}
原文链接:https://www.f2er.com/css/214575.html

猜你在找的CSS相关文章