无法使Bootstrap卡片正确对齐文本。

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

Can't get Bootstrap Card to align text properly

问题

这是一个排行榜类型的东西,用于工作。

这是一个Bootstrap元素,我想要数字右对齐,数字应该垂直对齐。查看当前显示的示例图片:点击这里查看图片

这是代码,我使用EJS来循环处理这个,因此只有一个实例,我已将所有的EJS元素转换为普通的HTML:

<div class="card d-flex" style="display: inline-block; width: 350px; float: right; margin-right: 100px;">
    <ul class="list-unstyled card-body mb-0 pb-0">
        <li class="media mb-3">
            <div class="media-body">
                <div style="display: inline-block;">
                    <strong style="font-size: 20px;">Jordan</strong>
                    <p class="float-right pull-right" style="padding-left: 200px; font-size: 20px; font-weight: 650;">12</p>
                </div>
                <div class="progress mb-1" style="height: 10px;">
                    <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 50%; background-color: green;" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>
        </li>
    </ul>
</div>

尝试使用text-alignfloatpull-righttext-rightmt-auto等方法都没有生效。

英文:

I have a leaderboard sort of thing, this is for something at work.

This is a bootstrap element and I want the numbers to be aligned to the right, the numbers should be vertically aligned. See example of how it currently looks on the image: enter image description here

Here is the code, I use EJS to for loop this, hence only 1 instance, I've translated all EJS elements to normal HTML:

&lt;div class=&quot;card d-flex&quot; style=&quot;display: inline-block; width: 350px; float: right; margin-right: 100px;&quot;&gt;
    &lt;ul class=&quot;list-unstyled card-body mb-0 pb-0&quot;&gt;
      &lt;li class=&quot;media mb-3&quot;&gt;
        &lt;div class=&quot;media-body&quot;&gt;
          &lt;div style=&quot;display: inline-block;&quot;&gt;
            &lt;strong style=&quot;font-size: 20px;&quot;&gt;Jordan&lt;/strong&gt;
            &lt;p class=&quot;float-right pull-right&quot; style=&quot;padding-left: 200px; font-size: 20px; font-weight: 650&quot;&gt;12&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class=&quot;progress mb-1&quot; style=&quot;height: 10px;&quot;&gt;
            &lt;div class=&quot;progress-bar progress-bar-striped progress-bar-animated&quot; role=&quot;progressbar&quot; style=&quot;width: 50%; background-color: green&quot; aria-valuenow=&quot;15&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/li&gt;

    &lt;/ul&gt;
  &lt;/div&gt;

Tried using text-align, float, pull-right, text-right, mt-auto etc. doesn't do anything.

答案1

得分: 0

如果您不需要它出于其他原因,您可以将 display: inline-block 替换为 display: flex; justify-content: space-between。这样可以使它占据两个文本元素之间的最大空间,姓名的长度不会影响数字的位置 无法使Bootstrap卡片正确对齐文本。

英文:

If you don't require it for some other reason you can replace display: inline-block with display: flex; justify-content: space-between

This should space it so it takes up the maximum amount of space between the 2 text elements and the length of the name wont effect the number position 无法使Bootstrap卡片正确对齐文本。

huangapple
  • 本文由 发表于 2023年2月6日 08:56:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356547.html
匿名

发表评论

匿名网友

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

确定