html - float :right is limited by its parent div, 使其右对齐/向下对齐

标签 html css alignment

我正在尝试获取一个工具栏 div,其中左侧 div 在屏幕左侧对齐,右侧 div 在屏幕最右侧对齐。

我已经尝试为父分隔线设置固定的分隔线设置,但没有一种方法看起来非常直观。我不能为父 div 使用 100vw,因为左侧有一个工具栏。

.dashboard_secondary_toolbar{
    /* display:inline-block; */
    flex: 1;
}

.dashboard_secondary_toolbar_left{
    float: left;
}

.dashboard_secondary_toolbar_right{
    float: right;
}
<div class = "dashboard_secondary_toolbar">
    <div class = "dashboard_secondary_toolbar_left">
        <p> align me left </p>
    </div>
    <div class = "dashboard_secondary_toolbar_right">
        <p> align me right </p>
    </div>
</div>

最佳答案

只需使用 flex 而不是 float 每个 div

.dashboard_secondary_toolbar {
  display: flex;
  flex: 1;
  justify-content: space-between;
}
<div class="dashboard_secondary_toolbar">
  <div class="dashboard_secondary_toolbar_left">
    <p> align me left </p>
  </div>
  <div class="dashboard_secondary_toolbar_right">
    <p> align me right </p>
  </div>
</div>

关于html - float :right is limited by its parent div, 使其右对齐/向下对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56839354/

相关文章:

html - 在 Seaside 中创建超链接,将图像作为可点击项

html - 为什么这个 div 不会调整给定位置 :relative; left:0px; right: 200px; 的大小

jquery - curvetext.js 不适用于任何文本动画

jquery - 动画图像的 CSS 给出不同的结果

php - 如何使用javascript编写动态文本

javascript - 使用 CSS 和 jQuery 的动态的、表格式的列表项行

css - 绝对内部相对溢出即

html-table - 在bulma中对齐表格单元格(td)内容

css - 当博客标题长度不同时如何使用 flexbox 使元素对齐

html - 如何将图标左对齐,文本右对齐?