【问题标题】:Align multiple div next to each other (fixed) [duplicate]将多个 div 彼此相邻对齐(固定)[重复]
【发布时间】:2018-07-22 17:23:43
【问题描述】:

我想在自定义 MainDiv 中对齐多个(在本例中为 3 个)div 以获得如下结果:

<div style="position: fixed; width:100%; height: 12%; left:0%; top: 0%; background: black">
  <div style="color: white; left: 5%; margin-top: 5%; position: fixed; font-size: 10px">INFORMATION A</div>
  <div style="color: white; margin:0 auto; margin-top: 5%; display: table; font-size: 10px">INFORMATION B</div>
  <div style="color: white; right: 5%; margin-top: 5%; position: fixed; font-size: 10px">INFORMATION C</div>
</div>

但是这段代码似乎不起作用,因为这是我得到的结果:


我该如何解决这个问题?

【问题讨论】:

  • 需要固定位置吗?

标签: javascript html css alignment


【解决方案1】:

你可以使用弹性布局

<div style="position: fixed; width:100%; height: 50%; left:0%; top: 0%; background: black; display: flex; justify-content: space-between;">                           
  <div style="color: white; left: 5%; margin-top: 5%; position: fixed; font-size: 10px">INFORMATION A</div>
  <div style="color: white; margin:0 auto; margin-top: 5%; display: table; font-size: 10px">INFORMATION B</div>
  <div style="color: white; right: 5%; margin-top: 5%; position: fixed; font-size: 10px">INFORMATION C</div>
</div>

【讨论】:

  • 固定位置的弹性布局?
  • 是吗? flex-layout 将其内容的行为改变为灵活,不关心固定位置。
  • 真的吗??阅读此内容:已修复:元素 已从正常文档流中删除;没有为页面布局中的元素创建空间。
  • @kurtwellitis 请不要考虑这样的坏 hack ...在这种情况下添加 flex 工作仅仅是因为其中一个元素不固定,因此属于流程...所以它被改变了伸缩项目,不再是块项目!
  • 你的权利@TemaniAfif
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 1970-01-01
  • 2013-06-16
  • 2023-04-06
  • 1970-01-01
相关资源
最近更新 更多