html - 如何对齐容器内的一个 div 而另一个对齐到浏览器窗口的右端?

标签 html css browser alignment containers

我在一个容器内有 2 个 div,我想通过 css 将一个 div 设置为左​​对齐到容器,另一个设置为与浏览器的右端对齐。这可能吗?

Example Image

有人帮我解决这个问题吗?

.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>

最佳答案

您可以使用 position fixed,然后 left 0 用于要左对齐的 div 和 right 0 用于要右对齐的 div。 Css 会是这样的

.divleft {
    position: fixed;
    left: 0;
}

.divright {
    position: fixed;
    right: 0;
}

关于html - 如何对齐容器内的一个 div 而另一个对齐到浏览器窗口的右端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639148/

相关文章:

html - 兼容的 HTML 和 CSS

html - 柔性 : Align multiple items as a table

php - 从 Jquery $.getJSON 方法获取数组的全局数组到 REUSE 数组

javascript - 从单个下拉框中选择多个选项和值

html - 如何在CSS中进行硬币翻转变换

html - 图像未正确对齐的网格布局

html - 如何在文本下方添加多色边框

javascript - 如何确定浏览器UI事件是否具有相同的 "cause"

c# - 使用 C# 从 WebBrowser 中的 JS 获取值

javascript - 访问系统光标图像形式的JavaScript