Tips for aligning a Bootstrap row in the center

I need some help centering this temperature converter on the page. I've tried adjusting the columns and rows, but the alignment is still off. Here is a screenshot for reference:

https://i.sstatic.net/xR8rA.png

Below is the code I am using:

<!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 Converter</title>

  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b4b9b9a2a5a2a4b7a696e3f8e7f8e5">[email protected]</a>/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 Converter
        </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>

If you have any suggestions on how to fix the alignment, please let me know. Thank you!

Answer №1

Make sure to avoid centering the Row. Instead, focus on centering the Col inside the Row using the class mx-auto. This will ensure that everything is perfectly centered with auto margins on the left and right.

<div class="row">
   <div class="col-lg-4 content mx-auto">
       <!-- Add your content here -->
   </div>
</div>

Answer №2

Apply the justify-content-center class to the row element

Answer №3

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

        <h2>
          Temperature Converter
        </h2>

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

          </div>

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

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

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

    </div>
  </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a dynamic navigation bar featuring an interactive search option

I am currently working on creating a responsive navigation bar with bootstrap, similar to the one shown in this example. However, I am facing issues with aligning the search button correctly and ensuring that the tabs remain intact when collapsed. Instead ...

Responsive design not functioning properly for Bootstrap columns on website

If my display currently looks like this with three equally distanced images at the top and two images at the bottom, how can I achieve that design? I attempted using Bootstrap by setting the top 3 images as <div className="col-md-4"> and t ...

Tips on expanding the content of a page all the way to the bottom of

Currently, I am facing an issue while working on a Joomla site where I am struggling to extend a page to the bottom of the screen. Attached is an image of the page: https://i.sstatic.net/uHZ9Q.png and below is the HTML code for the page: <div id="free_ ...

Issue with Ionic Grid: Row not occupying entire width of the container

Currently, I am working on creating a straightforward grid consisting of one row and seven columns. Each column holds a div with a single letter of text inside. My intention is for these columns to evenly space out across the page by default, but unfortu ...

Room available on the body's right side for tiny gadgets

I'm currently facing a website issue while using Bootstrap. Everything seems to be working fine until I attempt to check the responsiveness of my website. There appears to be an excessive white space on the right side of my body, but only in a specifi ...

Implementing the <bgsound> element in HTML

Can you explain the purpose of the <bgsound> element in HTML? ...

Struggling with getting basic CSS to work with React's MUI framework

I've been attempting to incorporate basic CSS with MUI components. According to their website, it should be feasible. https://material-ui.com/guides/interoperability/#plain-css But unfortunately, I'm having trouble getting it to function prope ...

How to reference a ListView control using its DataSource in a C# class

Currently, I have a ListView embedded in a webpage connected to a C# class datasource called CommentsDAO. This class contains the necessary methods to retrieve or delete data from the ListView. While data retrieval is successful, deleting a row proves to b ...

Present XML data on an HTML page to generate interactive form features

I have an application that features a checkbox tree. I would like to automatically pre-select those checkboxes if the user had previously checked them. To achieve this, I receive XML data from my backend Perl script which contains information on which che ...

Adjust the size of a Highcharts chart before printing

I'm facing an issue with a chart that doesn't have a specified height or width. My goal is to print the graph in a taller and larger size when I click on the print button. I attempted to use setSize() function, but since there are no original di ...

Tips to close a Navbar Dropdownmenu upon opening a new one?

I encountered an issue with multiple dropdown menus within a navbar. When I activate both in succession, they both remain open: https://i.sstatic.net/Cax4Y.gif Is there a way to set up the navbar or dropdown menu to automatically close the first dropdown ...

Create a stylish frame for designated rows within a table

Col1 Col2 Col3 Col4 Col5 Col6 Row11 Row12 Row13 Row14 Row15 Row16 Row21 Row22 Row23 Row24 Row25 Row26 Row31 Row32 Row33 Row34 Row35 Row36 Looking for a way to add a border around rows with matching values in the first column, or around a specif ...

Ways to verify if an element includes a specific class in JavaScript

When the mouse hovers over each paragraph within the DIVs with the "change" class, the font color should turn red, and revert back to black when the mouse is not on them. Here's my current code: var paragraphs = document.getElementsByTagName('p& ...

How to access a shadowroot element using R Selenium

Currently, I'm dealing with web scraping where one of the websites presents a 'Accept cookies' button within a shadow root. To address this issue, I sought assistance on how to click this button in discussions found here: Click on accept co ...

Express-minify is having trouble loading the CSS file. If we remove a portion of the file, it should be able

After implementing the express-minify middleware, I encountered an issue with loading the attached CSS file. Even after validating the CSS using an online service, no errors were detected. I attempted to debug by gradually removing elements, and the prob ...

Mastering the art of integrating two applications in Django involves understanding how to properly

Hey there, I'm currently diving into Django and I have a question regarding making my two apps work together. Here's how my folders are structured: mysite/ --/app1 (blog app) --/app2 (a list of users that sign up with a form) --/mysite --db --m ...

Inaccurate sizing of popup dialogs on SharePoint 2010

Currently, I am in the process of revamping a SharePoint 2007 web application to SharePoint 2010. I was surprised to find that the popup dialog boxes for new items, edit, etc. have inline styles for fixed width and height. Below is an example where div.ms ...

Creating an XPath expression for selecting multiple siblings of a div tag

Currently, I am working on writing an XPath expression for a specific section of code: <div class="line info"> <div class="unit labelInfo TextMdB">First</div> <div class="unit lastUnit"> <div clas ...

What is the best way to showcase a table below a form containing multiple inputs using JavaScript?

Context: The form I have contains various input fields. Upon pressing the [verify] button, only the "first name" is displayed. My goal is to display all input fields, whether empty or filled, in a table format similar to that of the form. Exploration: ...

Renew the Look of Dynamic HTML with Updated Styles

In the middle of my website, there is a console that contains links to dynamically update its content using javascript. Everything works smoothly, but the new HTML added dynamically does not have any styling applied to it. Is there a way to refresh the CS ...