Tips for centering div content using bootstrap

https://i.sstatic.net/GtIi0.pngI am trying to align 3 divs in a row at the center of the page.

<div class="row">
  <div class="center">
    <div class="col-sm-4" id="ph-container"></div>
    <div class="col-sm-4" id="do-container"></div>
    <div class="col-sm-4" id="water-temperature-container"></div>
  </div>
</div>

Answer №1

Instead of using center, it is recommended to use text-center.

<div class="row">
  <div class="text-center">
    <div class="col-sm-4 col-sm-offset-1" id="ph-container"></div>
    <div class="col-sm-4" id="do-container"></div>
    <div class="col-sm-4" id="water-temperature-container"></div>
  </div>
</div>

If you add an offset, the view will be improved greatly.

Answer №2

There are a total of 12 columns available, but using all 12 columns (4+4+4=12) will not center the content as they will take up the entire width of the parent block. To ensure proper alignment, it is recommended to use fewer columns.

<div class="row">
    <div class="col-sm-pull-1 col-sm-3" id="ph-container"></div>
    <div class="col-sm-3" id="do-container"></div>
    <div class="col-sm-3" id="water-temperature-container"></div>
</div>

Answer №3

<div class="row">
    <div class="col-sm-offset-1 col-sm-3" id="ph-container"></div>
    <div class="col-sm-3" id="do-container"></div>
    <div class="col-sm-3" id="water-temperature-container"></div>
</div>

Adjusting the width of these three divs slightly will center them on the page by pushing them from the left.

Keep in mind that changing the div widths may affect the appearance of your graphs, so you may need to update your styling accordingly.

You may find this resource helpful: Bootstrap 3 1.5 column offset

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

Unable to fetch the Observable value

I have a function that returns an Observable<Person[]>, where Person is my model: export interface Person { id: string; age: number; } Now in my component.ts, I am calling this function and aiming to retrieve the array to display it in the HTML ...

Animation fails to operate on the second ajax request

On my main page and subpage, I have an ajax call that displays the subpage. Everything works fine with the animation when loading the subpage by clicking on the menu: $(document).ready(function(){ $(".transactions").on("click", function (event) { ev ...

Upon clicking the Submit button in Selenium Webdriver (Java), the passwords field is cleared and the flow is halted

I am encountering a problem in IE11 while using Selenium in Java. After inputting the username and password into the fields, when I click the Submit button, the password field is cleared and the automation process cannot proceed. Even though it works fine ...

Searching for the right approach to implementing useState with count in order to efficiently add new items in Next.js

Although my code currently functions, I have a feeling that I am not utilizing the useState and useEffect hooks in the best way to achieve my ultimate goal. Let me explain further - I have a button with an onClick event in a separate component, which passe ...

A total of 12 columns within the Foundation grid layout, with ample space for customization

My layout structure is as follows: <div class="row"> <div class="columns small-12 large-6 medium-12 panel-wrapper"> Box no 1 </div> <div class="columns small-12 large-6 medium-12 panel-wrapper"> Box n ...

Error: 'fs' module not found in React.js and cannot be resolved

Encountering issues with tatum io v1 + react? Developers have acknowledged that it's a react problem which will be addressed in V2. In the meantime, you can utilize tatum io V1 with node js. I've included all dependencies that could potentially ...

Set the div to have a position of absolute, disregarding any other parent divs that may also have position absolute set

Is there a way to bring an outsider class <div> to the front of all others, even when all <div> elements are set as position: absolute;? How can the .free-object, which is inside .left, overlap both .left and .right? I have tried using z-ind ...

Unable to retrieve HTTP call response during debugging, although it is visible in the browser

When I send an HTTP request to create a record, I am able to see the added record id in the Network section of browsers like Chrome and Firefox. However, when I try to debug the code and retrieve the same id value, I encounter difficulties. I have tried us ...

Individual User's Time Slot

Greetings! I am in the process of developing a web application where users can seek assistance for their problems: One challenge I am facing is how to inform users of the time a question was posted in their specific time zones. For instance, if I post a ...

Looking to transfer data between pages using node.js and ejs for database access?

I am aiming to showcase the logged in username and quiz points on each page after the user logs in, and to increase the user's score when quiz answers are correct. I'm considering creating a straightforward JavaScript-based quiz, and then updati ...

Is it possible to effectively integrate both Bootstrap 5 and Bootstrap 3 in the same project?

The question is clear and concise. As my project is currently utilizing bootstrap 3, I find myself in need of the card class from bootstrap 5. However, when attempting to integrate bootstrap 5 into my project, I encountered issues with the styling of my ...

Integrating a search box with radio buttons in an HTML table

I am currently working on a project that involves jQuery and a table with radio buttons. Each button has different functionalities: console.clear(); function inputSelected(val) { $("#result").html(function() { var str = ''; ...

Using JavaScript onChange event with ModelChoiceField arguments

In my Django project, I have a Students model with various fields. I created a ModelChoiceField form allowing users to select a record from the Students table via a dropdown. forms.py: class StudentChoiceField(forms.Form): students = forms.ModelChoic ...

Trim the name property of an object within an object's map function if it exceeds a certain length

Imagine having an object structured like this: var fullObj = { prop1: "myProp1", subobject: { Obj1_id: { id: "Obj3_id", name: "./", otherProperties:... }, Obj2_id: { id: "Obj2_id&q ...

Angular application parametrization

My application consists of an Angular front-end, an app layer, and a DB layer. The architecture can be seen in this image. To serve the JS front-end bits to the client and proxy requests from the client to the app layer, I am using an nginx instance. If I ...

Is there a way to extract an icon from an object or array?

Currently, I am facing challenges in extracting an icon from either an object or an array for a project I am working on. My approach involves storing the icon in a variable and passing it as a prop to another component. However, the functionality is not wo ...

Incorporating a division using the data() method

Currently, I am in the process of generating a list of flash SWFs. The data for this list is retrieved through an ajax call, which returns a JSON object. To populate the rows with data, I utilize my makeAppRow function. makeAppRow = function(myData) { ...

What is the best way to style only textboxes with CSS without affecting other input types such as checkboxes?

If attribute selectors were universally supported by all browsers, we could effortlessly implement the following styling: input[type='text'] { font:bold 0.8em 'courier new',courier,monospace; } input[type='radio'] { margin:0 ...

Selenium was unable to find the p tag element on the webpage

I apologize for reaching out to you all for assistance with such a basic task, but I have tried everything in my toolkit and still can't seem to figure it out. I've experimented with partial xpath, full xpath, and various CSS selectors. I am see ...

Having trouble setting a background image for a specific DIV element in HTML

I am in the process of updating my webpage, and need some assistance implementing a small background image. Here is what I have done so far: https://i.sstatic.net/nTxtD.png Below is the marked section where I am trying to add the background image: https ...