CSS 左右对齐文本

标签 css flexbox

<分区>

我有这个:

<div style="background-color: #25a0da; color: White; margin: 0">
  <h1 style="margin: 0  20px; padding: 0; line-height: 52px;">
    <span style="display: flex; justify-content: flex-start"><asp:Literal ID="litDateRange4" runat="server"></asp:Literal></span>
    <span style="display: flex; justify-content: flex-end"> <asp:Literal ID="litPendingProfit" runat="server"></asp:Literal></span>
  </h1>
</div>

我希望第一个 span 向左对齐,第二个向右对齐,这是有效的,但它们出现在不同的行上。

对 flex 很陌生。

最佳答案

I want the first span to be snapped to the left, and the second one to the right

您可以使用 flexbox 布局模型来实现这一点。

h1 {
  display: flex;
  justify-content: space-between;
}
<div style="background-color: #25a0da; color: White; margin: 0">
  <h1 style="margin: 0  20px; padding: 0; line-height: 52px;">
    <span style="display: flex; justify-content: flex-start">aaa</span>
    <span style="display: flex; justify-content: flex-end"> bbb</span>
  </h1>
</div>

关于CSS 左右对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57727689/

相关文章:

html - 一个 SVG 的多个路径的多个复选框

html - 仅使用 Flex 功能创建特殊网格

css - flexbox 和 wrap 属性

css - 与 Chrome 相比,Firefox 忽略了 SVG 文本中的多个空格并将它们显示得更小

javascript - 实现全宽 slider

javascript - 滚动到该 div 后如何使 div 固定?

html - 响应式 flexbox 问题中的图像

html - flex 元素未包装在列方向容器中

html - flexbox 和屏幕尺寸的问题

CSS 媒体查询,它不会将属性从 1024 更改为 768