【发布时间】:2018-10-04 04:42:18
【问题描述】:
我在一个容器中有 2 个 div,我想将一个 div 设置为与容器左对齐,另一个设置为通过 css 与浏览器的右端对齐。这可能吗?
有人帮我解决这个问题吗?
.container {
background: #ccc;
height: 400px;
max-width: 500px;
margin:0 auto;
}
.outer {
background: #f8f9fa;
margin-top: 40px;
}
.left-box {
background: #000;
color: #fff;
padding: 10px 0;
float:left;
width:50%;
margin-top:20px;
height:100px;
}
.right-box {
background: #EC8400;
padding: 10px 0;
float:right;
margin-top:20px;
width:50%;
height:100px;
}
<div class="container">
<div class="outer">
<div class="left-box">
some text
</div>
<div class="right-box">
text/image here
</div>
</div>
</div>
【问题讨论】:
-
这取决于您的要求。当页面或容器滚动时会发生什么?是否有任何 div 必须保持锁定在其位置? div可以有固定的宽度吗?
-
这是一个正常的页面,不需要锁定在它的位置。请参阅小提琴jsfiddle.net/ys5mvjt6/1 一些问题,(图像截止/滚动条可见。)我期望的是,右侧图像需要调整为窗口大小。
标签: html css browser alignment containers