html - 水平线上的两个 div——左对齐和右对齐

标签 html inline

我需要带有两个内联 div 的顶部标题 - 左对齐和右对齐。请检查代码。它是否正确?我需要在哪里添加 div class="clearfix"

<div class="container">
<div class="columns">
       <div id="div-left">
          Left aligned text
        </div>

        <div id="div-right">
          Right aligned text
        </div>
    </div>
</div>

#div-left {
  float:left;
  display:inline
}

#div-right {
  float:right;
  display:inline
}

最佳答案

将两个 div 包裹在一个包含的 div 中,并为内部 div 提供 float:left 和 float:right,如果您愿意,还可以提供一些宽度 :)

<div>
  <div style="float:right">To the right</div>
  <div style="float:left">To the left</div>
</div>

关于html - 水平线上的两个 div——左对齐和右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20577389/

相关文章:

html - 需要通过 css 更改 html 值,如下所述。我使用的是wordpress,所以不好编辑核心文件

html - CSS:多次分配样式时会发生什么?

c++ - 在 MinGW 中导入内联函数

compiler-construction - F# 编译器如何/何时提前读取类型推断?

c++ - 如何告诉编译器不要内联类定义中定义的方法,under/ob1 优化?

python - HTML解析得到我想要的

html - 按钮文本位置与浏览器不同

php - 单击从 mysql 加载到表中

html - 使用 Bootstrap 的 Logo 图像和搜索框在调整浏览器窗口大小时重叠

jquery - 如果子div不包含某些内联css,则将某些内联css添加到父div