我正在努力弄清楚如何在#content-body-container的底部定位#book3并将文本包装在#book3周围。我不能在#book3上使用上边距,因为那时文本不会环绕它。我需要这种方法是跨浏览器兼容的,并且也适用于旧版浏览器。如果可能,我想要纯HTML / css解决方案
提供here
<html>
<head>
<style>
#content {
width: 960px;
height: 600px;
margin: 0;
}
#content-body-container {
position: relative;
float: left;
top: 28px;
width: 495px;
border: 1px solid black;
height: 462px;
}
#book3 {
position: relative;
float: left;
/*margin-top:117px;*/
/*top: 145px;*/
bottom: 0;
height: 345px;
width: 88px;
background-color: #ffe3b1;
}
#book1 {
position: relative;
float: left;
top: 61px;
bottom: 0;
height: 429px;
width: 79px;
margin-right: 16px;
background-color: #ffd48b;
}
#book2 {
position: relative;
float: left;
top: 28px;
bottom: 0;
height: 462px;
width: 28px;
margin-right: 12px;
background-color: #ffc664;
}
#link-book1 {
position: absolute;
bottom: 54px;
}
#link-book3 {
position: absolute;
margin-left: 2px;
bottom: 16px;
}
</style>
</head>
<body>
<div id="content">
<div id="content-body" class="content-wrapper">
<div id="book1">
<a href="#" id="link-book1" class="book-link">Book 1</a>
</div>
<div id="book2"></div>
<div id="content-body-container">
<div id="book3">
<a href="#" id="link-book3" class="book-link">Book 3</a>
</div>
<div id="content-body-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa.
Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet.
Suspendisse in justo eu magna luctus suscipit. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui.
</div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
如果容器的height
和浮动框是持久的,您可以向容器添加padding-top
,并向包含文本的块添加否定margin-top
以实现效果:
<强> EXAMPLE HERE 强>
#content-body-container {
/* other declarations... */
height: 462px;
box-sizing: border-box;
padding-top: 117px; /* 462px - 345px */
}
#content-body-text { margin-top: -117px; }
box-sizing: border-box;
用于强制UA计算包含填充和边框的height
框。
是supported even in IE8。但是,当您添加height
时,可以减少padding-top
。