I am trying to create a bootstrap modal in a circular Form. Already created one but my problem is how can i insert the Text in the middle of the circle modal responsively?
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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.7/js/bootstrap.min.js"></script>
<style>
.modal-content {
background-color: #0099FF;
position: relative;
border-radius: 50%;
width: 100%;
height: auto;
padding-top: 100%;
}
</style>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
</div>
</div>
</div>
Flex box will help you, and I have removed padding-top that was pushing content in bottom. for height I have used height:100vw and max-height:600px that will make box proper circle shape.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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.7/js/bootstrap.min.js"></script>
<style>
.modal-content {
background-color: #0099FF;
position: relative;
border-radius: 50%;
width: 100%;
height: 100vw;
display: flex;
justify-content: center;
align-items: center;
max-height: 600px;
}
</style>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
Content
</div>
</div>
</div>
Append a div to model-content and give it position:absolute and position it to be in the center
<style>
.modal-content {
background-color: #0099FF;
position: relative;
border-radius: 50%;
width: 100%;
height: auto;
padding-top: 100%;
}
#text {
position: absolute;
top:50%;
left:45%;
}
</style>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div id="text">Lorem ipsum</div>
</div>
</div>
</div>
Here's an example : http://www.bootply.com/kBT3elyYFV
Related
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>
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;
}
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 have to add a background image to modal header and it should be responsive as well. I am able to add the image but I am getting issues in making it responsive. Any help appreciated.
Below is the sample snippet.
.modal-header {
border-bottom: none;
padding: 15px 15px 0 15px;
background-image: url(https://s9.postimg.org/ky3v3mduz/Jellyfish.jpg);
height: 208px;
background-size: contain;
background-repeat: no-repeat;
.close {
background: none;
border: none;
float: right;
font-size: 40px;
line-height: 20px;
padding: 0;
&:hover {
color: #hover-blush;
}
}
}
}
<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/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
</div>
</body>
Use a combination of background-size: cover; background-position: center center; assuming you want the center of the image to be the part that is always shown. Otherwise, adjust those as needed to ensure the focal point of the image will be shown.
.modal-header {
border-bottom: none;
padding: 15px 15px 0 15px;
background-image: url(https://s9.postimg.org/ky3v3mduz/Jellyfish.jpg);
height: 208px;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
.close {
background: none;
border: none;
float: right;
font-size: 40px;
line-height: 20px;
padding: 0;
&:hover {
color: #hover-blush;
}
}
}
}
<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/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
</div>
</body>
To have a responsive background image, what you're looking for is a percentage-based background-size. To completely cover the content area, you would use:
.modal-header {
background-size: 100% 100%;
background-repeat: no-repeat;
}
.modal-header {
border-bottom: none;
padding: 15px 15px 0 15px;
background-image: url(https://s9.postimg.org/ky3v3mduz/Jellyfish.jpg);
height: 208px;
background-size: 100% 100%;
background-repeat: no-repeat;
.close {
background: none;
border: none;
float: right;
font-size: 40px;
line-height: 20px;
padding: 0;
&:hover {
color: #hover-blush;
}
}
}
}
<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/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
</div>
</body>
Note that this will distort the image, which may not be what you want. In order to not distort the image, you should only specify a single parameter in background-size, and also tell the background to be fixed to the center:
.modal-header {
background-size: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.modal-header {
border-bottom: none;
padding: 15px 15px 0 15px;
background-image: url(https://s9.postimg.org/ky3v3mduz/Jellyfish.jpg);
height: 208px;
background-size: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
.close {
background: none;
border: none;
float: right;
font-size: 40px;
line-height: 20px;
padding: 0;
&:hover {
color: #hover-blush;
}
}
}
}
<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/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
</div>
</body>
Ultimately, considering the modal header itself will never change in height, you may want to look into simply using an <img> tag instead of a background-image.
Hope this helps! :)
I think all you need to have is a right size image and changing the background-size to cover.
.modal-header {
border-bottom: none;
padding: 15px 15px 0 15px;
background-image: url(http://www.bahai.org/chrome/img/beliefs/bahaullah-covenant-feature-img.jpg?3e7a0319);
height: 208px;
background-size: cover;
background-repeat: no-repeat;
.close {
background: none;
border: none;
float: right;
font-size: 40px;
line-height: 20px;
padding: 0;
&:hover {
color: #hover-blush;
}
}
}
}
<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/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
</div>
</body>
I want to make my bootstrap modal content responsive but when I resize browser modal contents like modal header , textboxes and login button going out of div please let me know how to make them responsive.
Here is the code.
HTML:
<!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.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4 /jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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" style="vertical-align:central">Login With Facebook</h4>
</div>
<div class="modal-body">
<img class="modal-content" src="http://www.firstbaptistashland.com/wp-content/uploads/2015/09/facebook-logo-png-transparent-background-150x150#2x.png" width="100" height="100" style="margin-left:220px;display:block;width:auto;" />
<br>
Email:<input type="text" /><br>
Password::<input type="text" />
</div>
<div class="modal-footer">
<input type="submit" class="btn-default modal-content" style="background-color: #4CAF50; border: none; color: white; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; padding: 10px 24px; margin-right: 200px; cursor: pointer; " value="Login" />
</div>
</div>`
</div>
</div>
</div>
try this way on image tag
style="margin-left:220px;display:block;width:auto;"
style="width: auto; left: 50%; transform: translateX(-50%); display: block;"