-1

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.

disinfor
  • 10,865
  • 2
  • 33
  • 44
inurudum
  • 11
  • 6
  • 1
    Use `justify-content-center` class in *row* element instead of `row-sm-offset-5` – Raeesh Alam Feb 22 '22 at 04:06
  • As @RaeeshAlam said, replace `row-sm-offset-5` with the `justify-content-center`. `row-sm-offset-5` doesn't do anything. Offsets are for columns, not the row: https://getbootstrap.com/docs/5.0/layout/columns/#offsetting-columns – disinfor Feb 22 '22 at 04:24

3 Answers3

-1

You can use justify-content-center class in row element

Ipal
  • 135
  • 1
  • 10
  • I added a code snippet to the question, so you can edit your question to include the actual code in your answer. – disinfor Feb 22 '22 at 04:25
-1
<div class="container">
    <div class="row justify-content-center">
      <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>
Kartik Jain
  • 49
  • 1
  • 7
-1

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>
  • Glad you got it solved @inurudum. As you know a full width in Bootstrap is `col-12` so with anything less than that you can always use `mx-auto` to center the column. – Cutey from Cute Code Feb 24 '22 at 18:29