我希望父容器.wrapper1(绿色边框)自动包含.wrapper2(蓝色边框),是否可以不使用javascript?
.wrapper2可以包含在.wrapper1中(给定顶部未设置)。 但是如果top:100px,.wrapper2现在在.wrapper1
之外.wrapper1 {
border:3px solid green;
width:300px;
}
.wrapper2 {
position: relative;
width:100px;
top:100px;
margin:0 auto;
border:3px dashed blue;
}
<div class="wrapper1">
<p class="wrapper2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et, quia, quod, quae nisi beatae vel id fugiat cupiditate voluptas aperiam aspernatur est hic debitis a corrupti laudantium ipsa iure deleniti.</p>
</div>
感谢。
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个;
<div class="wrapper1">
<p class="wrapper2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et, quia, quod, quae nisi beatae vel id fugiat cupiditate voluptas aperiam aspernatur est hic debitis a corrupti laudantium ipsa iure deleniti.</p>
</div>
.wrapper1 {
border:3px solid green;
width:300px;
}
.wrapper2 {
width:100px;
top:100px;
margin:0 auto;
border:3px dashed blue;
}
jsfiddle:http://jsfiddle.net/cVsQ7/