Home > Enterprise >  My card content won't center correctly in bootstrap 5
My card content won't center correctly in bootstrap 5

Time:11-24

I want to centre all of the content of my cards but it's all going to the right side

my card code:

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap demo</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>

<body>
  <h1>Hello, world!</h1>



  <div >

    <div >
      <div >
        <div >
          <img src="img/oranvour.png" alt="dfg juice" >
          <div >
            <h5 >Juice</h5>
            <p >Price: $199.00</p>

            <div >
              <label  for="typeNumber">amount</label>
              <input type="number" id="typeNumber"  />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL jjXkk Q2h455rYXK/7HAuoJl 0I4" crossorigin="anonymous"></script>
</body>

</html>

I am expecting all of the content to be in the centre of the card not to align-right

CodePudding user response:

You need to set the text-center class on card like that:

<div  style="width: 18rem;">

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap demo</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>

<body>
  <h1>Hello, world!</h1>

  <div >

    <div >

      <div >
        <div  style="width: 18rem;">
          <img src="https://images.unsplash.com/photo-1669111957903-36e4da270ef1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80" alt="" >
          <div >
            <h5 >Juice</h5>
            <p >Price: $199.00</p>

            <div >
              <label  for="typeNumber">amount</label>
              <input type="number" id="typeNumber"  />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL jjXkk Q2h455rYXK/7HAuoJl 0I4" crossorigin="anonymous"></script>
</body>

</html>

CodePudding user response:

just add "mx-auto" in the class above the card like this :

<div >
  <div >
   <div >
      <div >
        <img src="img/oranvour.png" alt="dfg juice" >
        <div >
            <h5 >Juice</h5>
            <p >Price: $199.00</p>

            <div >
              <label  for="typeNumber">amount</label>
              <input type="number" id="typeNumber"  />
          </div>                      
        </div>
      </div>
    </div>
  </div>
<div/>
  • Related