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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" id="bootstrap-css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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>
3
Answers
If you’re wanting the modal above all other elements in the window you can use position:fixed and z-index:99999
First of all set these attributes
Now Your .Modal will be visible in constraints of .slider.
Anyway if Your .Modal be visible out of the .slider
or
<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:
Bootstrap carousel with modal
Original example: