How to center loading image on overlay - css

I've tried about everything I can find on SO, so I'm hoping someone can point out what I'm doing wrong. I know there are extensive posts, but believe me I've tried, whats seems to be all of them...
The content area in the image below will expand as needs depending on the amount of bound data, I've only managed to horizontal center the loader, but not sure how to get it to sit in the center of the overlay. It's also worth mentioning that I'm using bootstrap.
Question:
How do I vertically center a loading animation inside another div?
Assumption:
I've been tinkering with the position and a few other options, but I'm not sure. I'm thinking the "tree" working down from the top element needs to be in a certain state to allow me to vertical center the div... but not sure what or how it can be achieved?
Working Fiddle or snippet below...
.overlay {
width: 100%;
height: 100%;
background: grey;
border-radius: 5px;
}
.overlay .overlay-modal {
line-height: 200px;
position: relative;
border-radius: 5px;
z-index: 11;
margin: 0 auto;
}
.overlay .overlay-modal p {
background-color: #f1c40f;
width: 300px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 120px;
color: white;
border-radius: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<br/>
<div class="container-fluid">
<div class="col-md-2 sidebar well">
Some Menu
</div>
<div class="col-md-6 main">
<div class="container-fluid overlay">
<div class="overlay-modal">
<p><i class="fa fa-gear fa-spin"></i>
</p>
</div>
<div class="row">
<div class="col-md-12">
<h3>Employee</h3>
<p>
Content
</p>
<p>
Content
</p>
<p>
Content
</p>
<p>
Content
</p>
<p>
Content
</p>
</div>
</div>
</div>
</div>
<div class="col-md-4 main">
Other content
</div>
<div>

You placed your position relative on the wrong element.
.overlay {
position: relative;
}
instead of
.overlay-modal {
position: relative;
}

Using this CSS worked for me.
.overlay .overlay-modal {
line-height: 200px;
position: absolute !important;
top: 50%;
left: 50%;
border-radius: 5px;
z-index: 11;
margin: 0 auto;
-webkit-transform: translate(-50%);
-moz-transform: translate(-50%);
-ms-transform: translate(-50%);
-o-transform: translate(-50%);
transform: translate(-50%);
}
Is there any reason you can't use position: absolute;

Related

How do I get text on to my background img

How do I add all the texts and buttons to display on the background img not below it?
Using Bootstrap 5.
<div class="container-fluid">
<div class="row landingPageBack img-responsive">
<img src="img/Landing.jpg" alt="">
<div class="text-center">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</div>
CUSTOM CSS
/* BG IMAGE*/
body html {
margin: 0;
padding: 0;
}
.landingPageBack {
background-image: url('img/Landing.jpg');
min-height : 100%;
min-width : 100%;
background-size: 100% 100%;
background-repeat:no-repeat;
overflow-y: hidden;
overflow-x: hidden;
}
/* BG IMAGE*/
.landingPageBack {
background-image: url('https://images.unsplash.com/photo-1637593755675-c38c18661a86?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1935&q=80');
background-size: cover;
background-repeat: no-repeat;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<section class="landingPageBack">
<div class="vh-100 vw-100 d-flex justify-content-center align-items-center">
<div class="text-center text-white">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</section>
<!-- begin snippet: js hide: false console: true babel: false -->
Please check the code, Hope it will help you.
Here are some links you should go through:
https://getbootstrap.com/docs/5.1/utilities/flex/
https://getbootstrap.com/docs/5.1/utilities/sizing/#relative-to-the-viewport
Make the wrapped container div position: relative. Then you can place the image inside and a text Block element. The text-blockelöement must be position: absolute. With the css attribute top and left, bottom, right you can position the text on the image.
/* Container holding the image and the text */
.container {
position: relative;
text-align: center;
color: red;
font-size: 5rem;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<img src="https://via.placeholder.com/500/green" alt="Snow" style="width:100%;">
<div class="centered">Centered</div>
</div>
And for your example, you would only have to adjust your two classes a bit.
/* BG IMAGE*/
body html {
margin: 0;
padding: 0;
}
.landingPageBack {
position: relative;
}
.text-center {
position: absolute;
top: 50%;
left: 40%
}
.landingPageBack {
background-image: url('https://via.placeholder.com/500/green');
background-repeat: no-repeat;
background-size: 100%;
}
<div class="container-fluid">
<div class="row landingPageBack img-responsive">
<img src="https://via.placeholder.com/500/green" alt="">
<div class="text-center">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</div>

Is there any possibility to show element over owl carousel item?

I have created two side by side owl carousel scroll elements. Schema:
I want to achieve, that price item description is little bit over owl carousel item borders. Schema:
Can someone please help with this situation using css or jquery.
Edit:
I crated replica. There are two owl elements. I want price:before element to be seen:
$("#banner_section_right .slider").owlCarousel({});
$("#banner_section_left .slider").owlCarousel({});
#container {
width: 100%;
height: 200px;
background: blue;
position: relative;
float: left;
}
#banner_section_right {
width: 70%;
background: red;
float: left;
}
#banner_section_left {
width: 30%;
background: green;
float: left;
}
#banner_section_left .item {
width: 100%;
background: yellow;
}
#banner_section_left .item:before {
width: 1em;
background: yellow;
top: 0;
content: "";
position: absolute;
right: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.transitions.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css" rel="stylesheet"/>
<div id="container">
<div id="banner_section_right">
<div class="slider">
<div class="item">
<p>
Viens
</p>
</div>
<div class="item">
<p>
Divi
</p>
</div>
<div class="item">
<p>
Viens
</p>
</div>
<div class="item">
<p>
Divi
</p>
</div>
</div>
</div>
<div id="banner_section_left">
<div class="slider">
<div class="item">
<p>
$1 000 000
</p>
</div>
</div>
</div>
</div>
I have example your can learn from this might help you what you want to achieve.
html:
<div id="container">
<div class="green"></div>
<div class="red"></div>
<div class="box"></div>
</div>
CSS:
#container{
width: 100%;
height: 200px;
background: blue;
position: relative;
}
div.green{
background: green;
display: block;
height: 100px;
}
div.red{
background: red;
display: inlinblock;
height: 100px;
}
div.box{
width: 100px;
height: 100px;
background: yellow;
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
}
have a look at this css property transform: translateY(-50%); this can move object over other.
Working example : http://fiddlesalad.com/css/div-over-other-div

CSS element's positioning moved by half in Safari (but fine in Chrome)

I have an element positioned correctly in Chrome (Works fine) but in Safari it's off by 50%. General CSS doesn't stump me but this one does. I built everything in react and that shouldn't really have an impact on the CSS (I'm stating this just for reference).
The code for the problem I'm having is:
margin-left: 50px;
background-color: white;
transform: rotate(120deg);
height: 38px;
width: 38px;
border-radius: 50%;
color: white;
position: absolute;
background: white;
transition: all 250ms;
-webkit-transition: all 250ms;
overflow: hidden;
Edit HTML ADDED
<div>
<div class="jbRhCt" style="align-items: center; position: absolute; width: 100%; margin: 0px; padding: 0px; justify-content: center;">
<div class="dbgKej">
<div class="fCJbKH" style="background: rgb(31, 139, 179);">
<div class="ijNdlz" style="margin-left: 26px;">
</div><div class="hOzhhR" style="margin-left: 72px;">
</div><div class="bPQgoG" style="margin-left: 120px;"></div>
<div class="dMJdoh" style="background: white; transform: rotate(120deg); margin-left: 50px;">
<div class="czTFjn" style="opacity: 1;"></div>
<div class="bbrObs" style="opacity: 1;"></div>
<div class="ftVltL" style="opacity: 1;"></div>
<div class="fqOkrX" style="opacity: 0;"><div class="enUBsj" style="opacity: 0;"></div>
<div class="bSIUmO" style="opacity: 0;"></div></div></div>
<p class="iWgihJ" style="margin-left: -40px; color: white;">The Light!</p>
</div>
</div>
</div>
</div>
It's off by the top and right and am unsure why. For reference, in Chrome this is how it looks (the white moon)
And in Safari it looks like so
Any idea what is going on here?
Hard to tell without the corresponding html and the css for the parent element. Since it's absolutely positioned, maybe try adding right: 0;
If that throws your moon out of the button, use a position: relative; on the parent element.
Different browsers have different initial points for absolute positioning. So specify coordinates, for example: right: 0; top: 0;

How can i fix position of a square in fieldset?

I want the square like below for all screensize
But when i resize the window in smaller screen size it is looking like below:
Please help me to solve this problem.I tried in many ways but couldnot solve the problem.Related codes are given below :
Html:
<div class="price-area">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="col-xs-12 col-sm-6">
<div class="square">
<fieldset class="price-border">
<legend>Standard</legend>
<p class="one" >Leaflet • Poster</p>
<p>Banner • Bill Board • Support 24/7</p>
</fieldset>
</div>
</div>
<div class="col-xs-12 col-sm-6">
</div>
</div>
<div class="col-xs-12"></div>
</div>
</div>
</div>
CSS:
.square {
position: relative;
}
.price-border {
margin-bottom: 25px;
}
.price-border legend {
width: auto;
margin-bottom: 2px;
margin-left: 42%;
}
.price-border p.one {
text-align: center;
margin-top: 20px 20px 10px auto;
}
.price-border p:last-child {
text-align: center;
margin-bottom: 50px;
margin-right: 20px;
}
.price-border:after {
height: 0px;
width: 0px;
border: 39px solid #000;
position: absolute;
top: 34%;
left: 93.5%;
content: "";
display: block;
z-index: ;
transform: rotate(45deg);
}
Change .price-border:after style
/* CHANGES */
.price-border:after {
left: auto;
right: -36px;
}
Basically you only want to move your element to the right for number of pixels and how your element has static width you can just set right attribute.
More generic solution would be doing it with transform. For your case, code bellow.
.price-border:after {
left: 100%;
transform: translateX(-55%) rotate(45deg);
}

Does CSS transition work with positioned elements?

This time, I'll include the code (as I've been asked previously).
The problem is that, even when this code does what I need (a CSS modal/lightbox window), I can't get it to animate neither the top nor the translate properties.
I think it's a problem of positioning, because, the original example used no position for the container but, instead, used the :before pseudo-element (I don't like it).
What's wrong with this code.
<!DOCTYPE html>
<html>
<head>
<meta charset="iso-8859-1" />
<title>Pure CSS Modal Window</title>
<style>
*
{
margin: 0px;
padding: 0px;
}
.modal-container
{
position: fixed;
display: none;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: rgba(0, 0, 0, 0.75);
}
.modal-content
{
position: absolute;
top: -100%;
left: 50%;
width: 70%;
max-width: 400px;
max-height: 400px;
transform: translateX(-50%);
background-color: #fff;
padding: 20px;
border-radius: 10px;
overflow-y: auto;
transition: all 5s;
}
.modal-container:target
{
display: block;
}
.modal-container:target .modal-content
{
top: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
Modal 1
Modal 2
<div class="modal-container" id="modal1">
<div class="modal-content">
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
Close
</div>
</div>
<div class="modal-container" id="modal2">
<div class="modal-content">
<p>This is the content of Modal 2</p>
Close
</div>
</div>
</body>
</html>
This is because the display state changes from display: none to display: block, meaning there is no previous layout to transition between.
One option would be to replace display: none with visibility: hidden and display: block with visibility: visible.
Working Example:
*
{
margin: 0px;
padding: 0px;
}
.modal-container
{
position: fixed;
visibility: hidden;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: rgba(0, 0, 0, 0.75);
}
.modal-content
{
position: absolute;
top: -100%;
left: 50%;
width: 70%;
max-width: 400px;
max-height: 400px;
transform: translateX(-50%);
background-color: #fff;
padding: 20px;
border-radius: 10px;
overflow-y: auto;
transition: all 5s;
}
.modal-container:target
{
visibility: visible;
}
.modal-container:target .modal-content
{
top: 50%;
transform: translate(-50%, -50%);
}
Modal 1
Modal 2
<div class="modal-container" id="modal1">
<div class="modal-content">
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
<p>This is the content of Modal 1</p>
Close
</div>
</div>
<div class="modal-container" id="modal2">
<div class="modal-content">
<p>This is the content of Modal 2</p>
Close
</div>
</div>
The solution provided by Alexander O'Mara works great (& also taught me a little), but I found another answer.
I solved it just separating both DIV's. I mean, instead of:
<div class="container">
<div class="content">
<p>Content here</p>
</div>
</div>
I used:
<div class="container">
</div>
<div class="content">
<p>Content here</p>
</div>
And for the CSS I used:
.container:target + .content {}
instead of
.container:target .content {}
All this without changing "display: none" for "visibility: hidden", as Alexander suggested, & it worked perfectly.
Thanks for your help. It's great to see that people around the world worries about other one's problems & try to solve them.
Cheers.
Marcelo.

Resources