Center Content Vertically in Bootstrap Modal 4.3

I'm trying to center align vertically in my modal body, but nothing seems to be working. I am using Bootstrap version 4.3. Can anyone help me figure out what's going wrong?

<section>
    <div id="search-shopkeeper-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="shopkeeperModal" aria-hidden="true">
        <div class="modal-dialog modal-xl" role="document">
            <div class="modal-content">
                <div class="modal-header border-0 p-0 m-0">
                    <div class="container-fluid p-2">
                        <form action="">
                            <div class="form-row">
                                <div class="col-12">
                                    <div class="input-group input-group-lg">
                                        <div class="input-group-prepend">
                                            <span id="search-shopkeeper-addon" class="input-group-text bg-transparent border-0"><i class="fas fa-search"></i></span>
                                        </div>
                                        <input type="text" class="form-control rounded-0 border-0 shadow-none" placeholder="Type the Shopkeeper's name..." aria-label="Username" aria-describedby="search-shopkeeper-addon">
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-body" style="border: 1px red solid">
                    <!-- @todo -->
                    <div class="container d-flex align-items-center" style="border: 1px red solid">
                        <div><h1 class="text-center">NO RESULTS FOUND!</h1></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default text-white shadow-none" data-dismiss="modal" style="background-color: #333333 !important">Close</button>
                </div>
            </div>
        </div>
    </div>
</section>

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

Answer №1

If you're looking to implement new styling rules, consider the following:

.modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
}

You can observe this in action here:

.modal-content {
  height: 500px; /* Required for the example to showcase the modification */
}

.modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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>

<section>
  <div id="search-shopkeeper-modal" class="" tabindex="-1" role="dialog" aria-labelledby="shopkeeperModal" aria-hidden="true">
    <div class="modal-dialog modal-xl" role="document">
      <div class="modal-content">
        <div class="modal-header border-0 p-0 m-0">
          <div class="container-fluid p-2">
            <form action="">
              <div class="form-row">
                <div class="col-12">
                  <div class="input-group input-group-lg">
                    <div class="input-group-prepend">
                      <span id="search-shopkeeper-addon" class="input-group-text bg-transparent border-0"><i class="fas fa-search"></i></span>
                    </div>
                    <input type="text" class="form-control rounded-0 border-0 shadow-none" placeholder="Enter Shopkeeper Name..." aria-label="Username" aria-describedby="search-shopkeeper-addon">
                  </div>
                </div>
              </div>
            </form>
          </div>
        </div>
        <div class="modal-body" style="border: 1px red solid">
          <!-- @todo -->
          <div class="container d-flex align-items-center" style="border: 1px red solid">
            <div>
              <h1 class="text-center">NO RESULTS!</h1>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default text-white shadow-none" data-dismiss="modal" style="background-color: #333333 !important">Close</button>
        </div>
      </div>
    </div>
  </div>
</section>

Answer №2

To make the modal-body align items center, simply add the classes "d-flex align-items-center."

Alternatively, you can achieve the same effect using CSS as mentioned in the comment above.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#search-shopkeeper-modal">
  Launch demo modal
</button>
<section>
    <div id="search-shopkeeper-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="shopkeeperModal" aria-hidden="true">
        <div class="modal-dialog modal-xl" role="document">
            <div class="modal-content">
                <div class="modal-header border-0 p-0 m-0">
                    <div class="container-fluid p-2">
                        <form action="">
                            <div class="form-row">
                                <div class="col-12">
                                    <div class="input-group input-group-lg">
                                        <div class="input-group-prepend">
                                            <span id="search-shopkeeper-addon" class="input-group-text bg-transparent border-0"><i class="fas fa-search"></i></span>
                                        </div>
                                        <input type="text" class="form-control rounded-0 border-0 shadow-none" placeholder="Digite o nome do Lojista..." aria-label="Username" aria-describedby="search-shopkeeper-addon">
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-body d-flex align-items-center" style="border: 1px red solid; height: 500px;">
                    <!-- @todo -->
                    <div class="container d-flex align-items-center" style="border: 1px red solid">
                        <div><h1 class="text-center">SEM RESULTADOS!</h1></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default text-white shadow-none" data-dismiss="modal" style="background-color: #333333 !important">Fechar</button>
                </div>
            </div>
        </div>
    </div>
</section>

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

"Need help with resolving issues in my React Bootstrap Navbar? Learn the latest updates on fixing Navbar Brand Collapse here

Having issues with my React.js website navbar created using bootstrap. The menu button doesn't show up when the navbar collapses at a certain point. Can someone spot what's missing in the code below? Tried toggling by following a tutorial, but i ...

Is it possible to customize the appearance of the Firefox tab group window?

On the main browser window, you can access and modify chrome://browser/content/browser.xul using the DOM Inspector and adjusting it in the profiles' userChrome.css file. I am interested in doing something similar for the tab group window (CTRL+SHIFT+ ...

Having trouble aligning modal to the left in Bootstrap 4 and MVC 5

I am currently working on a project where I am using a modal window to display an iframe. The webpage within the iframe is quite wide, so I have adjusted the width accordingly. However, the modal itself is situated in the center of the screen, causing the ...

Align the button to the right side inside a div container

As someone who isn't very skilled in CSS, I have a question for beginners. Below is an excerpt from an HTML document: <div _ngcontent-vyb-c4="" class="form-row"> <div _ngcontent-vyb-c4="" class="col-md-12"> <d ...

When utilizing the JavaScript createElement() method to create elements on keydown, it will not be compatible with jQuery's draggable() method

I'm currently developing a drag and drop feature for a project, allowing users to add items to a work area and then position them by dragging. I'm facing an issue where I want to create multiple instances of the same element using a key code, but ...

ZeroClipboard intricate CSS issue

I have a list of images with an option box that appears on mouseover. The box contains an embedded code input field for copying purposes. I recently implemented zeroclipboard to enable the copy function on click. However, when I hover over an image and try ...

Center 3 elements horizontally using Flexbox, ensuring the center element is aligned properly

Is it possible to center 3 elements using flexbox on a page? The middle element should be centered on the page, while the left and right elements can vary in width. Please refer to the image below: https://i.sstatic.net/IVdz8.png I am not certain if this ...

Managing Margins and Padding in Multiple Lines of Divs in CSS

Trying to understand the spacing issues that arise when tiling a series of divs within a parent div. Here is a link to the fiddle for reference: http://jsfiddle.net/SNSvU/4/. Below is the code snippet: <div id="prioritiesWrapper"> <div class="p ...

I'm having trouble showing the concealed list with JavaScript

I am new to javascript and facing a challenge. Whenever I update the list items in an HTML example from engineer, pilot, technician, if I select engineer, there should be an onchange event calling a function in JavaScript that shows a hidden select list co ...

Can you set the line thickness for "text-decoration: line-through;" using CSS?

When it comes to the line-through property in CSS, the default weight of 1px is ideal for body copy set at 1em. However, for larger items like a price set at 3em on an offer site, 1px can feel too light. Is there a way to increase the line weight for line ...

Show Zeroes in Front of Input Numbers

I am working with two input fields that represent hours and minutes separately. <input type="number" min="0" max="24" step="1" value="00" class="hours"> <input type="number" min="0" max="0.60" step="0.01" value="00" class="minutes"> This se ...

Modify select option in Bootstrap Vue based on user input

I am facing a challenge in populating a Bootstrap-Vue form select with objects obtained via JSON. The JSON data comprises teacher information from various fields: [ { "id": 1, "name": "John", "surname": ...

What is the process for taking the CSS content from a local CSS file and injecting it into a <style> tag?

Creating custom style content using the <style> tag with style.innerHTML can be done like this: let style = document.createElement("style"); style.setAttribute("id", "raptors"); style.innerHTML = " ...

What is the best way to use html, css, jquery, and bootstrap to show or hide images without any extra space or alignment issues

I am looking to showcase 6 images on a page using the Bootstrap grid layout. The images should be displayed in two rows, with 3 images in each row. Additionally, I want to implement a filter functionality using Isotope, so users can click on a specific cat ...

Guide on incorporating HTML data into an existing webpage

Requesting assistance in creating an HTML page that features a dynamic drop-down menu. The drop-down should trigger a list to appear upon selection, which can be sourced from either a text file or plain HTML document. The envisioned functionality involves ...

Aligning a hyperlink with an image on an HTML page

I'm attempting to centrally position an image within a link: <a href="URL"> <img class="my_class" src="SRC" /> </a> The CSS code I have been using is as follows: .my_class { position:relative; display: block; margin-left: ...

What could be causing my JavaScript code to not function properly in an HTML document?

Hello, I am a beginner in the world of coding and currently delving into web development. Recently, I was following a tutorial on creating a hamburger menu but I seem to be encountering some issues with the JavaScript code. I have double-checked my Visual ...

What is the specific use of the second app.css file in Laravel?

I'm currently delving into Laravel 8, and I'm perplexed by the role of Resources\css\app.css. While every other component in the Resources directory serves a clear function, the app.css file appears to be empty. Even when I attempt to a ...

Creating Consistent Height and Alignment for Bootstrap 4 Cards

Aligning Bootstrap 4 cards using d-flex and align-self-stretch for the cards works great. But I'm struggling to make the part with the red border float to the bottom. Any suggestions using only Bootstrap 4 utilities? https://i.sstatic.net/2VUME.png ...

Is a Responsive Split Layout the Solution for Your Web Design Needs?

I'm looking to create a webpage layout where the left half of the viewport is for Login and the right half is for Signup. This layout should be split side by side on tablets, desktops, and large screens, but stacked vertically (Login on top, Signup on ...