I am trying to change the default width of the dialog but it's not working.I have tried solutions mentioned in this post. Here is my HTML code below:
<style>
#myDialog .modal-dialog{
width:80%;
}
</style>
<div id="myDialog" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
<div class="modal-title" id="Dialog_title">Text Document</div>
</div>
<div class="modal-body">
<div id="my_doc_content"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="rg.closeDialog('myDialog');">Close</button>
</div>
</div>
</div>
</div>
Override the .modal-dialog width
.modal-dialog{
width: 80%;
margin: auto;
}
Place this piece of code in after the bootstrap.min.css to override its default width.
Here is working fiddle
Here is a JSFiddle that may help you: Working JSFiddle
When CSS style is added on the class .modal instead of .modal-dialog, you can then simply change the width of the modal as you want by the following code:
.modal{
width: 80%; /* respsonsive width */
margin-left:-40%; /* width/2) */
}
$(function() {
$("#myDialog").modal("show");
});
.modal-dialog {
width: 80%;
margin: auto;
}
.modal{
width: 80%; /* respsonsive width */
margin-left:-40%; /* width/2) */
}
<div id="myDialog" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
<div class="modal-title" id="Dialog_title">Text Document</div>
</div>
<div class="modal-body">
<div id="my_doc_content"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="rg.closeDialog('myDialog');">Close</button>
</div>
</div>
</div>
</div>
Hope this helps you!
I always suggest to work with non-built files, working with sources you can take benefits from variables, mixins and, when needed, add/modify some default behaviour not explicitly exposed...
so, going to https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.3/scss/_modal.scss you can see where sizes are defined and add/edit them as you need...
// example
#include media-breakpoint-up(lg) {
.modal-extralg { max-width: $modal-lg * 2; }
}
Just use id:
#myDialog {
width:80%;
}
If you using bootstrap 4+, there are default optional sizes,
check this
You can make modal-md, modal-lg in different grid sizes
Example:
div class="modal-dialog modal-xl modal-dialog-centered" role="document"
Related
I am using a bootstrap modal and the close button is an image. When the modal size changes depending on the viewport, I want the close button to always stay in the top right corner of the modal
<div id="myModal" class="modal modal fade">
<a class="close-modal" href="javascript:void(0)" onclick=closeModalBox()>
<img src="images/close.png" width="39" >
</a>
<div class="modal-dialog">
<div class="modal-content" style="position: relative;">
<div class="modal-body" >
<!-- code -->
</div>
</div>
</div>
</div>
The css:
.close-modal {
margin: 0;
position: absolute;
opacity: 1;
z-index: 10;
cursor: pointer;
top: 1%;
left: 77%;
}
.modal-content{
position: relative;
}
Any ideas? Thanks
There seems to be an issue with the html structure, see example below, to keep the close button in the correct position. also refer to this link. Modal
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Do you mean to keep the button while scrolling down?
If that is the case use the "sticky" variable,
https://getbootstrap.com/docs/4.0/utilities/position/
You are using percentage values which will change visually when going between device sizes. Set these to fixed values so your close button will always be at a specific spot relative to the device size. Also, because you are using absolute positioning you can take advantage of the 'right' attribute instead.
https://www.w3schools.com/cssref/pr_pos_right.asp
.close-modal {
margin: 0;
position: absolute;
opacity: 1;
z-index: 10;
cursor: pointer;
top: 50px; // define your value here
right: 80px; // define your value here
}
<script type="text/javascript">
$(window).on('load',function(){
$('#loginerrormodal').modal('show');
});
</script>
<div class="modal fade" tabindex="-1" role="dialog" id="loginerrormodal">
<div class="modal-dialog" role="document">
<div class="modal-content bg-white">
<div class="modal-header">
<h5 class="modal-title">...</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Chiudi</button>
</div>
</div>
</div>
</div>
When I run the modal on mobile, the black background isn't responsive:
(the modal opes at page load so I don't have buttons to launch it)
How I can fix?
As it's possible to see in the live version you provided, there is an element exceeding the total width of the device, which is disturbing the modal.
Find the <div> with classes "card", "bg-white" and "mx-auto" and remove the inline style of width: 30rem for mobile devices breakpoint (480px).
If that's not possible, you can create a media query using !important to override the inline style, like this:
#media (max-width: 480px) { // the breakpoint that the problem is ocurring
.card.bg-white.mx-auto {
width: 100% !important; // it should work instead of 30rem
}
}
I fix with this:
.modal-backdrop {
height: 100%;
width: 100%;
}
I'm trying to lock a bootstrap modal at bottom right of the window.
What i have is :
HTML
<div class="modal custom fade" id="trackModal" tabindex="-1" role="dialog" aria-labelledby="trackModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="getlaid" id="trackModalLabel">Hello</h4>
</div>
<div class="modal-body">
<p>TEST</p>
</div>
<div class="modal-footer">
<div class="btnmodal" data-dismiss="modal">Close ✖</div>
</div>
</div>
</div>
</div>
CSS
.modal.custom .modal-dialog {
width:120%;
position:fixed;
bottom:0px;
right:0px;
margin:0px;
}
With this code block I'm not able to display modal at the bottom right of the window and it's keep displaying in the middle of the page. What is wrong here?
Maybe you meant to use 20% instead of 120%?
.modal.custom .modal-dialog {
width:20%;
position:fixed;
bottom:0;
right:0;
margin:0;
}
http://www.codeply.com/go/6GXNLGHyoW
The following code worked for me.
<div class="modal-dialog position-fixed end-0">
<div class="modal-content position-absolute bottom-0">
I use modal-lg class for a large modal but when I use this SO answer to vertically center my modal it makes the modal small:
this vertical centering causes it to be small
.modal {
text-align: center;
}
#media screen and (min-width: 768px) {
.modal:before {
display: inline-block;
vertical-align: middle;
content: " ";
height: 100%;
}
}
.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}
html:
<div class="modal fade" id="result-details-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 id="result-details-title" class="modal-title"></h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
How do I keep it large when it is vertically centered?
Using this little jQuery function you can do this, if that CSS is causing shrinking issue for your modal box.
Code Snippet
$(function() {
function reposition() {
var modal = $(this),
dialog = modal.find('.modal-dialog');
modal.css('display', 'block');
// Dividing by two centers the modal exactly, but dividing by three
// or four works better for larger screens.
dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
dialog.css("margin-left", Math.max(0, ($(window).width() - dialog.width()) / 2));
}
// Reposition when a modal is shown
$('.modal').on('show.bs.modal', reposition);
// Reposition when the window is resized
$(window).on('resize', function() {
$('.modal:visible').each(reposition);
});
});
.center {
margin-top: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="center">
<button data-toggle="modal" data-target="#result-details-modal" class="btn btn-primary center-block">Click Me</button>
</div>
<div class="modal fade" id="result-details-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 id="result-details-title" class="modal-title"></h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
I have a bootstrap modal window on my site that I can't seem to get styled consistently.
This is what my first modal looks like (and how I want it styled):
This is the 2nd modal window and styling:
here is the css that styles the title and the close:
.modal-title {
margin: 10px !important;
}
.close {
opacity: 1 !important;
position: relative !important;
padding-right: 15px !important;
top: 7px !important;
left: 3px !important;
}
Here is a copy of the relevant html for the modal windows:
<div id="movie" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="fa fa-close"></i></button>
<h4 class="modal-title">They Live (1988)</h4>
</div>
<div class="modal-body">
...
</div>
</div>
</div>
</div>
<div id="contactUs" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div classs="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="fa fa-close"></i></button>
<br>
<h4 class="modal-title">Send Me a Note</h4>
</div>
<div class="modal-body">
<form id="contact-send" method="post" action="">
...
</form>
</div>
</div>
</div>
</div>
The html to call the modals:
Movie
and
<button type="button" class="cta btn btn-lg btn-success" data-keyboard="true" data-toggle="modal" data-target="#contactUs">Contact Us</button>
edit 1: There are no parent divs. I did as suggested and removed the !important elements. I do have a form on the 2nd modal window and an iframe in the first, maybe this has to do with margins being set by those rules...looking into that now. Anyway this is what it looks like right now for the form:
and:
Edit2:
Messing around with my code a bit more, I see that if I remove the modal-header class and put the elements into modal-content that it seems to work. I'll post a final edit if I figure out anything else.
It is a simple syntax error that you may have overlooked.
The .modal-header inside #contactUS is not working because the class attribute is written as classs. Simply remove the extra letter.
You have a <br> tag before the h4 which I assume you added as an attempt to solve the problem. It is not needed so you can remove it.
The correct code would be like this:
.modal-title {
margin: 10px !important;
}
.close {
opacity: 1 !important;
position: relative !important;
padding-right: 15px !important;
top: 7px !important;
left: 3px !important;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
Movie
<button type="button" class="cta btn btn-lg btn-success" data-keyboard="true" data-toggle="modal" data-target="#contactUs">Contact Us</button>
<div id="movie" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="fa fa-close"></i></button>
<h4 class="modal-title">They Live (1988)</h4>
</div>
<div class="modal-body">
...
</div>
</div>
</div>
</div>
<div id="contactUs" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<!-- was classs -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="fa fa-close"></i></button>
<!-- <br> -->
<h4 class="modal-title">Send Me a Note</h4>
</div>
<div class="modal-body">
<form id="contact-send" method="post" action="">
...
</form>
</div>
</div>
</div>
</div>
jsFiddle: https://jsfiddle.net/azizn/j1sb9gz3/