HTML Bootstrap编码 | 卡片

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

HTML Bootstrap Coding | Cards

问题

我正在使用Bootstrap创建我的网站的卡片。我试图将网格图片卡片的卡片内容居中。我尝试在不同部分应用class="center",但项目仍然都左对齐。这是其中一个网格的片段:

<div class="col">
    <div class="card">
        <i class="fa fa-medkit fa-5x" aria-hidden="true" class="center"></i>
        <div class="card-body">
            <h5 class="card-title">Allied Health</h5>
            <p class="card-text"></p>
        </div>
    </div>
</div>

我添加了class="center",甚至添加了class="all contents aligned center"到不同的部分,但没有变化。

英文:

I am using a bootstrap to create cards for my site. I am trying to center the card contents of the grid image cards. I have tried applying class="center" into various parts and the items are still all aligned left. This is a snippet of one of the grids

&lt;div class=&quot;col&quot;&gt;
    &lt;div class=&quot;card&quot;&gt;
      &lt;i class=&quot;fa fa-medkit fa-5x&quot; aria-hidden=&quot;true&quot; class=&quot;center&quot;&gt;&lt;/i&gt; 
      &lt;div class=&quot;card-body&quot;&gt;
        &lt;h5 class=&quot;card-title&quot; &gt;Allied Health&lt;/h5&gt;
        &lt;p class=&quot;card-text&quot; class=&quot;center&quot;&gt;&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

I added class="center" and even class="all contents aligned center" into different parts, but there was no change.

答案1

得分: 0

将属性 display: flexbox; 添加到你的 div 元素中。

你应该在其中添加一个 justify-content-center 类,以使内容在 flexbox 方式下居中。我可以给你一个有用的链接:在Bootstrap中居中元素

英文:

add the attribute display: flexbox; to your div element.

You should add a justify-content-center class in it, to make it center the content in a flexbox way.
I can give you a useful link :center element in bootstrap

答案2

得分: 0

text-center添加到card元素中。同时,请注意,每个HTML元素只能有一个类属性。要将多个类添加到单个元素中,需要用空格分隔它们。

英文:

Add text-center to the card element.

Also, note that you can only have one class attribute per html element. To add multiple classes to a single element, you separate them with a space.

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

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

&lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
&lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
&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;col-6&quot;&gt;
    &lt;div class=&quot;card text-center&quot;&gt;
      &lt;i class=&quot;fa fa-medkit fa-5x&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; 
      &lt;div class=&quot;card-body&quot;&gt;
        &lt;h5 class=&quot;card-title&quot;&gt;Allied Health&lt;/h5&gt;
        &lt;p class=&quot;card-text&quot;&gt;Some card text here...&lt;/p&gt;
        &lt;a href=&quot;#&quot; class=&quot;btn btn-primary&quot;&gt;Go somewhere&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月14日 03:01:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440177.html
匿名

发表评论

匿名网友

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

确定