简体   繁体   English

如何在不居中对齐内部文本的情况下居中对齐引导卡?

[英]How can I center align bootstrap cards without center aligning the text inside?

I am using the code provided by bootstrap for the cards on their website but cannot seem to center align the cards to my page without also aligning the text within the cards.我正在使用 bootstrap 为其网站上的卡片提供的代码,但似乎无法将卡片居中对齐到我的页面而不对齐卡片中的文本。

This is what I have right now --> https://i.imgur.com/f06m0Qc.png这就是我现在拥有的 --> https://i.imgur.com/f06m0Qc.png

<div class="card col-33" style="width: 16rem; margin-right: 2rem;">
   <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
       <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
         <a href="#" class="card-link">Card link</a>
         <a href="#" class="card-link">Another link</a>
             </div>
<div class="card col-33" style="width: 16rem; margin-right: 2rem;">
   <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
       <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
         <a href="#" class="card-link">Card link</a>
         <a href="#" class="card-link">Another link</a>
             </div>
<div class="card col-33" style="width: 16rem; margin-right: 2rem;">
   <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
       <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
         <a href="#" class="card-link">Card link</a>
         <a href="#" class="card-link">Another link</a>
             </div>

The style that I am wanting to achieve is this --> https://i.imgur.com/PaonbTR.png我想要实现的风格是这样的 --> https://i.imgur.com/PaonbTR.png

Not worried about the style right now as I can change that in CSS.现在不担心样式,因为我可以在 CSS 中更改它。

Put your code into a div and add a class name for example "centered" Your CSS may look like this :将您的代码放入一个 div 并添加一个类名,例如“居中”您的 CSS 可能如下所示:

.centered {
    margin-right:auto; 
    margin-left:auto ; 
}
 

Please check below link.请检查以下链接。 Hope this help.希望这有帮助。 thanks谢谢

http://jsfiddle.net/3vxtw786/ 777 http://jsfiddle.net/3vxtw786/ 777

I have added a parent dive with outer class and gave dispaly: flex and justify-content:center .我添加了一个带有外部类的父级潜水,并给出了dispaly: flexjustify-content:center this will bring all the dive in the center这将使所有的潜水都集中在中心

below is the link for your ref.以下是您的参考链接。https://www.w3schools.com/cssref/css3_pr_justify-content.asphttps://www.w3schools.com/cssref/css3_pr_justify-content.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM