Bootstrap Modal in a Div - html

I have a bootstrap modal within display: table-cell; container, but when the modal is provoked, it's not in full screen, but instead fits inside the div. How do I make it so that it fits full screen? I've been struggling with this problem for a long time, so someone please help me!
.action-delete-btn {
text-align: center !important;
position:absolute !important;
float:right;
top:10px;
}
.action-delete-btn {
display:none;
}
.action-delete-btn {
right:130px;
}
<script src="https://kit.fontawesome.com/bc33a16514.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<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.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container-fluid d-flex flex-wrap" id="word-list-container">
<button class="btn btn-danger rounded-circle action-delete-btn" id="delete-btn" type="button" data-toggle="modal" data-target="#confirmDeletionModal">
<i class="fas fa-trash-alt"></i>
</button>
<div class="modal" id="confirmDeletionModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenteredLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenteredLabel">Are you sure you want to delete this?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<button type="button" class="btn btn-danger">
Yes, delete
</button>
</div>
</div>
</div>
</div>
</div>
enter image description here

Add the below code into the CSS file
.modal-dialog {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.modal-content {
height: auto;
min-height: 100%;
border-radius: 0;
}

Related

How to make modal appear above all divs

I have this flex slider to show a customers previous purchases/orders, it uses a "slider" div and inside that is a foreach statement to pull the users previous purchases from a database to produce each "slide" within the slider.
In each slide there is a button to open the modal, which works fine if there is only one item there, but if there is 2-3 items then the display:flex is activated - causing the modal to pop up inside the slider div rather than on top of everything, I believe it has something to do with the position:relative for the "slider" CSS and the position for the modal CSS
and I cant move the modal outside of those divs because the modal needs to be inside the foreach statement so that it pops up with the correct item details (since they are being pulled from a database).
Also, I cant seem to replicate the issue on my PC when I narrow my browser as much as I can (guessing the window doesn't go narrow enough for the issue to occur).
Had this issue a long time, any help is appreciated, thanks
.slider {
width: 100%;
padding: 6px 0px;
display: flex;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
scroll-snap-type: x mandatory;
-ms-overflow-style: none;
/* IE and Edge */
scrollbar-width: none;
/* Firefox */
}
.slider::-webkit-scrollbar {
display: none;
}
.slide {
border: 1px solid black;
width: 140px;
flex-shrink: 0;
height: 100%;
}
.slider>div {
scroll-snap-align: start;
}
.slider img {
margin: 6px 6px;
}
.modal {
position: fixed !important;
bottom: 0 !important;
left: 0 !important;
z-index: 1200 !important;
display: none;
width: 100%;
height: 100%;
overflow-x: hidden !important;
overflow-y: auto !important;
outline: 0;
background-color: rgba(10, 10, 10, 0.45);
}
.modal-backdrop {
display: none !important;
}
.modal-content {
color: black !important;
z-index: 1200 !important;
position: relative;
display: block;
flex-direction: column;
width: 100%;
pointer-events: auto;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, .2);
border-radius: .3rem;
outline: 0;
}
i.fa-ellipsis-v {
border-radius: 60px;
box-shadow: 0 0 2px #888;
padding: 0.5em 0.6em;
font-size: 14px;
}
i.fa-ellipsis-v:hover {
cursor: pointer;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" id="bootstrap-css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<div class="slider">
<div class="slide" id="slide-1">
<img src="/images/products/<?php echo $ditt['prodimage'];?>">
<i data-toggle="modal" data-target="#exampleModal-1"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="slide" id="slide-2">
<img src="/images/products/<?php echo $ditt['prodimage'];?>">
<i data-toggle="modal" data-target="#exampleModal-2"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="slide" id="slide-3">
<img src="/images/products/<?php echo $ditt['prodimage'];?>">
<i data-toggle="modal" data-target="#exampleModal-3"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</div>
If you’re wanting the modal above all other elements in the window you can use position:fixed and z-index:99999
.modal{
position:fixed;top:calc(50% - 200px);left:calc(50% - 250px);width:500px;height:400px:z-index:99999;
}
First of all set these attributes
.Modal{
position:absolute
}
.slider{
position:relative
top:0; //as default to overwrite browser defaults for non-static elements
left:0;//as default to overwrite browser defaults for non-static elements
}
Now Your .Modal will be visible in constraints of .slider.
Anyway if Your .Modal be visible out of the .slider
edit .slider{overflow} value
or
YOu can set .modal{position:fixed } or YOu can put YOur .modal out of .slider :
<div class="Modal></div><div class="slider>...</div>
Prevent from using z-index - it's unintuitive.
Z-index is worth just for dynamic purpose, like programaticly switching visible images layed out in the same constraints.
By the way
here You can figure out Your snippet to be reproducable.
Just a modal using the bootstrap classes:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" id="bootstrap-css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Bootstrap carousel with modal
.outer-container {
display: flex;
flex-direction: column;
}
.main-container {
border: solid yellow 2px;
padding: 1rem;
}
#carouselExampleControls {
border: solid green 1px;
display: flex;
background-color: #88dd8811;
}
.modal-container {
display: block;
height: 8rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" id="bootstrap-css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<div class="outer-container">
<div class="other-container">Other container</div>
<div class="main-container">
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators bg-success">
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
<div class="modal-container d-flex flex-row p-3 justify-content-center align-items-center">
<div class="me-2">Happy people modal here:</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary w-25 me-1" data-bs-toggle="modal" data-bs-target="#firstModal">
Launch FIrst modal
</button>
<!-- Modal -->
<div class="modal fade modal-centered" id="firstModal" tabindex="-1" aria-labelledby="firstModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="firstModalLabel">Big Dog title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<span class="ms-5 p-3 text-white bg-warning">I am a big dog!</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- end of first modal -->
<div class="modal-container">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModalTwo">
Launch demo modal two
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalTwo" tabindex="-1" aria-labelledby="exampleModalTwoLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalTwoLabel">Modal two title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<span> I am a fish!</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="modal-container m-3">I will hold a modal</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="modal-container m-3">I will hold a modal</div>
</div>
</div>
<button class="carousel-control-prev text-primary" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon bg-primary" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next text-success" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon bg-primary" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
</div>
Original example:
.slider {
width: 100%;
padding: 6px 0px;
display: flex;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
scroll-snap-type: x mandatory;
-ms-overflow-style: none;
/* IE and Edge */
scrollbar-width: none;
/* Firefox */
}
.slider::-webkit-scrollbar {
display: none;
}
.slide {
border: 1px solid black;
width: 140px;
flex-shrink: 0;
height: 100%;
}
.slider>div {
scroll-snap-align: start;
}
.slider img {
margin: 6px 6px;
}
.modal {
position: fixed !important;
bottom: 0 !important;
left: 0 !important;
z-index: 1200 !important;
display: none;
width: 100%;
height: 100%;
overflow-x: hidden !important;
overflow-y: auto !important;
outline: 0;
background-color: rgba(10, 10, 10, 0.45);
}
.modal-backdrop {
display: none !important;
}
.modal-content {
color: black !important;
z-index: 1200 !important;
position: relative;
display: block;
flex-direction: column;
width: 100%;
pointer-events: auto;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, .2);
border-radius: .3rem;
outline: 0;
}
i.fa-ellipsis-v {
border-radius: 60px;
box-shadow: 0 0 2px #888;
padding: 0.5em 0.6em;
font-size: 14px;
}
i.fa-ellipsis-v:hover {
cursor: pointer;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.10.3/font/bootstrap-icons.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" id="bootstrap-css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
Slider does not run and style seems to have no effect on it
<div class="slider">
<div class="slide" id="slide-1">
<img src="/images/products/<?php echo $ditt['prodimage'];?>" alt="prodimage1">
<i class="bi-bag-fill" style="font-size: 3rem; color: orange;" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#exampleModal-1"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>" alt="prodimage1">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="slide" id="slide-2">
<img src="/images/products/<?php echo $ditt['prodimage'];?>" alt="prodimage2">
<i class="bi-bag-fill" style="font-size: 3rem; color: orange;" data-bs-toggle="modal" data-bs-target="#exampleModal-2"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>" alt="prodimage2">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="slide" id="slide-3" data-bs-target="#exampleModal-3">
<img src="/images/products/<?php echo $ditt['prodimage'];?>" alt="prodimage3">
<i class="bi-bag-fill" style="font-size: 3rem; color: orange;"data-bs-toggle="modal" data-bs-target="#exampleModal-3"></i>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal-3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="margin-top:64px;">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Order options</h5>
</div>
<div class="modal-body">
<img src="/images/products/<?php echo $ditt['prodimage']; ?>" alt="prodimage3">
<br>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</div>

Make a bootstrap Modal, relative to a column

I have 3 columns in my design and I want a modal to be placed inside the second column. And the modal shouldn't move outside the 2nd column when the screen size is changed (only on desktop sizes (1922x1080 - 1280x600) ).
.col{
height:100vh;
}
.column-two{
position:relative;
}
.modal-content {
width: 200px !important; height: 228px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx"
crossorigin="anonymous" />
<div class="row align-items-start">
<div class="col border">
ONE
</div>
<div class="col border column-two">
TWO
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<div class="col border" >
THREE
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.js"
integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
crossorigin="anonymous"></script>
I'm planning to make the modal position relative and place it inside the column.
Please add below custom css and check agian. i hope your issue will fix by this custom css.
.column-two .modal {
position: absolute;
}
/* for center position */
.column-two .modal.show {
display: flex !important;
}
This would be my solution:
.col{
height:100vh;
}
.column-two{
position:relative;
}
#exampleModal{
position: relative;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx"
crossorigin="anonymous" />
<div class="row align-items-start">
<div class="col border">
ONE
</div>
<div class="col border column-two">
TWO
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<div class="col border" >
THREE
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.js"
integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
crossorigin="anonymous"></script>

Position modal centered with floating outside box

I have a bootstrap 4 modal that I wish to display a little different. I want to display a floating box off to the left of the modal.
My question is how can I position both the modal and the floated box in the center of the page, even though the floating box is sitting outside the modal with a position absolute?
This is what it looks like currently, the floated box has a position absolute with a negative left position:
This is how I want it to look like, with the box and modal centered:
I don't know how much I have to modify the modal to do this, as I am hoping to make it responsive as well.
Would anyone have any ideas on how I could achieve this? It would be much appreciated.
Thanks, guys.
.affix-box {
position: absolute;
top: -40px;
left: -100px;
width: 200px;
height: 100px;
background-color: green;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-lg-12">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="affix-box"></div>
<div class="modal-header">
<h5 class="modal-title ml-auto" 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>
</div>
</div>
</div>
Add width: 91%; and left: 9%; to modal-content
.affix-box {
position: absolute;
top: -40px;
left: -100px;
width: 200px;
height: 100px;
background-color: green;
}
.modal-content{
width: 91%;
left: 9%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-lg-12">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="affix-box"></div>
<div class="modal-header">
<h5 class="modal-title ml-auto" 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>
</div>
</div>
</div>
Here is the simple replacement.
instead of top and left i have used transform: translate(-50%, -50%); which sets the center of the floating box on the top left corner of modal.
.affix-box {
position: absolute;
width: 200px;
height: 100px;
background-color: green;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-lg-12">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="affix-box"></div>
<div class="modal-header">
<h5 class="modal-title ml-auto" 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>
</div>
</div>
</div>
In addition to what #Joykal has said, you can also try changing the model size to reduce its width, you can use .modal-sm or .modal-lg class instead of .modal-xl depending on your need
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
May be this will help you
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
#myModal .close{
display: none;
}
</style>
<script>
$(document).ready(function(){
$(".btn").click(function(){
$("#myModal").modal('show');
$("#myModal2").modal('show');
});
$(".close,.close-btn").click(function(){
$("#myModal").modal('hide');
$("#myModal2").modal('hide');
});
});
</script>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn">Basic</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" style="right: 50%;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
</div>
</div>
</div>
<!--/. Modal -->
<!-- Modal -->
<div class="modal fade" id="myModal2" role="dialog" style="left: 50%;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default close-btn" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--/. Modal -->
</div>
</body>
</html>

I want to remove horizontal line from the modal body and footer?

I want to remove horizontal lines from my modal
$(document).ready(function(){
$('#myModal').modal('show');
});
<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>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
As you can see there is a line above and below the content
I think you are talking about the borders applied to modal. Use the below code.
.modal-header {
border-bottom: 0 none;
}
.modal-footer {
border-top: 0 none;
}
Its been 2 years since this question was asked and I still don't see any answer with bootstrap so here it is, Just use the border-0 class in the header and footer div. That should do the trick.
<div class="modal-header border-0">
....
</div>
<div class="modal-footer border-0">
....
</div>
Try this...
.no-border{
border:none;
}
and simply add to your class
<div class="modal-header no-border">
To remove these borders, I found it easiest to pass in a custom title component or string.
If you just want to remove the title altogether, set title={null} on props. Then the title and its bottom border will not show. Note this does not remove the close "X" icon.
The same goes for the footer. Passing footer={null} as a prop to removes it entirely (including the buttons). If you still want to show some content in the footer, there is a good example of using custom components in the Ant docs here
In bootstrap 4.5: The modal-header and footer lines are just empty spaces in between.
Actuly, the modal-header and footer and body has no background color.
but when you change it, a separator lines shows up with white color, so we apply the the color to modal-content instead, just like this:
.modal-content
background-color: red// this will hide the white separators
In some bootsrap version:
just add
.modal-footer
border: 0
.modal-header
border: 0
$(document).ready(function(){
$('#myModal').modal('show');
});
<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>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="background-color:red;border: 0;">
<div class="modal-header" style="border: 0;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer" style="border: 0;">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
try this:
<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" style='border: none;'>
<h5 class="modal-title" 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" style='border: none;'>
<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>
check:https://jsfiddle.net/sugandhnikhil/bz82oadf/
Thanks!!!!
This helped me:
.modal-header {
border: none !important;
}
.modal-footer {
border: none !important;
}

How to center align icon inside button?

.close-button button {
border: 1px solid black;
border-radius: 50%;
height: 25px;
width: 25px;
outline: none;
}
.close-button {
margin-right: 50%;
margin-top: 7%;
/* I wrote to center the button */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-success">Click</button>
<div class="modal" id="exampleModal">
<div class="modal-dialog">
<div class="modal-content" style="height:100px;">
<div class="close-button">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
</div>
</div>
</div>
Example:
https://www.w3schools.com/code/tryit.asp?filename=FTCZIK9F0A66
Text-align:center or line-height:50% not working. How can fix it ? Thank you.
Add the following classes
<div class="close-button h-100 d-flex align-items-center justify-content-center">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
Add font-size: 20px; on the button
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-success">Click</button>
<style>
.close-button button {
border: 1px solid black;
border-radius: 50%;
height: 25px;
width: 25px;
outline: none;
color: black;
font-size: 20px;
}
</style>
<div class="modal" id="exampleModal">
<div class="modal-dialog">
<div class="modal-content" style="height:100px;">
<div class="close-button h-100 d-flex align-items-center justify-content-center">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
</div>
</div>
</div>