What is the best way to center align a Bootstrap 4 modal window?

I'm facing a small issue here, I would like to have the modal display in the center. Instead of it appearing like this https://i.sstatic.net/R518w.jpg, I want it to look like this https://i.sstatic.net/wwUo7.jpg. Here is the code:

<!-- The Modal -->
<div class="modal fade" id="modal-first">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <button type="button" class="close" data-dismiss="modal">&times;</button>

    <!-- Modal body -->
    <div class="modal-body d-flex align-items-center">
      <div class="row">
        <div class="col">
            <img src="1x/lawang_sewu2.jpg" style="width: 350px; height: 500px; object-fit: cover;">
        </div>
        <div class="col">
          <p style="font-size: 36px; width: 250px;">Lawang Sewu</p>
          <p style="width: auto; height: auto; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eget ipsum ex. Integer pulvinar elementum fringilla. Fusce sollicitudin sed enim non elementum. Etiam sit amet turpis massa. Sed id posuere magna, sed molestie dolor. Vivamus at mauris malesuada, porttitor arcu in, auctor arcu. Sed efficitur, purus a molestie cursus, eros sapien volutpat purus, id accumsan nibh massa vitae augue. Sed fermentum, ex ut sodales auctor, neque ante malesuada eros, consectetur volutpat urna orci eget felis. Donec euismod scelerisque nisi ac dignissim. Phasellus eros libero, interdum ac arcu nec, venenatis maximus tortor. Nunc blandit tincidunt nulla. Mauris efficitur tincidunt lacus at ultricies. Maecenas dignissim quam malesuada eleifend blandit. In hac habitasse platea dictumst.</p>
      </div>
      </div>
    </div>

    <!-- Modal footer -->
    <div class="modal-footer">
      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
    </div>
  </div>
</div>
.modal-content{
 padding: 5%;
}

Answer №1

If you want to customize your modal size, simply add the following CSS code to your stylesheets:


.modal-dialog {
    min-width: 300px; // Minimum width in pixels
    max-width: 800px; // Maximum width in pixels
}

Make sure to place this custom CSS script after the bootstrap.css file for it to take effect.

Answer №2

The maximum width of your modal has been constrained by the modal-dialog class. To adjust this, consider removing the class or modifying the max-width property.

Answer №3

<div class="modal fade" id="modal-first">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <button type="button" class="close" data-dismiss="modal">&times;</button>

            <!-- Modal body -->
            <div class="modal-body d-flex align-items-center">
                <div class="row">
                    <div class="col-6">
                        <img src="1x/lawang_sewu2.jpg" style="width: 350px; height: 500px; object-fit: cover;">
                    </div>
                    <div class="col-6">
                        <p style="font-size: 36px; width: 250px;">Lawang Sewu</p>
                        <p style="width: auto; height: auto; text-align: justify;">Lorem ipsum dolor sit amet,
                            consectetur adipiscing elit. Morbi eget ipsum ex. Integer pulvinar elementum fringilla.
                            Fusce sollicitudin sed enim non elementum. Etiam sit amet turpis massa. Sed id posuere
                            magna, sed molestie dolor. Vivamus at mauris malesuada, porttitor arcu in, auctor arcu.
                            Sed efficitur, purus a molestie cursus, eros sapien volutpat purus, id accumsan nibh
                            massa vitae augue. Sed fermentum, ex ut sodales auctor, neque ante malesuada eros,
                            consectetur volutpat urna orci eget felis. Donec euismod scelerisque nisi ac dignissim.
                            Phasellus eros libero, interdum ac arcu nec, venenatis maximus tortor. Nunc blandit
                            tincidunt nulla. Mauris efficitur tincidunt lacus at ultricies. Maecenas dignissim quam
                            malesuada eleifend blandit. In hac habitasse platea dictumst.</p>
                    </div>
                </div>
            </div>

            <!-- Modal footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>

Include col-6 in your modal structure.

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

Expanding the CSS Search Box

Visit the link I've been working on coding a CSS text box. When you hover over the button in the provided link, you'll notice that the 'Type to search' functionality is working smoothly as it moves to the right. My current focus is on ...

When the screen size is decreased, one card begins to appear behind another card

In my attempt to create a set of responsive cards using Bootstrap, I have written the following code for the cards: <div class="col-xl-4 col-md-6 col-sm-6 p-2"> <div class="card shadow" style=" ...

Scrolling without limits - cylindrical webpage (CSS/JS)

Is it possible to create a page that infinitely scrolls from top to top without going straight back to the top, but instead showing the bottom content below after reaching it? Imagine being able to scroll up and see the bottom above the top like a 3D cylin ...

The sticky-top class in Bootstrap 4 does not seem to be functioning properly on the

It seems that other classes in my codebase are interfering with the sticky-top class from Bootstrap. I initially thought that all I had to do was add the class to the navbar, but with two navbars and restrictions on using fixed-top, things have become tric ...

Troubleshooting Safari compatibility with CSS transitions: a first attempt

Greetings everyone, I am a complete beginner here so please bear with me. After looking at some examples, I have managed to create a start/stop slowdown feature. Here is the JSFiddle link for reference .small-wheel, .big-wheel{ transition: all 2s ease ...

Close the menu located in the menu bar under the Home section

I am struggling with creating the bootstrap collapse menu. <div className='collapse' id='mobile-menu'> <button clasNames='navbar-toggler' type='button' data-togg ...

Tips for animating slider elements that are not set to absolute positioning

I'm currently working on implementing an animated slider for my website. I have been using floats and margins to position the elements of the slider, but now I want to find a way to incorporate animations without having to use CSS3 transitions with ab ...

Tips for utilizing percentages along with MotionValues in Framer Motion?

With Framer Motion's useTransform, I'm looking to adjust the width of an element using a MotionValue that is a percentage (e.g. 75%) rather than in pixels. The default setting assumes pixels: <motion.div className="dynamic-element" style={{ ...

Unable to delete the margin of Material-ui TextField

Having trouble removing the padding around material-ui's TextField component when using styled-components and inline styling. Any solutions to this issue? Interestingly, the inline width property is functioning correctly, unlike the styled-component w ...

Enhanced page flow with CSS and jQuery

I'm looking to improve the overall layout of my webpage, but I can't seem to pinpoint exactly what it is that I need! Imagine you have the following HTML structure: <section> <article> <h1>Article Header</h1> & ...

There appears to be a gap on the right side of the <span> element, resembling an additional space at the end

While testing a button on my website, I noticed that all the spans have an extra space at the end. Adding a background box made this gap very noticeable. Upon further inspection of my other pages, I realized that the issue exists there too. I have not made ...

What is the best way to create non-standard text wrapping in HTML and CSS that is both semantic and sleek, avoiding square or circular shapes?

Is there a way to achieve text wrapping like this using semantic and clean HTML and CSS that is compatible with all browsers? The only solution I can think of is adding different classes to the <p> element. However, the drawback of this approach is ...

What could be causing my submenu to not display the specified hover effect?

Help needed troubleshooting dropdown menu issue in HTML and CSS. Using :hover to switch from display:none; to display:flex;. Want submenu to appear when hovering over "Unsere Produkte". Grateful for any assistance. Thank you. /* Desktop Navigation Bar ...

Dimensions properties for a webpage displayed within a DIV element

I was attempting this in an iframe previously, but now I have managed to make it work in a DIV. However, I am facing issues in achieving the desired properties. When I try to modify the properties of the 'siteloader', it seems to ignore the embe ...

Utilizing regular expressions in Powershell to modify a CSS file

Snippet from my current theme.css file: .actionBlock[selected] { color: var(--gray11); background-color: var(--gray11); } I am trying to modify color: var(--gray11); to color: #FFF; /* UPDATED : var(--gray11) */ After attempting in Po ...

Changing the border color of an HTML input is easy with these simple steps:

As part of an educational project, I am developing a login-registration system using HTML, CSS, and PHP. The system will include various HTML text boxes and elements. My goal is to change the border color of a textbox to green when I input something into ...

What methods can be used to modify the appearance of the cursor depending on its position?

Is there a way to change the cursor to a left arrow when on the left half of the screen and switch it to a right arrow when on the right half, using JavaScript? I am trying to achieve something similar to what is shown on this website. I attempted to acco ...

Positioning an element in the center of another using JQuery

Greetings! I am currently working with some elements that look like this: <div id="one">content</div> <div id="two">content</div> These elements are followed by another set of elements (without any parent, placed directly after th ...

I am attempting to adjust the CSS code so that it does not shrink when clicked on. How can I prevent this from happening?

Here is the element I am attempting to modify. I attempted &:active { flex:7;} but upon releasing the left click button, it reverted back to its original size. I was aiming for something similar to this <h1>Gallery</h1> < ...

Tips for creating a div that slides from the right side to the left side

I received a code from someone and I need help with making the sliding div slide from right to left. Essentially, I want the div to hide on the right side and slowly move to the left within a width of 300px. Here is the HTML code: <a id="loginPanel"&g ...