作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将父级 div 设置为相对,其他设置为绝对和 50% 宽度,但即使是 jsfiddle 也显示它不起作用。我错过了什么?
http://jsfiddle.net/kagawa_leah/3gcV9/1/
html:
<div class="border">
<div class="left">
<p>LEFT Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. </p>
</div> <!--end left-->
<div class="right">
<p> RIGHT Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. </p>
</div> <!--end right-->
</div> <!--end border -->
CSS:
.border {
position: relative;
height: 100px;
background-color: #000000;
}
.left {position: absolute;
width: 50%;
float:left;
text-align:left;
bottom: 4px;
background-color:red;
}
.right {position: absolute;
width: 50%;
float:right; text-align:right;
bottom: 4px;
background-color: blue;
}
最佳答案
你不能 float 绝对定位的元素。您可能只想在每个元素上设置 right/left
。这是一个示例 fiddle :http://jsfiddle.net/ByVGf/1/
.border {
position: relative;
height: 100px;
background-color: #000000;
}
.left {position: absolute;
width: 50%;
left: 0
text-align:left;
bottom: 4px;
background-color:red;
}
.right {position: absolute;
width: 50%;
right: 0;
text-align:right;
bottom: 4px;
background-color: blue;
}
关于html - 左右浮动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8640174/
我是一名优秀的程序员,十分优秀!