Flex项目未将其内容对齐到右边。

huangapple go评论45阅读模式
英文:

Flex item not aligning its content to the right

问题

我有以下的HTML代码,我想要将右侧flex项目的内容右对齐:

<!-- language: lang-html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="d-flex">
    <div class="flex-grow-1">
        Line 1
        <br />Line 2
    </div>
    <div class="ml-auto">
        <strong>Line 3</strong><br/>
        Longer line 4
    </div>
</div>

然而,内容没有被右对齐。也就是说,文本 Line 3Longer line 4 应该是右对齐的。

我漏掉了什么?

英文:

I have the following HTML where I would like to right align the contents of the right flex item:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css&quot; integrity=&quot;sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm&quot; crossorigin=&quot;anonymous&quot;&gt;

&lt;div class=&quot;d-flex&quot;&gt;
    &lt;div class=&quot;flex-grow-1&quot;&gt;
        Line 1
        &lt;br /&gt;Line 2
    &lt;/div&gt;
    &lt;div class=&quot;ml-auto&quot;&gt;
        &lt;strong&gt;Line 3&lt;/strong&gt;&lt;br/&gt;
        Longer line 4
    &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

However, the contents are not being right-aligned. ie. The text Line 3 and Longer line 4 should be right-aligned.

What am I missing?

答案1

得分: 0

class="text-right"

Line 3
Longer line 4
英文:

use class="text-right"

&lt;div class=&quot;text-right&quot;&gt;
   &lt;strong&gt;Line 3&lt;/strong&gt;&lt;br/&gt;
    Longer line 4
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年6月22日 11:34:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定