Aligning a bootstrap modal to the side of the page

Peter Nordberg
Peter Nordberg used Ask the Experts™
on
Hi,

I have a regular css bootstrap Modal looking like this:

 <!-- modal default -->
                <div id="myModal2" aria-hidden="true" aria-labelledby="myModalLabel" class="modal fade" role="dialog" tabindex="-1">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">&times;</span></button>
                                <h4 id="myModalLabel" class="modal-title">Modal title</h4>
                            </div>
                            <div class="modal-body">
                                <p>Aliquam erat volutpat. Proin lacus erat, aliquam id efficitur sit amet, mattis vel urna. Pellentesque malesuada turpis vitae vestibulum facilisis. Aliquam vehicula felis vel justo consectetur, quis volutpat tellus consequat. Aliquam tellus lacus, eleifend at leo vitae, imperdiet cursus ex. Sed sodales augue euismod felis auctor auctor. Suspendisse sodales fermentum dolor sed mattis. Ut ipsum nunc, volutpat non velit a, tristique tempor mauris. Duis ac finibus lectus. Cras blandit eros ac diam luctus mattis. Nam dignissim mattis blandit. Nulla facilisi. Nullam non massa ac mauris efficitur congue aliquet ut orci.</p>
                                <p>Maecenas volutpat, massa rhoncus eleifend sagittis, sem nulla mollis ante, non porta dolor quam ullamcorper elit. Mauris accumsan nulla non risus accumsan auctor. Praesent luctus, mi id aliquet molestie, ex sem aliquet lorem, ut tempor ex urna ut orci. Aenean eget mi magna. Vestibulum quis congue nunc. Nulla faucibus felis eros, ut ultricies sapien mattis at. Aenean facilisis gravida quam vitae dignissim. Quisque ac orci vel tellus eleifend faucibus.</p>
                                <p>Suspendisse vitae tincidunt leo, eu tempus sem. Donec congue, lacus id mattis convallis, ex lectus molestie tortor, at porttitor ipsum quam sit amet tellus. Nulla facilisi. Ut ut risus mi. Donec nec sollicitudin lacus. Praesent at lorem mauris. Curabitur pulvinar nunc non auctor elementum.</p>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.modal default -->

Open in new window


Now I want to just align it to the right of the page and to the full with of the div holding it. How can I do it?

Thanks!

Peter
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
If you look at the example page https://getbootstrap.com/docs/4.0/components/modal/#using-the-grid (and here note that you can use the grid inside the modal to adjust your content) you will see by using your browser console that the class modal-dialog has the following.

.modal-dialog {
    position: relative; 
    width: auto;
    margin: .5rem;
    pointer-events: none;

}

Open in new window

If you change this to float to the right it should do what you want. Just make sure to place this class in your custom css and load it after bootstrap.
modal-dialog {
    /* position: relative; */
    width: auto;
    margin: .5rem;
    pointer-events: none;
    float: right;
}

Open in new window


You can also change the size of the modal as well https://getbootstrap.com/docs/4.0/components/modal/#optional-sizes
Peter NordbergIT Manager

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial