Positioning a div inside of an overlay - html

Trying to create a contact form in an overlay. I have the overlay div working, but it only works if I set it to "position: absolute". The div inside of the overlay, will not position properly, regardless of what I try.
Need the "form-wrap to be centered vertically & horizontally.
<div id="overlay">
<div id="form-wrap">
<img id="close-btn" src="images/framework/close.png">
<form id="form-box">
<input name="first-name" id="first-name" type="text" maxlength="32">
</form>
</div>
</div>
#overlay{
top: 0;
left: 0;
height:100%;
width: 100%;
position: absolute;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
position: relative;
z-index: 900;
margin: 0;
background-color: white;
}

try this:
#overlay{
top: 0;
left: 0;
right: 0;
bottom: 0;
position: fixed;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
position: relative;
top: 50%;
left: 50%;
margin: -300px 0 0 -200px;
background-color: white;
}
Example

This will only work if the height of your overlay is greater than 600px!
#overlay{
top: 0;
left: 0;
height: 100%;
width: 100%;
position: absolute;
z-index: 899;
display: none;
background-color: rgba(0, 0, 0, 0.41);
}
#form-wrap{
width: 400px;
height: 600px;
top: 50%;
position: relative;
z-index: 900;
margin: -300px auto 0 auto;
background-color: white;
}
Example

Related

Element absolute inside div relative inside display table not show element complety

I'm trying show a modal in middle of the page with a width or hight dyç
I have a div with style absolute inside div with position relative, and the button not show completely,
I try to change z-index.
link of my code https://jsfiddle.net/renatoclt/qhn9v2py/3/
Here is my HTML & CSS
.ngx-utilitario-modal {
display: table;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
z-index: 1000;
overflow-y: auto;
margin-top: 15px;
}
.ngx-utilitario-modal .ngx-utilitario-modal-body {
display: table-cell;
vertical-align: middle;
padding: 0;
margin: 0;
width: fit-content;
height: fit-content;
overflow-y: auto;
}
.ngx-utilitario-modal .ngx-utilitario-modal-content {
background: #fff;
margin: 0 auto;
width: fit-content;
height: fit-content;
max-height: 100%;
overflow-y: auto;
padding: 15px;
}
.ngx-utilitario-modal .ngx-utilitario-modal-content .ngx-utilitario-modal-cerrar {
opacity: 1;
font-size: 18px;
position: absolute;
top: -30px;
right: -30px;
width: 30px;
height: 30px;
background-color: #fff;
border-radius: 100%;
-moz-border-radius: 100%;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.2);
padding: 0px;
}
.ngx-utilitario-modal-background {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
opacity: 0.75;
z-index: 900;
animation-delay: 2s;
}
<div class="ngx-utilitario-modal">
<div class="ngx-utilitario-modal-body">
<div class="ngx-utilitario-modal-content">
<div style="position: relative;">
<button type="button" class="ngx-utilitario-modal-cerrar" (click)="close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div>
este es ng-content
</div>
</div>
</div>
</div>
<div class="ngx-utilitario-modal-background" [#openClose]="showModal"></div>
<div class="ngx-utilitario-modal-open"></div>
The result actually shows half of the button. I expect to show the button completely
On your .ngx-utilitario-modal .ngx-utilitario-modal-content class, you should remove overflow-y: auto;
Then you'll likely need to adjust the width of the modal to make it not be 100% so the close button isn't cut off on the sides.
Something like this:
.ngx-utilitario-modal{
display: table;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
z-index: 1000;
overflow-y: auto;
margin-top: 15px;
}
.ngx-utilitario-modal .ngx-utilitario-modal-body {
display: table-cell;
vertical-align: middle;
padding: 0;
margin: 0;
width: fit-content;
height: fit-content;
overflow-y: auto;
}
.ngx-utilitario-modal .ngx-utilitario-modal-content{
background: #fff;
margin: 0 auto;
width: fit-content;
height: fit-content;
max-height: 100%;
padding: 15px;
width: 80%;
}
.ngx-utilitario-modal .ngx-utilitario-modal-content .ngx-utilitario-modal-cerrar{
opacity: 1;
font-size: 18px;
position: absolute;
top: -30px;
right: -30px;
width: 30px;
height: 30px;
background-color: #fff;
border-radius: 100%;
-moz-border-radius:100%;
box-shadow:0px 1px 2px rgba(0,0,0,0.2);
padding: 0px;
}
.ngx-utilitario-modal-background {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
opacity: 0.75;
z-index: 900;
animation-delay: 2s;
}
<div class="ngx-utilitario-modal">
<div class="ngx-utilitario-modal-body">
<div class="ngx-utilitario-modal-content">
<div style="position: relative;">
<button type="button" class="ngx-utilitario-modal-cerrar" (click)="close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div>
este es ng-content
</div>
</div>
</div>
</div>
<div class="ngx-utilitario-modal-background" [#openClose]="showModal"></div>
<div class="ngx-utilitario-modal-open"></div>
You can't use overflow: auto if you want this to work. Overflow would have to be set to visible.

Frosted glass effect on entire div doesn't work properly

I want a div to be completely covered by another layer that looks like frosted glass. The div under the frosted glass will be the background for my responsive website. It can be gradient or just a picture like in my fiddle. I managed to cover the the div with the effect. However there is still a little gap between the edges of the layers but I want the effect to cover the entire div. Thanks.
.bg {
position: absolute;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
margin: 0;
}
.blurred-box {
position: relative;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: inherit;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 100%;
height: 100%;
background: inherit;
position: absolute;
left: 0;
left position right: 0;
top: 0;
bottom: 0;
top position bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
<div class="bg">
<div class="blurred-box"></div>
</div>
One way to fix that is set :after to be bigger then container:
.bg {
position: absolute;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
margin: 0;
}
.blurred-box {
position: relative;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: inherit;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 120%;
height: 120%;
background: inherit;
position: absolute;
left: -10%;
top: -10%;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
<div class="bg">
<div class="blurred-box"></div>
</div>
Also you could try to scale a little the blurred image container and hide the overflow on .bg:
.bg {
overflow: hidden;
}
.blurred-box:after {
transform: scale(1.08, 1.08);
}
and set padding: 0; margin: 0; on body to get rid of the small offsets. Some styles are redundant. So, my attempt:
body {
padding: 0;
margin: 0;
}
.bg {
position: relative;
background-image: url(https://images.unsplash.com/photo-1422224832140-0e546210efc3?dpr=1&auto=compress,format&fit=crop&w=1950&h=&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 500px;
overflow: hidden;
}
.blurred-box {
width: 100%;
height: 100%;
background: inherit;
}
.blurred-box:after {
content: '';
width: 100%;
height: 100%;
background: inherit;
position: absolute;
top: 0;
left: 0;
top: 0;
bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
transform: scale(1.08, 1.08);
}
<div class="bg">
<div class="blurred-box"></div>
</div>

HTML / CSS columns overlap

I made a fiddle here.
Why does dice-canvas-container use the full width of the window and not stop at the start of attack-canvas-container?
Is it because both columns are positioned absolute?
<div id="attack-container">
<div id="dice-canvas-container">
<div id="plyra-dice-canvas"></div>
<div id="plyrb-dice-canvas"></div>
</div>
<div id="attack-canvas-container">
..................
</div>
</div>
If suitable with your requirement then you can go with flex css instead of position: absolute
#attack-container {
padding: 0;
text-align: center;
/* position: absolute; */
max-width: 1728px;
max-height: 1080px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1047;
/* float:left; */
display:flex;
}
#dice-canvas-container {
padding: 0;
text-align: center;
max-width: 1428px !important;
max-height: 1080px;
width: 100%;
height: 100%;
/* position: absolute; */
left: 0;
top: 0;
opacity: 0.8;
z-index: 1048;
/* display: block; */
/* float:left; */
background-color: red;
min-height:150px;
}
#attack-canvas-container {
#extend %background-gradient;
max-width: 300px;
max-height: 1080px;
font-size: 90%;
width: 100%;
height: 100%;
z-index: 1048;
/* position: absolute; */
right: 0;
top: 0;
box-sizing: border-box;
text-align: left;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
min-height: 150px;
}
#plyra-dice-canvas,
#plyrb-dice-canvas {
padding: 0;
text-align: left;
position: absolute;
max-width: 1428px;
max-height: 540px;
width: 100%;
height: 50%;
z-index: 1049;
}
#plyra-dice-canvas {
left: 0;
top: 0;
height: 50%;
}
#plyrb-dice-canvas {
left: 0;
top: 50%;
height: 50%;
border-top: 1px solid $brand-primary;
}
<div id="attack-container">
<div id="dice-canvas-container">
<div id="plyra-dice-canvas"></div>
<div id="plyrb-dice-canvas"></div>
</div>
<div id="attack-canvas-container">
</div>
</div>
Check the updated Fiddle.
Because you are using position: absolute (1) with width: 100% (2) for both containers in combination with z-index (3).
(1) : because of this, both container are absolutely positioned, not relatively.
(2) : since both have 100% width, they will overlap the other one.
(3) : the one with the higher z-index wins the upper hand.
You need to change the absolute positioning and give proper widths to the divs.

Overlay with circle cutout doesn't show in Safari

so I have this code:
.background-image {
height: 700px;
width: 100%;
background: red;
}
.top {
margin-top: -85px;
position: relative;
height: 700px;
}
.top .circle {
width: 100%;
height: 700px;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
margin: 0 auto;
z-index: 1;
}
.top .circle:before {
content: '';
position: absolute;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-radius: 50%;
box-shadow: 0px 0px 0px 9999px rgba(43, 54, 69, 0.75);
z-index: -1;
}
<div class="top">
<div class="background-image"></div>
<div class="circle"></div>
</div>
The result is overlay over the red background, with circle cut out in the middle of that. You can see results here: https://jsfiddle.net/erLqg448/
That code works great in Firefox and Chrome but in safari, that whole overlay seems to be missing. Any ideas?
Apparently safari has a problem with such a large value of spread-radius. But if you use a smaller value, like 99em it should cover your viewport and still render properly. Take a look at above snippet and updated jsFiddle
.background-image {
height: 700px;
width: 100%;
background: red;
}
.top {
margin-top: -85px;
position: relative;
height: 700px;
}
.top .circle {
width: 100%;
height: 700px;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
margin: 0 auto;
z-index: 1;
}
.top .circle:before {
content: '';
position: absolute;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-radius: 50%;
box-shadow: 0px 0px 0px 99em rgba(43, 54, 69, 0.75);
z-index: -1;
}
<div class="top">
<div class="background-image"></div>
<div class="circle"></div>
</div>

Center box in already centred div

I'm using the following HTML / CSS to overlay a box on a website i'm working on. I want the box to center in the screen, not start based on the centering already going on. So basically the white box should be on the center of the page, not the text test
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
}
.centrediv {
height: 200px;
width: 800px;
background-color: white;
border: 1px solid black;
}
<div class="loading"><div class="centrediv">Test</div></div>
Use transform: translate(-50%, -50%), top: 50% and left: 50% on .centreDiv to center it horizontally and vertically.
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: visible;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
}
.centrediv {
position: absolute;
height: 100px;
width: 200px;
background-color: white;
border: 1px solid black;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
<div class="loading">
<div class="centrediv">Test</div>
</div>