如何围绕堆叠元素(即具有负边距的元素)包装文本?

时间:2016-04-29 15:45:42

标签: javascript jquery html css margin

我希望有人能帮助我。

我想在多个堆叠的浮动元素周围包装文本,但是当我向第二个元素添加一个负边距时,文本不会播放球(见下文)......

有没有人有解决方案可以帮助我解决这个问题?

提前致谢!

我到目前为止所做的事情:

<style>
.elements {
    float:left;
    padding:10px;
    width:50%;
    background:#039;
    color:#fff;
    font-family:Arial, Helvetica, sans-serif;
    color:#fff;
    padding:50px;
    box-sizing:border-box;
    margin-right: 20px;
    position: relative;
}

#element-two {
    margin-top:-50px;
    background:#900;
    margin-left:30px;
}
</style>


<div id="post">
<div id="element-one" class="elements">Element 1</div>
<div id="element-two" class="elements">Element 2</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id dictum odio. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus vitae leo dictum, <br>
<br>
<br>
porttitor augue ut, accumsan nunc. Phasellus at malesuada orci, quis varius nulla. Nullam dui purus, elementum non fermentum eu, 
laoreet ac massa. Maecenas dictum elit sit amet mi pretium tincidunt. Maecenas interdum elementum lectus, eu aliquam nibh lacinia nec. 
<br><br><br>
Quisque facilisis accumsan blandit. Mauris eget pulvinar lacus. Donec pretium posuere mattis. Suspendisse et tempor orci, sit amet placerat neque. Etiam laoreet massa eu libero posuere, sit amet laoreet metus auctor.

</div>

我希望页面看起来如何 How I would like the page to look

页面看起来如何 How the page looks as it is

1 个答案:

答案 0 :(得分:4)

希望这会有所帮助。

 `https://jsfiddle.net/0zf7rxpn/1/`

简而言之,我将负边距底部设置为蓝色元素,因此红色元素上升。然后到红色元素我给了一些边缘右边,位置:相对和负面右边。