Issue with Bootstrap 4's vertical alignment not being centered

There seems to be an issue with centering my h1 and paragraph. I've used the right classes and styles, but the divs containing them are not aligning properly in the center of the Row.

Despite using justify-content center and align-items center, it's not working as expected. Any insights on why this might be happening? Thank you!

    *{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    }
    
    body{
    background-color: pink;
    }
    
    .red-b{border: 4px solid red;}
    .blue-b{border: 4px solid blue;}
    .yellow-b{border: 4px solid yellow;}
    .green-b{border: 4px solid green;}
    .orange-b{border: 4px solid orange;}
    .black-b{border: 4px solid black;}
    
    /* HEADER */
    
    .main-header{
    background-image: url('header-photo.jpg');
    height: 100vh;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    }
    
    
    
    .main-header a{
    color: #fff;
    }
    
    .header-banner{
    height: 80vh;
    }
    
    h1{
    color: white;
    font-size: 100px;
    text-align: center;
    font-weight: 700;
    }
    
    @media only screen and (max-width: 1200px) {
                
    h1{
    color: red;
    }
    }
    
    @media only screen and (max-width: 992px) {
    h1{
    color: yellow;
    font-size: 70px;
    }
    }
    
    /*MAIN*/
    
    /*FOOTER*/
<!doctype html>
    <html lang="en">
      <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    
        <title>Hello, world!</title>
    
        <link rel="stylesheet" type="text/css" href="style.css">
      </head>
      <body>
        <header class="main-header">
        <div class="container">
          <nav class="navbar navbar-expand-lg navbar-dark">
            <a class="navbar-brand" href="#">START BOOTSTRAP</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
    
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
              <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                  <a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Services</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Portfolio</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Contact</a>
                </li>
              </ul>
              
            </div>
          </nav>
    
          <div class="header-banner row justify-content-center align-items-center blue-b">
            
            <div class="col-12 red-b">
              <h1>YOUR FAVORITE SOURCE OF FREE BOOTSTRAP THEMES</h1>
            </div>
    
            <div class="col-12 yellow-b">
              <p class="header-paragraph text-center">lorem ipsum blablabla Montreal Canada</p>
            </div>
    
          </div> <!-- /.row -->
          </div><!-- /.container -->
        </header>
    
        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
      </body>
    </html>

Answer №1

You should take into account align-content-center (https://getbootstrap.com/docs/4.1/utilities/flex/#align-content)

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    }
    
    body{
    background-color: pink;
    }
    
    .red-b{border: 4px solid red;}
    .blue-b{border: 4px solid blue;}
    .yellow-b{border: 4px solid yellow;}
    .green-b{border: 4px solid green;}
    .orange-b{border: 4px solid orange;}
    .black-b{border: 4px solid black;}
    
    /* HEADER */
    
    .main-header{
    background-image: url('header-photo.jpg');
    height: 100vh;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    }
    
    
    .main-header a{
    color: #fff;
    }
    
    .header-banner{
    height: 80vh;
    }
    
    h1{
    color: white;
    font-size: 100px;
    text-align: center;
    font-weight: 700;
    }
    
    @media only screen and (max-width: 1200px) {
                
    h1{
    color: red;
    }
    }
    
    @media only screen and (max-width: 992px) {
    h1{
    color: yellow;
    font-size: 70px;
    }
    }
    
    /*MAIN*/
    
    /*FOOTER*/
<!doctype html>
    <html lang="en">
      <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    
        <title>Hello, world!</title>
    
        <link rel="stylesheet" type="text/css" href="style.css">
      </head>
      <body>
        <header class="main-header">
        <div class="container">
          <nav class="navbar navbar-expand-lg navbar-dark">
            <a class="navbar-brand" href="#">START BOOTSTRAP</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
    
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
              <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                  <a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Services</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Portfolio</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Contact</a>
                </li>
              </ul>
              
            </div>
          </nav>
    
          <div class="header-banner row justify-content-center align-items-center blue-b align-content-center">
            
            <div class="col-12 red-b">
              <h1>YOUR FAVORITE SOURCE OF FREE BOOTSTRAP THEMES</h1>
            </div>
    
            <div class="col-12 yellow-b">
              <p class="header-paragraph text-center">lorem ipsum blablabla Montreal Canada</p>
            </div>
    
          </div> <!-- /.row -->
          </div><!-- /.container -->
        </header>
    
        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
      </body>
    </html>

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

Is it possible that the scroll locking feature in JS/CSS does not function properly on iOS Safari when the browser interface is hidden?

Wondering if there is a solution for preventing page scroll when a simple menu button opens a semi-transparent overlay with an opacity of 0.9. I tried using techniques like setting body: overflow hidden and position fixed, but it only works on iPhone Safar ...

Problem with overlapping content and navigation side bar in Bootstrap 4

Working on a project for my university, I utilized Bootstrap-4 to create various divisions - header, content-top-fat, content-bot-fat, and main-content. I aimed to fix the positioning of the header, content sections, and footer while allowing only the main ...

What is the method for displaying an asterisk in a select box option?

Is there a way to append an asterisk after the first option in a select element? Here is my html <select class="form-control textyformcontrol"> <option selected>Service area</option> <option>First Option</option> &l ...

What could be causing my page to appear at different heights in Safari and Firefox compared to Chrome?

I've been working on www.rootologyhealth.com and I'm stumped by the strange behavior of the Nav Bar on the homepage. It's positioned too high in Safari and Firefox, but appears perfectly in Chrome. Despite my efforts to troubleshoot, I can&a ...

Issue with Dropdown alignment in Bootstrap Navigation Menu

I'm currently utilizing Bootstrap to design a Navbar. However, I'm encountering an issue where clicking on the dropdown menu causes the items in the dropdown to extend outside of the window instead of adjusting the window size accordingly. To try ...

Is there a way to customize the Master Page in asp.net to resolve the Bootstrap4 dropdown issue? I am encountering an error message that says "Uncaught TypeError: Bootstrap

Hello everyone, I recently encountered an issue while trying to use dropdown in my project after updating to bootstrap 4. It was working perfectly fine before the update, but now I'm getting an error in the JavaScript. The error that pops up when I tr ...

Steps for creating a vertical line divider between two columns using Bootstrap 4

Looking to create a visual divider between my two div columns on the webpage. <div class="container-fluid"> <div class="row"> <div class="col-md-3"></div> <div class="col-md-9"></div> </div> </div ...

Collapse all Angular Sidemenu subitems at once

I have a Sidemenu with items and subitems. Currently, the subitems open by default but when I close one, it closes all the items together. I want to modify it so that only that specific item closes. The reopening functionality is working fine but I need th ...

Is it possible to have 3 divs with the height of the tallest

I have a unique template that I employ for crafting responsive websites. It relies on boxes with percentage widths, floats, and clears. A prime instance can be viewed via this link. Notice how the three boxes vary in height. While it's simple to set a ...

Setting the position of the searchbox in Leaflet using CSS (leaflet.extra package)

Is it possible to customize the position of the searchbox in Leaflet using CSS, specifically when using the Leaflet extra package in Shiny? Here's a simple code example: library(leaflet) library(leaflet.extras) library(shiny) ...

Here's a new take on the topic: "Implementing image change functionality for a specific div in Angular 8 using data from a loop"

I need to create a list with dynamic data using a loop. When I click on any item in the list, I want the image associated with that item to change to a second image (dummyimage.com/300.png/09f/fff) to indicate it's active. This change should persist e ...

Creating a design with CSS that allows floating boxes to completely occupy the wrapper element

This situation is really getting to me. I am currently in the process of creating a page that will feature a fixed header and footer, with dynamic boxes sandwiched in between. These boxes need to be properly arranged to fill the space within the wrapper c ...

Integrating photospheres into your Squarespace website design

Attempting to incorporate photospheres into my Squarespace website has been a challenge. The Google Maps option is functional, but it doesn't meet my specific requirements and appears like this: <iframe src="https://www.google.com/maps/embed?pb=! ...

Troubleshooting Logo Size Problems: Converting from Figma to HTML and CSS

I've been working on designing a landing page using Figma and overall it's looking great. However, I've run into some issues with my images, particularly with my logo. Figma provides specific width and height dimensions for my logo, but when ...

Having trouble accessing a fully loaded Wordpress remotely through Wamp

After installing WAMP Developer Pro on my Windows 7 computer, a testing website was set up locally. Now, I am trying to test it on the LAN, but when accessing the page, only text appears without any images, themes, or styling. Apache is running on port 80 ...

Is there a way to align the image block-grid from left to right?

Is there a way to change the alignment of images in the x-block-grid four-up class to be RTL on this page? () I have managed to make the h2 tag RTL using the following code: <h2 class="h-custom-headline h5 accent" dir="rtl"><span>Code</spa ...

Provide necessary CSS styles exclusively

Is there a method to streamline extensive CSS files by isolating only the necessary selectors for a specific page, and generating new css files containing just these selectors? Scenario: I am dealing with a significantly large CSS file that I need to opti ...

Table that can be scrolled through

Back in 2005, Stu Nichols shared a technique for creating a fixed header with scrolling rows in a table on this site. I'm curious if there are any newer methods or improvements to achieve the same effect, or is Stu's approach from 2005 still con ...

What is the best way to create a collapsible navigation bar using bootstrap specifically for mobile users?

Anyone know how to create a collapsible navigation bar using Bootstrap that works properly on mobile devices? I've tried implementing the code from the Bootstrap website, but it's not behaving as expected. Any suggestions or guidance would be gre ...

font-family choice in web browsers

My current goal is to configure the browser to utilize the Quicksand font, which I am sourcing directly from a file located in the same directory. When I structure the code as shown below, the browser successfully implements the Quicksand font: @charset " ...