How to scale a background image in a modal? - html

I have a modal, and I have a background image in it. The only thing I need to do is scale it down. However, when I change the "width", it actually changes the modal's width. I can't come up with a solution. I have read many other posts here on Stackoverflow as well as other sites (such as css tricks) but I can not find a solution. Any thoughts will be more than welcome.
/* Login Modal */
.login-modal-content {
background-image: url('https://cdn.reebit.cl/images/isotipo.png');
background-repeat: no-repeat;
width: 100%;
height: auto;
background-position: right 20px bottom 10px;
}
.login-modal-header {
border-bottom: 0px;
}
.login-modal-body {
width: 100%;
margin: 0 auto;
}
.login-modal-body img {
width: 60%;
}
// My html seems correct to me //
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="modal fade bd-example-modal-lg login-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="loginModal">
<div class="modal-dialog modal-lg">
<div class="modal-content login-modal-content">
<div class="modal-header login-modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body modal-body-img login-modal-body text-center col-lg-6 pb-5 pt-0">
<img src="https://cdn.reebit.cl/images/header-logo.svg">
<h5>¡Hola! Ingresa a tu cuenta</h5>
<form class="login-form">
<div class="form-group login-modal-form-email">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Correo electrónico">
</div>
<div class="form-group login-modal-form-password">
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Clave">
</div>
<button type="submit" class="btn btn-block btn-modal-login">Ingresar</button>
</form>
Olvidé mi clave
</div>
</div>
</div>
</div>

You probably wanna try using background-size CSS property:
/* Login Modal */
.login-modal-content {
background-size: cotain; // Or 'cover'
background-image: url('https://cdn.reebit.cl/images/isotipo.png');
background-repeat: no-repeat;
width: 100%;
height: auto;
background-position: right 20px bottom 10px;
}
There's a very good tutorial here too: https://css-tricks.com/almanac/properties/b/background-size/

Related

How do I make an image take up 100% of a Bootstrap modal container?

I have some bootstrap modals with images in them. Some of them are long vertically which makes a scrollbar appear. I tried to fix this by setting a max-height to the modal-content and having modal-body, where the image is inside of to be 100% of that. Now the backdrop is the height I set it to, but the image still extends past the container.
jsfiddle: https://jsfiddle.net/cLn52tqg/
.modal-content {
max-height: 85vh;
}
.modal-content>.modal-body {
max-height: 100%;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="modal fade show" id="modalImage2" tabindex="-1" aria-labelledby="allImage2" aria-hidden="true" style="display: block;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header text-center">
<h2 class="modal-title w-100 text-dark" id="allImage2">image title</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<img class="img-fluid" src="https://images.unsplash.com/photo-1564754943164-e83c08469116?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80" alt="">
<p class="modalText text-dark text-center mt-2">image description</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Seems like setting a max height is preventing the image to scale down inside the container. Setting height fixed the issue you can add a calc() function if you want to add some extra height into consideration.
.modal-content>.modal-body{
height: 70vh;
overflow: auto;
position: relative;
}
.modal-content>.modal-body > img{
object-fit: contain;
width: 100%;
height: 100%;
}
I setup a custom class for the modal content which will use display: grid for this -- it doesn't work in the tiny little snippet preview but if you run the snippet and view full page you will see it working nicely
.modal-content.grid-content {
display: grid;
grid-template-rows: auto 1fr auto;
height: calc( 100vh - 1.75rem - 1.75rem ); /* Account for vertical margin on parent */
}
.modal-content.grid-content .modal-body {
min-height: 0;
display: grid;
grid-template-rows: 1fr auto;
}
.modal-content.grid-content .modal-body > * {
min-height: 0;
}
.modal-content.grid-content .modal-body img {
display: block;
margin: auto;
max-height: 100%;
/* REMOVE THESE 2 LINES IF YOU WANT IMAGE TO CCENTER INSTEAD OF CROP */
object-fit: cover;
width: 100%;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="modal fade show" id="modalImage2" tabindex="-1" aria-labelledby="allImage2" aria-hidden="true" style="display: block;">
<div class="modal-dialog modal-lg">
<div class="modal-content grid-content">
<div class="modal-header text-center">
<h2 class="modal-title w-100 text-dark" id="allImage2">image title</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<img class="img-fluid" src="https://images.unsplash.com/photo-1564754943164-e83c08469116?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80" alt="">
<p class="modalText text-dark text-center mt-2">image description</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

How can I make the H1 tag responsive?

Hello everyone my question is as follows. How can I make the H1 tag responsive so that it doesnt shift boxes on my image. I am using bootstrap 4.5.2 for my project.
Here is an image on the pc version
Here is an image on the mobile version (the H1 tag has shifted 1 box to the left)
Here is my html code
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
officeMap
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">officeMap</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="dynamic-content">
<img src="PlanPage/Resources/grid.png" alt="officeMap" class="img-fluid">
<div class="room1"><h1>1</h1></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is my css
body {
background-image: url('Resources/blurred_desk1.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.room1 {
position: absolute;
bottom: 10%;
left: 12%;
}
The image im using
https://hbr.org/resources/images/article_assets/2013/04/grid.png
I tried like this and it worked.
#media screen and (min-width: 1200px){
.room1 {
position: absolute;
bottom: 10%;
left: 12%;
}
}
#media screen and (max-width: 1199px) and (min-width: 990px) {
.room1 {
position: absolute;
bottom: 10%;
left: 18%;
}
}
#media screen and (max-width: 989px) {
.room1 {
position: absolute;
bottom: 10%;
left: 30%;
}
}
You can not use percentage values and expect them to behave this way.
You can use flexbox and set fix size for image and shrink h1 to get remaining width with flex-shrink-1.
Something like this:
Codepen

Loading div in front of bootstrap modal

I'm using bootstrap and modals for partial views, I have a "loading" div to put in front of everything while getting the data. I can't put the loading div in front of the modal, already tried with z-index but still nothing.
This is my css:
.load {
position: absolute;
z-index: 500 !important;
height: 100%;
display: none;
border: 0;
padding: .5em 1em;
overflow: auto;
top: 0%;
left: 0%;
background: white;
width: 100%;
border: none;
opacity: 0.8;
}
.imagen_loading {
position: absolute;
z-index: 500 !important;
top: 35%;
left: 43%;
width: 300px;
height: 300px;
background: url('../../Content/img/gif/loader3.gif')
}
And this is my modal:
<div class="modal fade" id="modal_aprobar_transferencia" data-target="#modal_aprobar_transferencia">
<div class="modal-dialog">
<div class="modal-content" style="overflow:auto; width:90% !important; height:90% !important;">
<div class="modal-header orange">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"><strong></strong>Transfers</h4>
</div>
<div class="modal-body">
#{
Html.RenderAction("lista_transferencias", "Almacen");
}
</div>
</div>
</div>
</div>
Edit:
<div class="container-fluid" style="padding-left:7em; padding-right:3em;">
<h3>Storehouse</h3>
<div class="row barra_menu" style=" ">
<div class="" style="float:left;">
<button type="button" class="btn btn-lg btn-info" href="#modal_formulario_altas" data-toggle="modal">
Receives
</button>
</div>
<div class="dropdown">
<button type="button" class="btn btn-lg btn-info dropdown-toggle" data-toggle="dropdown" style="float:left;">
Transfers <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
New transfer
New seal package
See transfers
Receive transfers
</li>
</ul>
</div>
<div class="modal fade" id="modal_nuevos_sellos" data-target="#modal_nuevos_sellos">
<div class="modal-dialog" style="width:30% !important; height:15% !important;">
<div class="modal-content">
<div class="modal-header orange">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"><strong></strong>Add seal package</h4>
</div>
<div class="modal-body">
<div class="form-group">
<div class="form-group col-3">
<label for="caja_inicio">First seal </label>
<input type="text" class="form-control numeric must " onkeydown="upperCaseF(this)" id="caja_inicio">
</div>
<div class="form-group col-3">
<label for="caja_final">Last seal</label>
<input type="text" class="form-control numeric must " onkeydown="upperCaseF(this)" id="caja_final">
</div>
<div class="form-group col-3">
<label for="caja_sucursal">Branch office </label>
<select type="text" class="form-control" id="caja_sucursal">
<option>Select</option>
<option value="1">Fortune</option>
<option value="2">Lucky one</option>
</select>
</div>
<div class="form-group col-3">
<br />
<button type="button" class="btn btn-primary mb-2" id="boton_guardar_sello" onclick="guardar_sellos_index(event);">Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal_aprobar_transferencia" data-target="#modal_aprobar_transferencia">
<div class="modal-dialog">
<div class="modal-content" style="overflow:auto; width:90% !important; height:90% !important;">
<div class="modal-header orange">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"><strong></strong>Approval of transfers</h4>
</div>
<div class="modal-body">
#{
Html.RenderAction("lista_transferencias", "Almacen");
}
</div>
</div>
</div>
</div>
<!----LISTADO DE INVENTARIO----->
<div class="panel panel-default panel-primary">
<div class="panel-heading"><h4>Inventory</h4></div>
<div style="padding:1em; overflow:auto; ">
<table id="tabla_inventario" class="table table-striped ">
<thead>
<tr>
<th>#Html.DisplayNameFor(model => model.id_inventario)</th>
<th>#Html.DisplayNameFor(model => model.sucursal)</th>
<th>#Html.DisplayNameFor(model => model.po)</th>
<th>#Html.DisplayNameFor(model => model.mill_po)</th>
<th>#Html.DisplayNameFor(model => model.total)</th>
<th>#Html.DisplayNameFor(model => model.categoria_inventario)</th>
<th>#Html.DisplayNameFor(model => model.descripcion)</th>
<th>#Html.DisplayNameFor(model => model.estado)</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>#Html.DisplayFor(modelItem => item.id_inventario)</td>
<td>#Html.DisplayFor(modelItem => item.sucursal)</td>
<td>#Html.DisplayFor(modelItem => item.po)</td>
<td>#Html.DisplayFor(modelItem => item.mill_po)</td>
<td>#Html.DisplayFor(modelItem => item.total)</td>
<td>#Html.DisplayFor(modelItem => item.categoria_inventario)</td>
<td>#Html.DisplayFor(modelItem => item.descripcion)</td>
<td>#Html.DisplayFor(modelItem => item.estado)</td>
<td>
<button type="button" onclick="ver_item(#item.id_inventario)" class="btn btn-default glyphicon glyphicon-search " style="color:black; padding:0px 5px 0px 5px;"></button>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div id="loading" class="load">
<div id="spinner" class="imagen_loading" style=""></div>
</div>
My partial views are mostly the same, tables and edits.
I'd appreciate any help.
The trick in here is data-backdrop="false" style="background-color: rgba(0, 0, 0, 0.5);" by removing the default backdrop and create a dummy one by setting background color of the dialog itself with some alpha.
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="false" style="background-color: rgba(0, 0, 0, 0.5);">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
Notes: clicking on the background does not close the dialogue as is expected.
Solution: So to achieve that you have to add some javascript code. Here is some example of how you can accomplish this.
$('.modal').click(function(event){
$(event.target).modal('hide');
});
HTML: place this within your body tag
<div id="LoaderWindow">
<div id="Loader"></div>
</div>
/* CSS for loading*/
.loader-window {
width: 100%;
height: 100%;
position: fixed;
z-index: 1051;
background: rgba(54, 70, 93, 0.95);
}
.loader {
position: absolute;
top:50%;
left:50%;
border: 8px solid #f3f3f3;
border-radius: 50%;
border-top: 8px solid #5BFEC8;
width: 60px;
height: 60px;
margin-top:-30px;
margin-left:-30px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
You have to use jquery to add class.
function loader(
operation
) {
if (operation == 'add') {
$('#LoaderWindow').addClass('loader-window');
$('#Loader').addClass('loader');
} else {
$('#LoaderWindow').removeClass('loader-window');
$('#Loader').removeClass('loader');
}
}
loader('add') would be used when you request data and after received a response use loader('remove');
When inspecting the modals within the Bootstrap (3 and 4) documentation, it looks like their default z-index is 1050. Did you try increasing the z-index of your loading div to something greater than 1050?
Try setting this styles to your loading div:
#loading {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
background: url(img/preloader.gif) center no-repeat #fff;
}
Be advised, the loading <div> must be out of the modal <div>.
HTML
<div id="loading"></div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div>

how to put image in header laravel

I want to put image as header's background and I tried this and it doesn't work.
.header-fit {
background-image: url('{{ asset('img/justice.jpg') }}');
max-height: 100%;
height: auto;
width: 100%;
}
<header id="home" class="header-fit">
<div id="maincontent" class="container" tabindex="-1">
<div class="row">
<div class="col-lg-12">
<div class="input-group">
<input type="text" class="form-control" placeholder="#">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Search</button>
</span>
</div>
</div>
</div>
</div>
</header>
I guess this css would be worked solution for you if path to image is correct
.header-fit {
background-image: url(img/justice.jpg);
max-height: 100%;
height: auto;
width: 100%;
}
Here is you would read some info regarding usage of background-image property

How to get rid of the space when resizing the bootstrap div browser?

When I resize my browser to a mobile size, I get a large amount of gap between both div's[Searcharea div and Steps div]. But, while in pc mode, there is no gap. I tried margin top and bottom but, I am not able to figure out the error. Please Help . Thanks. Below is the code.
HTML CODE:
<div class="searcharea col-md-12">
<div class="head col-md-12 col-xs-12">
<h1> Search for your own seat. </h2>
</div>
<div class="col-md-12 col-xs-12">
<div class="input-group custom-search-input">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-danger" type="button">
<span class="glyphicon glyphicon-search"></span> CLICK
</button>
</span>
</div><!-- /input-group -->
</div>
</div> <!-- Search Bar ENDs -->
<div class="steps col-md-12 col-xs-12">
<div class="find col-md-12">
<h2 class="findhead">Finding Nearby ! </h2>
</div>
</div>
CSS:
.searcharea{
background-image: url(restback.jpg);
background-repeat: no-repeat;
background-size: 100%;
height: 600px;
margin-top: 0px;
}
.custom-search-input {
margin:5%;
width: 60%;
margin-left: 20%;
}
.head{
color: #ffffff;
margin-top: 15%;
text-align: center;
}
.steps {
background-color: lightblue;
height: 700px;
margin-top: 0px;
}
.find{
text-align: center;
}
Problem is with your fixed height i.e. height: 600px;
/* CSS used here will be applied after bootstrap.css */
.searcharea {
background-image: url('http://placehold.it/1200x600');
background-repeat: no-repeat;
background-size: 100% 100%; // Add
min-height: 300px; // Add
}
.custom-search-input {
margin: 0 auto; // Replaced
width: 60%;
padding-bottom: 5%; // Add
}
.head {
color: #ffffff;
margin-top: 15%;
text-align: center;
}
.steps {
background-color: lightblue;
height: 700px;
margin-top: 0px;
}
.find {
text-align: center;
}
<div class="searcharea col-md-12">
<div class="head col-md-12 col-xs-12">
<h1> Search for your own seat. </h1>
</div>
<div class="col-md-12 col-xs-12">
<div class="input-group custom-search-input">
<input class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-danger" type="button">
<span class="glyphicon glyphicon-search"></span> CLICK
</button>
</span>
</div>
<!-- /input-group -->
</div>
</div>
<!-- Search Bar ENDs -->
<div class="steps col-md-12 col-xs-12">
<div class="find col-md-12">
<h2 class="findhead">Finding Nearby ! </h2>
</div>
</div>
Bootply