Overlay that covers only parent div - html

I have a group of controls inside a div (listbox and buttons below), and I'd like to cover them with a semi-transparent overlay (with a centered loading indicator in it).
Parent div size and position are not fixed.
Here is an example: http://jsfiddle.net/n4fbp8ex/
- Area of interest is inside red border. I'd like it to be covered with an overlay.
- "Loading..." div is my overlay. It should cover whole parent div (but nothing else), and text should be centered vertically and horizontally
How do I fix my "centeredOverlay" style?
html:
<div class="halfColumn">
some content
<br/>
<input />
</div>
<div class="halfColumn">
bla bla
<br/>
lorem ipsum
<div style="border-style:solid; border-width: 1px; border-color: red;">
<div class="centeredOverlay">Loading...</div>
<select size=2 style="width:100%; height:50vh">
</select>
<button>Click me</button>
<button>Click me too</button>
</div>
</div>
<div style="clear:both"></div>
</div>
css:
.centeredOverlay {
position: absolute;
background-color: rgba(0,0,0,0.3); /*dim the background*/
}
.halfColumn {
float: left;
width: 50%;
}
.halfColumn2 {
float: right;
width: 50%;
}

I think this is what you are looking for..although the text has not yet been positioned.
JSfiddle
EDIT - JSfiddle with new span element to center text
.centeredOverlay {
position: absolute;
background-color: rgba(255, 0, 0, 0.3);
/*dim the background*/
top:0;
left:0;
width:100%;
height:100%;
color:black;
text-align: center;
}
.halfColumn {
float: left;
width: 50%;
}
.wrapper {
position: relative;
border-style:solid;
border-width: 1px;
border-color: red;
}
.halfColumn2 {
float: right;
width: 50%;
}
<div class="main">
<div class="halfColumn">some content
<br/>
<input />
</div>
<div class="halfColumn">bla bla
<br/>lorem ipsum
<div class="wrapper">
<div class="centeredOverlay">Loading...</div>
<select size=2 style="width:100%; height:50vh"></select>
<button>Click me</button>
<button>Click me too</button>
</div>
</div>
<div style="clear:both"></div>
</div>

Is this what you're looking for?
.overlayContainer{
position:relative;
}
.overlay {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
opacity:0.3;
background:#b3b3b3;
text-align:center;
}
http://jsfiddle.net/n4fbp8ex/4/

The inset property is still not widely supported (Safari and Edge lagging behind, as usual) but look how cool it's going to be:
.parent-div {
height: 200px;
width: 200px;
background: red;
position: relative;
}
.child-div {
background: rgba(0,0,255,0.5);
position: absolute;
inset: 0;
}
<div class="parent-div">
<p>blablabla</p>
<div class="child-div"></div>
</div>
The child element only needs 2 CSS properties:
position: absolute;
inset: 0;
inset: 0 really is just a shorthand variation of
top:0;
bottom:0;
right:0;
left:0;

Related

CSS - prevent border from moving on scroll

When the browser window is resized, the borders are shifting away from the content?
How can I achieve a design where the border remains in one place, no matter the height of the window?
.story_header {
position: relative;
display: flex;
justify-content: center;
}
.story_header:before,
.story_header:after {
content: '';
width: 100px;
position: absolute;
border: 2px solid black;
margin-top: 20px;
left: 35%;
}
.story_header:after {
right: 35%;
left: auto;
}
<div class='section_1'>
<div class="grid-x">
<div class='large-12 cell'>
<h2 class='story_header'>Our Story</h2>
</div>
</div>
You need to wrap the 'Our Story' to an element let's say span then add the pseudo elements on that span. Try this:
CSS:
.story_header{
position:relative;
display:flex;
justify-content: center;
}
.story_title{
position:relative;
}
.story_title:before, .story_title:after{
content:'';
width:100px;
position:absolute;
border:2px solid black;
margin-top:20px;
}
.story_title:before{
right:100%;
}
.story_title:after{
left:100%;
}
HTML:
<div class="grid-x">
<div class='large-12 cell'>
<h2 class='story_header'> <span class="story_title">Our Story</span></h2>
</div>
</div>

CSS forced top z-index with parent overflow:hidden

I can't sort out how to move the element, which is placed under .content-wrapper{ overflow:hidden; .content{position:absolute;} }, to the very top.
Consider a screenshot below:
An image element with man photo is placed under the .content element. But the part of his head on photo, which is highlighted with yellow (pointed with red arrow) is hidden due to the parent .content-wrapper has an overflow:hidden property. The main problem is that I can't change the hidden overflow to whatever else.
Is that actually real to solve such a problem without using a JavaScript?
==== Supplement 1 ====
To clarify the problem, I've made up a code snippet below:
.wrapper{
width:100%;
overflow:hidden;
position:initial;
padding:0 10px;
background-color:#EEEEEE;
box-sizing:border-box;
}
.content-wrapper{
position:relative;
overflow:hidden;
background-color:#DDDDDD;
margin:10px 0;
min-height:350px;
}
.content{
background-color:white;
position:absolute;
top:30px;
left:10px;
right:10px;
bottom:10px;
}
.content.grayed{
background-color:#CCCCCC;
}
.content.positioned{
top:50px;
left:180px;
bottom:-50px; //negative positioned parts supposed to be hidden
right:-50px; //as .content-wrapper has overflow:hidden;
}
.content.positioned img{
width:40%;
height:auto;
margin-top:-40vh; //but that is not supposed to be hidden out of .content-wrapper
margin-left:10vw;
min-width:250px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Is there really no any solution?
I would consider adding the image outside and adjust the position to obtain this. Change the translation to adjust the position:
.wrapper {
width: 100%;
overflow: hidden;
position: relative; /*change this*/
padding: 0 10px;
background-color: #EEEEEE;
box-sizing: border-box;
}
.content-wrapper {
position: relative;
overflow: hidden;
background-color: #DDDDDD;
margin: 10px 0;
min-height: 350px;
}
.content {
background-color: white;
position: absolute;
top: 30px;
left: 10px;
right: 10px;
bottom: 10px;
}
.content.grayed {
background-color: #CCCCCC;
}
.content.positioned {
top: 50px;
left: 180px;
bottom: 0;
right: 0;
padding: 20px calc(40% - 0.4*148px) 0 20px; /* the space of the image*/
}
.content.positioned img {
position: absolute;
opacity: 0; /*Hide this one*/
}
.hack {
/*Don't use any top/bottom here !!*/
left: 190px;
right: 10px;
position: absolute;
z-index: 1;
}
.hack img {
width: 40%;
position: absolute;
right: 0;
bottom: 0;
transform: translateY(70%);
max-width:300px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="hack">
<img src="//i.imgur.com/DsOdy1V.png">
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br> ...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Add a <div> like content-wrapper-inner and move the height, position from content-wrapper into it.
.wrapper{
width:100%;
overflow:hidden;
position:initial;
padding:0 10px;
background-color:#EEEEEE;
box-sizing:border-box;
}
.content-wrapper{
overflow:hidden;
background-color:#DDDDDD;
margin:10px 0;
}
.content{
background-color:white;
position:absolute;
top:30px;
left:10px;
right:10px;
bottom:10px;
}
.content-wrapper-inner {
min-height:350px;
position:relative;
background-color: red;
}
.content.grayed{
background-color:#CCCCCC;
}
.content.positioned{
top:50px;
left:180px;
bottom:-50px; //negative positioned parts supposed to be hidden
right:-50px; //as .content-wrapper has overflow:hidden;
}
.content.positioned img{
width:40%;
height:auto;
margin-top:-40vh; //but that is not supposed to be hidden out of .content-wrapper
margin-left:10vw;
min-width:250px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content-wrapper-inner">
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Try to make overflow:visibleof the outer div of the content.
You can't have content reach out of a parent with overflow: hidden and still find a way to show the head. The question is why you need overflow hidden on the parent.
Perhaps you could use a sibling element for the image container and limit overflow on the content container.
Something like:
HTML
<div class="parent">
<div class="child-content-wrapper">
Content goes here
</div>
<div class="child-image">
Image goes here
</div>
</div>
CSS:
.parent {
position: relative;
}
.child-content-wrapper {
overflow: hidden;
}
.child-image {
position: absolute;
right: 0;
bottom: 0;
z-index: 1;
}
That should work and you'll be able to get the cut off effect on the rotated content box and the whole head.

Place image on top of element with css

How do I place an image on top of a button with html and css?
<div>
<img src="photo.jpg">
<button>Text</button>
</div>
I guess it should be something like
div {
position: relative;
}
img {
position: absolute;
top: 10px;
}
but it acts a bit weird.
Is it possible to just have a normal div and then set the img to float on top of everything else in the div element?
I don't know what's your purpose exactly, if you want the image to take the whole line, make the button lay beneath, why don't set the CSS display attribute of the image to display:block;?
hello see the below one its simple with a few line code
<div style="position:relative;" >
<img src="http://www.industrydynamics.ca/images/skype_icon.png" width="100" height="100" >
<input type="button" name="" value="Button" style="position:absolute;width:80px;left:10px;top:120px;" >
</div>
You can use position: absolute with transform: translate() on img.
This calc(-100% - 1px) means
-100% or - height of element (img in this case) that you are performing transform on, so it will translate for its own height up on Y axis
-1px is for top border on div element.
div {
position: relative;
display: inline-block;
border: 1px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 1px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
Just to demonstrate if you have border of 5px then you should use -5px in calc.
div {
position: relative;
display: inline-block;
border: 5px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 5px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
#bottom{
background-repeat: repeat-x;
height:121px;
width: 984px;
margin-left: 20px;
margin-top: 13px;
}
#bottom .content{
width: 182px; /*328 co je 1/3 - 20margin left*/
height: 121px;
line-height: 20px;
margin-top: 0px;
margin-left: 9px;
margin-right:0px;
display:inline-block;
position:relative;
}
<div id="bottom">
<div class="content">
<img src="http://placehold.it/182x121"/>
<button>Text</button>
</div>
</div>
May be you are trying to achieve something like this.
.userIcon {
background: url('https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png') no-repeat;
height:20px;
width:20px;
background-size:20px;
top: 8px;
}
.left {
float:left;
}
.right {
float:right;
}
.clear{
clear:both;
}
.button{
padding:10px;
color: #FFF;
background-color: #0095ff;
border:1px solid #07c;
box-shadow: inset 0 1px 0 #66bfff;
}
.btnText{
margin:2px 0px 0px 10px;
}
<div>
<button class="button">
<span class="left userIcon"></span>
<span class="right btnText">Create user account</span>
<span class="clear"></span>
</button>
</div>
If you just want to make the image to come over the button, you can make the display as block
check the following snippet
div img{
display:block;
}
button{
text-align:center;
margin:40px;
padding:10px;
}
<div>
<img src="https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png">
<button>Text</button>
</div>
Hope this helps

Fixing containers on browser zoom and resize

I've created the following banner below, using a triangle and rectangle in order to create the banner required over the image. However if the user zooms in on the browser these two containers have a gap between them. Any ideas how I could fix the two containers together or is there a better approach to writing this banner in general using CSS? Thanks in advance! :)
Code:
<html>
<style>
#triangle {
width: 0;
height: 0;
border-bottom: 150px solid red;
border-right: 50px solid transparent;
top: 8px;
position: relative;
}
#square {
background-color:red;
height:150px;
width:300px;
z-index: 3;
margin-left: 8px;
top: 8px;
position: relative;
color: white;
}
.align div {
display:inline-block;
float: left;
}
</style>
<div class="img">
<img src="IMAGE HERE" alt="test" width="800" height="150">
</div>
<div class="align">
<div id="square">
<h1>
Headline
</h1>
<p>
Some text here!
</p>
</div>
<div id="triangle"></div>
</div>
</html>
I did not see any white space between the rectangle and the triangle on my browser. However I cleaned your code so you can try this :
#triangle {
width: 0;
height: 0;
border-bottom: 150px solid red;
border-right: 50px solid transparent;
top: 8px;
position: relative;
}
#square {
background-color:red;
height:150px;
width:300px;
z-index: 3;
margin-left: 8px;
top: 8px;
position: relative;
color: white;
}
.align div{
display:inline-block;
float: left;
}
.align {
min-width:450px;
}
<div class="align">
<div id="square">
<h1>
Title
</h1>
<p>
Some text here.......
</p>
</div>
<div id="triangle"></div>
</div>
EDIT : Fixed the align at 400% zoom. Added min-width to .align .
This problem is browser dependent and not all browsers showing same problem. Chrome may show perfect but mozilla might show problem. Also, Use reset css to avoid any browser dependent css property.

centering div on 4 other divs

I know there are a lot of div centering questions but most only revolve that div and not surrounding divs...
I have 4 divs equal of width and height.
On top of that, I would like to have another div but centered (vertical & horizontal) above those 4.
I came this far:
<div class="content">
<div class="logoWrapper"></div>
<div class="topleft" id="wrapper"></div>
<div class="topright" id="wrapper"></div>
<div class="bottomleft" id="wrapper"></div>
<div class="bottomright" id="wrapper"></div>
</div>
.logoWrapper {
width:270px;
height:150px;
position:absolute;
left:50%;
top:50%;
margin:-75px 0 0 -135px;
}
#wrapper {
width: 49%;
height: 49%;
float: left;
background-color: #79be53;
border-color: white;
border-radius: 1%;
border-style: solid;
}
For some reason I dont understand yet this does not center the div...its a bit to the right of my screen! Or am I going crazy...?!
Do you want something like this
Then do this change position to relative and adjust margin accordingly
.logoWrapper {
width: 270px;
height: 150px;
position: relative;
left: 50%;
top: 50%;
margin: 0px 0 0 -135px;
background: #FF0004;
}
As mentioned by #billy id needs to be unique
so change your code in to this
<div class="content">
<div class="logoWrapper"></div>
<div class="topleft" id="wrapper1"></div>
<div class="topright" id="wrapper2"></div>
<div class="bottomleft" id="wrapper3"></div>
<div class="bottomright" id="wrapper4"></div>
</div>
and css to this
#wrapper1,#wrapper2,#wrapper3,#wrapper4 {
}
If you want your div like this
Then just add background color to .logoWrapper(Its transparent by default) its already in center. If its not in center for you just add unique id to those div's that might be causing issue
The easiest way to center div will be
.logoWrapper {
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
}
No need to adjust margin this property is enough to center div.
Are you looking for something like this? https://jsfiddle.net/81cLt6t6/
This is how I centered the box
.logoWrapper {
width:270px;
background-color: red;
height:150px;
position:absolute;
left: calc(50% - 135px);
top: calc(52% - 75px);
/*margin:-75px 0 0 -135px;*/
z-index: 9999;
}
IDs are unique, so don't repeat them.
I'm not quiet sure what you are trying to achieve, but here is a snippet using calc
.content {
position: relative
}
.logoWrapper {
width: 270px;
height: 150px;
position: absolute;
left: calc(50% - 135px);
top: calc(50% + 135px);
background: blue
}
.wrapper {
width: 49%;
height: 49%;
min-height: 200px;
float: left;
background-color: #79be53;
border-color: white;
border-radius: 1%;
border-style: solid;
}
<div class="content">
<div class="logoWrapper"></div>
<div class="topleftt wrapper"></div>
<div class="topright wrapper"></div>
<div class="bottomleft wrapper"></div>
<div class="bottomright wrapper"></div>
</div>