!Do not close it as duplicate, the answers in the "duplicate" only center it relative to the X button!
I'm trying to completely center the modal-title of a bootstrap4 modal.
However, it only centers it relative to the X and not to the whole width of the modal. The answers here: Bootstrap 4 Modal Center Content all have the same issue.
https://jsfiddle.net/couthzLt/
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center d-block">
<h5 class="modal-title d-inline-block" id="exampleModalLabel">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>
The header is not completely centered as you can see on this image that:
modal header centered relative to X
My question is if it's possible to center it to the right edge of the modal - not the X.
By default close is positioned using float:right which keeps it as part of the document flow. Because of this modal-title is always going to center itself respective of the width available minus what close is using.
To fix the problem we need to pull close out of the flow. Easiest way to do that is:
.close {
position: absolute;
right: 1rem;
}
position: absolute pulls the class out of the normal flow which in turn lets modal-title take up the full width. The right margin is designed to replicate the margins defined for the Modal component to ensure that your layout remains more or less unchanged.
Put text-center d-block in modal-header
Put up button dismiss
Last modal title.
<div class="modal-header text-center d-block">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Title center</h2>
...
</div>
How about something like this:
#exampleModalLabel {
position: absolute;
left: 0;
right: 0;
margin: auto;
}
On my side, I did the following:-
NOTE: The size of my modal was default, it was not large or small.
Then in Modal::begin I added titleOptions as below
Modal::begin([
'title' => 'yor title ...',
'titleOptions' => ['style' => ['margin-left' => '95px']],
...other options..
]);
Related
I have a modal with two columns in it. One of the column contains a table. However, the table does not fit into the column and need to scroll horizontally, but I need to make the table fit into the column. Also, I have problem with the scrolling issues. Table should be can scroll if the items is more than the size of the modal.
Here, the link of example:- https://jsfiddle.net/35wzenqf/2/
Please change the view to tabs(row) easier for you to see the columns in modal :)
<div class="btn-group d-flex">
<button class="btn btn-lg btn-icon btn-primary w-100" data-toggle="modal" data-target="#modal-default">
<span class="btn-inner--icon"><i class="far fa-money-bill-alt"></i></span>
<span class="btn-inner--text">Pay</span>
</button>
</div>
Thank you for anyone helping!
Thanks Ferikeem and Hamid for helping!
These are the answers for my questions:-
Change modal-lg to modal-xl, in my code it doesn't works I don't know why so I added style="max-width: 1140px" for my modal-dialog class. It's the same size as modal-xl in bootstrap.
For the scrolling, I need to set the height.
.horizontal-scroll
{
overflow-y: auto;
height: 70vh;
}
Increase the size of the medal
enter link description here
<!-- Extra large modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl">Extra large modal</button>
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
...
</div>
</div>
</div>
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
}
I am working with angular and want to create a modal.
However I am having a lot of problems removing or editing modal-backdrop as it never takes my values in css.
It is possible to remove through data-backdrop = false, I know, but I intend to close the modal when I click outside of this, it gives not use the data-backdrop.
Can someone experienced help me? I've been at this for days and so far still nothing.
I leave my code and stackblitz to test. Thanks !
Code
Stackblitz
HTML
<div class="container">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
Modal body..
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
As shown in this stackblitz https://stackblitz.com/edit/angular-1dh6k3
you can add
.fade.show {
background: red; // example
opacity: 1; // example
}
and you are able to edit the modal backdrop
An alternative answer without using !important (should be avoided when possible)
::ng-deep .modal-backdrop.show {
background: transparent;
}
You can try this:
.modal-backdrop {
opacity: 0 !important;
}
I'm trying to load the bootstrap modal containing information retrieved from the database.
I'm fetching the results in the modal using AJAX .
The bootstrap modal is loaded correctly but not on the center of the page,it is loaded on the right corner of the page.
I want it to be on the center of the page
I've tried to add css properties on modal class and also search for the problem on different platform but didn't find anything.
After clicking this anchor tag I've bind the modal
<a href="" onclick=" show(<?php echo $ids[$i] ?>)" class = 'fa fa-eye' data-toggle="modal" data-target="#exampleModalLong"'></a>
This is the code for ajax
function show(id)
{
var xhr = new XMLHttpRequest();
xhr.open("GET" ,"findinfo.php?id="+id,true);
xhr.send(null);
xhr.onreadystatechange = function(){
if( (xhr.readyState == '4') && ( xhr.status == '200') )
{
document.getElementById("mbody").innerHTML = xhr.responseText;
}
}
}
here is the modal I've used
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby=" exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="dialog">
<div class="modal-content">
<!-- modal header -->
<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>
<!-- modal body -->
<div class="modal-body" id = 'mbody'>
</div>
<!-- modal footer -->
<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 want The bootstrap modal on the center of the page,it is loaded on the right corner of the page.
Image shows this
Try this,
.modal.fade.show .modal-dialog{
top: 50%;
transform: translateY(-50%);
}
You said in your comment, you have a wrapping container markup:
<div class = 'container'> <div class = 'row'> <div class = col-md-12> Here is my modal... </div> </div> </div>
And thats the problem. The class "col-md-12" uses css "position: relative;" and flexbox stuff. then the "fixed"-position of the modal maybe have some caveats. As I said in my comment you should read the "How it Works"-part.
Solution might be: Place your modal directly within body without any wrapping containers. This should be the preferred way anyhow.
Hope it helps & best regards
I all,
I am using modals on my website and the scroll area containing them do not fit the page.
See on the screenshot.
I am not applying any additional style to the modals and I can't figure out where does the problem come from.
I am sorry it is hard to post code because I am not sure which part might cause this and the code base is relatively large..
EDIT: Sample modal
<div class="modal fade" id="addSpotModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" onclick='addSpot.cancel()'
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add a spot</h4>
</div>
<div class="modal-body">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick='addSpot.cancel()'>Close</button>
<button type="button" class="btn btn-primary" onclick='addSpot.sendAddSpotRequest()'>Save changes</button>
</div>
</div>
</div>
Any idea?
Thanks. Olivier
Firstly, the scroll is based on the modal itself, so as you can see, the rounded corners are not visible. The content inside the modal is pushing the size to be larger than the viewing area. You could try the size utilities like modal-lg on the dialog (<div class="modal-dialog modal-lg">) if you haven't done so. You can also change the dimensions through LESS/variables. The #modal-lg, #modal-md, and #modal-sm. To decrease the top margin, you would need to adjust the CSS for modal-dialog as 30px is the default.