我有以下页面:
我正在使用绝对定位将我的内容放在图像旁边。不确定是否可以使用内联块或浮点数来解决我的问题。
我现在的问题是页脚与我的内容重叠,因为绝对定位的内容会失去它的高度。
JSFiddle:https://jsfiddle.net/sc3e1t15/
.wrapper { position: relative; }
.title,
.footer { font-weight: bold; }
.image { font-style: italic; width: 210px; border: 1px solid red; }
.links { max-width: 210px; }
.content { position: absolute; top: 18px; left: 220px; border: 1px solid green; }
<div class="wrapper">
<div class="title">
I'm the title.
</div>
<div class="image">
I'm an image.
</div>
<div class="links">
I'm some links.<br>
I want to be on the left side too!
</div>
<div class="content">
I'm the content.<br>
I want to be shown neatly next to the image.<br>
Spread over multiple lines<br>
Nothing to see here<br>
Staph reading me!<br>
Love you brah.
</div>
<div class="footer">
I'm a problem ... Because I disrespect the contents height.
</div>
</div>
答案 0 :(得分:6)
试试这个。在左侧包装你想要的内容并给它显示属性。
{display:inline-block;}
无需在此处使用位置。
.wrapper { position: relative; }
.title,
.footer { font-weight: bold; }
.image { font-style: italic; width: 210px; border: 1px solid red; }
.links { max-width: 210px; }
.content { display:inline-block; border: 1px solid green; }
.left-contain { display: inline-block; vertical-align: top;}
&#13;
<div class="wrapper">
<div class="title">
I'm the title.
</div>
<div class="left-contain">
<div class="image">
I'm an image.
</div>
<div class="links">
I'm some links.<br>
I want to be on the left side too!
</div>
</div>
<div class="content">
I'm the content.<br>
I want to be shown neatly next to the image.<br>
Spread over multiple lines<br>
Nothing to see here<br>
Staph reading me!<br>
Love you brah.
</div>
<div class="footer">
I'm a problem ... Because I disrespect the contents height.
</div>
</div>
&#13;