Achieving horizontal center alignment for two rows in bootstrap

I'm in the process of building a website that features two rows with 3 columns each. For some reason, all my content is aligned to the left. Do you see anything wrong with my code?

Below is the code snippet I'm using:

<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title> Delightful Days Daycare</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <script src="https://use.fontawesome.com/b1366dc4f6.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
        <!-- Header -->
    </head>
    <body>
        <div>
            <div class="background-box">
                <div class="row">
                    <div class="box-1 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button1"><a class="box-text" href="about-us.html">ABOUT US</button></a></h2><img src="img/info.png" class="about-img">Learn more about Mrs. Chris and Delightful Days </div>
                    <div class="box-2 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button2"><a class="box-text" href="photos.html">PHOTOS</a></button></h3><img src="img/photos.png" class="photos-img">View our photo gallery</div>
                    <div class="box-3 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button3"><a class="box-text" href="calendar.html">CALENDAR</a></button></h3><img src="img/calendar.png" class="cal-img">Stay up to date with our official calendar to view holidays and closed days</div>
                </div>
                <div class="row">
                    <div class="box-4 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button4"><a class="box-text" href="contact-us.html">CONTACT US</a></button></h3>
                        <img src="img/phone.png" class="phone-img">Need to get in touch? View our contact page for more information </div>
                    <div class="box-5 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button5"><a class="box-text" href="openings.html">OPENINGS</a></h2></button>
                        <img src="img/open.png" class="open-img">View available openings </div>
                    <div class="box-6 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button6"><a class="box-text" href="pricing.html">PRICING</a></button></h3>
                        <img src="img/money.png" class="pricing-img">View our pricing page for more information</div>
                </div>
            </div>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </body>
</html>

This is how my CSS is styled:

.background-box{
    background-color: #4c4c4c;
    height: 1000.5px;
    color: white !important;
    font-size: 20px;
    text-align: center;
    position: auto;
    display: block;

}

/* Additional box styles go here... */

.box-text{
    color: white;
    font-family: "Source Sans Pro";
    font-weight: 600;
    font-style: normal;
    font-size: 26px;
}

Answer №1

If you want the container to occupy the width of the page, make sure to wrap your rows inside a container or container-fluid.

<div>
    <div class="background-box container">
            <div class="row">
                <div class="box-1 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button1"><a class="box-text" href="about-us.html">ABOUT US</button></a></h2><img src="img/info.png" class="about-img">Learn more about Mrs. Chris and Delightful Days </div>
                <div class="box-2 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button2"><a class="box-text" href="photos.html">PHOTOS</a></button></h3><img src="img/photos.png" class="photos-img">View our photo gallery</div>
                <div class="box-3 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button3"><a class="box-text" href="calendar.html">CALENDAR</a></button></h3><img src="img/calendar.png" class="cal-img">Stay up to date with our official calendar to view holidays and closed days</div>
            </div>
            <div class="row">
                <div class="box-4 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button4"><a class="box-text" href="contact-us.html">CONTACT US</a></button></h3>
                    <img src="img/phone.png" class="phone-img">Need to get in touch? View our contact page for more information </div>
                <div class="box-5 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button5"><a class="box-text" href="openings.html">OPENINGS</a></h2></button>
                    <img src="img/open.png" class="open-img">View available openings </div>
                <div class="box-6 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button6"><a class="box-text" href="pricing.html">PRICING</a></button></h3>
                    <img src="img/money.png" class="pricing-img">View our pricing page for more information</div>
            </div>
    </div>
</div>

Bootply
http://www.bootply.com/K4bQ0BrbiK

Using container-fluid

<style>
/*the wrapper class*/
    .wrapper {
        margin: 0 auto;
        width: 60%;
    }
/*change the width as required*/
</style>

<div>
    <div class="background-box container-fluid">
  <div class="wrapper">
            <div class="row text-center">
                <div class="box-1 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button1"><a class="box-text" href="about-us.html">ABOUT US</a></button></h2><img src="img/info.png" class="about-img">Learn more about Mrs. Chris and Delightful Days </div>
                <div class="box-2 col-sm-4  col-md-4 col-lg-4"><h2><button class="button button2"><a class="box-text" href="photos.html">PHOTOS</a></button></h2><img src="img/photos.png" class="photos-img">View our photo gallery</div>
                <div class="box-3 col-sm-4  col-md-4 col-lg-4"><h2><button class="button button3"><a class="box-text" href="calendar.html">CALENDAR</a></button></h2><img src="img/calendar.png" class="cal-img">Stay up to date with our official calendar to view holidays and closed days</div>
            </div>
      </div>
      <div class="wrapper">
            <div class="row text-center">
                <div class="box-4 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button4"><a class="box-text" href="contact-us.html">CONTACT US</a></button></h2>
                    <img src="img/phone.png" class="phone-img">Need to get in touch? View our contact page for more information </div>
                <div class="box-5 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button5"><a class="box-text" href="openings.html">OPENINGS</a></button></h2>
                    <img src="img/open.png" class="open-img">View available openings </div>
                <div class="box-6 col-sm-4 col-md-4 col-lg-4"><h2><button class="button button6"><a class="box-text" href="pricing.html">PRICING</a></button></h2>
                    <img src="img/money.png" class="pricing-img">View our pricing page for more information</div>
            </div>
      </div>
    </div>
</div>

Bootply
http://www.bootply.com/VNYm7x5XOI

Answer №2

Include an Additional Class

CSS

.Row-centered
 { 
   margin: auto; 
   max-width: 300px;
}

HTML

/* Add New Class Inside Row */
<div class="row Row-centered">

View Live Demo

Answer №3

To create space between columns, check out the information on column offsetting available at this link

Answer №4

One way to achieve this is by applying margin to the specified element.

.background-box{

margin-left:40px;
margin-right:40px;
margin-top:auto;
margin-bottom:auto;

 }

An alternative option is to utilize padding.

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

Get the Label Values Based on CheckBox Status

Is there a way to retrieve the values of labels corresponding to checkboxes in HTML? I have multiple labels and checkboxes next to each other, and I want to be able to get the label values if the checkbox is checked. Can you provide guidance on how to do ...

What is the best way to ensure consistent code placement at the bottom of my Django Template using inheritance?

Lately, I've been working on incorporating a footer into my layout.html file that is inherited by all other pages within my Django project. I am aiming to create a footer that remains fixed at the bottom of every webpage just like how Stack Overflow ...

What is the best way to incorporate bootstrap into a react project?

import './App.css'; import TodoList from './components/TodoList'; import 'bootstrap/dist/css/bootstrap.min.css' function App(){ return( <div className="my-todo-app"> <TodoList/> ...

A compilation of audio files compatible with all web browsers, no flash required

Currently in the process of developing a website dedicated to Songs, featuring playlists and mp3 files. I have come across various flash mp3 playlist players, however I am looking to avoid using flash and ensure compatibility with all browsers and smartp ...

What makes table layouts load pages more quickly?

Is it true that Google uses tables for layout because they load faster? I'm skeptical of this claim, as a CSS based layout with minimal and semantic markup seems like it would be more efficient in terms of page load time. It is commonly believed that ...

Avoiding Overlapping DIVs: Tips to Keep Your Elements in Place

Instead of using table-based layout, I have decided to go with a DIV-based layout in order to streamline the markup and improve page load speed. However, as I am not an expert in CSS, I find it quite challenging. Below are the CSS classes I am currently us ...

How can a dropdown menu appear above other content on a webpage?

My latest work task has me scratching my head. I've been asked to tweak these category dropdown menus at the top of the page so that when they slide down, the rest of the page shifts along with them to accommodate the change. It seems like a rather od ...

Is it possible for jQuery UI Tabs to load entire new HTML pages?

In my index.html file, I have set up 3 different tabs. Using the jQuery UI function tabs(), I am attempting to load an HTML page via Ajax. Each HTML page includes the jQuery library and contains the following code: <link type="text/css" href="css/redmo ...

Tips for seamlessly placing a div with a background image within a parent container, all while preventing any scrolling issues as the child div rotates

I created a simple demo featuring a square image with rounded corners to give it a circular appearance. The image rotates slowly, but as it moves diagonally, the horizontal width fluctuates, causing the parent container to resize. I want the parent contain ...

Use an if-else statement in jQuery with selectors to determine if a specific div element has been added to it

What if you have a main div and append one of these sub-divs to it? For example: <div class ="append"> <div id ="one"></div> <div id ="two"></div> </div> Then in jQuery, could you do something like this: if ($(.a ...

retrieve the value of a textarea element from an HTML table

Is there a way to extract data from a nested table's textarea using the row index? I attempted the following code snippet but it did not work. var note = document.getElementById($index).cells[3]; var y = document.getElementsByTagName("textarea").valu ...

Tips for displaying the CSS3 background image on your website

My website is not displaying the background-image with the URL img/hero.jpg. I attempted using ../img/hero.jpg but still no success. Are there any solutions to this issue? I also experimented with a PDF image, but it did not work either. ...

The error message indicates a BadRequestKeyError: KeyError was raised with the specific key 'nume_pacient' missing

When the button is pressed, I need to extract the text from my input with the name "nume_pacient", pass it to a Python code, and use it in a database query. The results should then be displayed on the same page. HTML PAGE: {% extends "base.html" %} {% blo ...

Having issues with the toggle display button functionality not working properly in Angular when using click()

One of the files in my project is named server.component.ts and another is named server.component.html. This is how my server.component.ts file is structured: import { Component } from '@angular/core'; @Component({ selector: 'app-server& ...

The html select option tag is automatically closed because of the presence of the "/" character within the dynamic value in JSP and JSTL

<select id="ordersSelect" class="drop-down" onchange="somemethod()"> <c:forEach items="${orders}" var="order" varStatus="orderStatus"> <option value="${order.id}"> ${order.publicId} </option> </c:forEach> </select> ...

Using Java Selenium to navigate a webpage using XPath

I am attempting to use selenium for the purpose of logging in, navigating, filling out a form and downloading a file. When I try to navigate by clicking on a link, it seems pretty straightforward. However, since the link does not have an ID or name attribu ...

Issues with the styling of DIV elements

Currently tackling a project that involves numerous DIVs and sections, encountering an issue with the header. When I attempt to minimize the browser window, the search bar and panes div are not staying within the "header" section as expected. The structur ...

Incorporating hyperlinks into icons

This is my first time creating a website for myself and I have added social media icons to share my social media pages. However, I am unsure of how to add links to these icons. Any assistance would be greatly appreciated. Here is the HTML code: <i ...

When two elements overlap, adjust their CSS positions to ensure responsiveness

Is there a way to adjust the position of an element when it comes into contact with another? Check out this example http://jsfiddle.net/mZYR8/1/ In the example, if .title-wrap (yellow) touches .right-wrap (orange), I want the orange element to slide unde ...

Is there a way to exclude the Unicode character from the first menu item while still utilizing it in the other items on my menu?

I have been working on customizing my menu by using the unicode character \25C6 to represent a black solid diamond as a spacer between labels. After searching for solutions on Stack Overflow, I attempted to implement the suggested method using the bef ...