PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 30, 2022

[FIXED] How can I center bootstrap5 card

 September 30, 2022     bootstrap-5, css     No comments   

Issue

I'm trying to add this card to be on a center of web browser but I can't, is any body can show me how to center card in either bootstrap5 or css3?

I'm using Bootstrap5.

The Card

<div class="container">
    <div class="row">
        <div class="col">
            <div class="card" style="width: 18rem;">
                <img src="https://thumbs.dreamstime.com/b/young-black-man-smiling-to-camera-his-desk-office-young-black-man-smiling-to-camera-his-desk-office-108952653.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                  <h5 class="card-title">Card title</h5>
                  <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="btn btn-primary">Go somewhere</a>
                </div>
              </div>
        </div>
    </div>
  </div>

Even when I try to add justify-content-center in a row, it does not work.

<div class="container">
    <div class="row justify-content-center">
        <div class="col">
            <div class="card" style="width: 18rem;">
                <img src="https://thumbs.dreamstime.com/b/young-black-man-smiling-to-camera-his-desk-office-young-black-man-smiling-to-camera-his-desk-office-108952653.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                  <h5 class="card-title">Card title</h5>
                  <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="btn btn-primary">Go somewhere</a>
                </div>
              </div>
        </div>
    </div>
  </div>

Solution

you could try "d-flex justify-content-center" at

<div class="col d-flex justify-content-center"> 

it is due to the display of flex and flex attributes only affects the immediate child. Which means if your .card needs to have the "justify-content-center" style, it has to be set to its immediate parent.



Answered By - Kurt Chun
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing