how to center a bootstrap row

Issue

I am trying to center this temperature convertor and I am not able to do so. everything in the column seems solid but the row is not. I have attached a picture below.

enter image description here

Here is my code.

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

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Temperature convertor</title>

  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">


  <style>
    .content {
      padding-top: 30px;
      background-color: #eeeeee;
    }
    
    body {
      background: linear-gradient(to left, black, purple);
    }
  </style>


</head>

<body>



  <div class="container">
    <div class="row row-sm-offset-5">
      <div class="col-sm-3 text-center content">

        <h2>
          Temperature convertor
        </h2>

        <form action="">
          <div class="form-group">
            <label for="userInput"> Enter the temperature:  </label>
            <input type="number" id="userInput">

          </div>

          <div class="form-group" style="margin-top: 10px;">

            <input type="button" value="To Celsius" onclick="toCelsius()">
            <input type="button" value="To Fahrenheit" onclick="toFahrenheit()">
          </div>
        </form>

        <p id="result"> </p>
      </div>

    </div>
  </div>




  <!-- javascript file placed right before closing tag to reduce log times caused by script -->
  <script src="alert.js"></script>
</body>

</html>

Please let me know what I’m doing wrong.

Solution

Hopefully you do not need to center the Row. You can center the Col within the Row by using mx-auto. That will create auto margins to the left and right and everything will be centered perfectly.

<div class="row">
   <div class="col-sm-3 content mx-auto">
       <!-- Your form -->
   </div>
</div>

Answered By – Cute Code Rob

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.