If I have a div that has another div beneath it, would the underlying div's hover state be activated when the cursor is over the top div? Assume that the top div has a z-index of 5 and the other div's z-index is 1.
The short answer is no.
Take the following code as an example:
HTML:
<div id="one">one</div>
<div id="two">two</div>
CSS:
div {
position: absolute;
height: 300px;
width: 300px;
}
div:hover {
background-color: yellow !important;
}
div#one {
top: 0;
left: 0;
background-color: red;
z-index: 10;
}
div#two {
top: 150px;
left: 150px;
background-color: green;
z-index: 1;
}
The hover never activates on div#one when div#two is hovered in the overlapping area.
http://jsfiddle.net/Yff7Q/
Just whipped together something quick.
An element within another element with :hover will work (even on negative z-index).
An element outside the element with the negative z-index won't work.
CodePen | JsFiddle
HTML:
<div class="box">
<div class="inside">
</div>
</div>
<br><br>
<div class="box">
</div>
<div class="outside"></div>
CSS:
.box{
position:relative;
height:250px;
width:250px;
opacity:.4;
background:red;
}
.outside, .inside{
background:blue;
height:100px;
width:100px;
position:absolute;
z-index:-5;
}
.outside{
top:400px;
}
.inside:hover{
opacity:0;
}
.outside:hover{
opacity:0;
}
Related
How do I make a fixed element push other elements to the side when they overlap?
I don't want this:
Or this:
I want this:
I want to know how to make the elements collide or push so that I can easily align the elements without having to position them pixel by pixel.
Edit: I tried positioning a div to be fixed and displaying it as a block, but other elements were still overlapping it. Is it even possible to push elements away from a fixed element?
Is it even possible to push elements away from a fixed element?
I would say no. Not with this concept.
I can think of two solutions that I would not recommend.
Implement it with an iframe. But I would not recommend that.
Using JS to read out the width and assign it to the neighbouring element.
I updated my question after i got a good hint. For this example i added body height 200vh; that you can scroll down to see like it works.
body {
height: 200vh;
}
.verti {
background: red;
width: 200px;
height: 500px;
z-index: 10;
position: fixed;
top: 8px;
}
.hori {
background: green;
width: 500px;
height: 200px;
z-index: 1;
position: relative;
left: 200px;
}
<div class="w">
<div class="hori"></div>
<div class="verti"></div>
</div>
Tried using float? I'm pretty new to all this but this is what I got:
<body>
<div id="container">
<div id="fixed">
<p class="center-text white">Fixed <br>Element</p>
</div>
<div id="not-fixed">
<p class="center-text white">Not Fixed Element</p>
</div>
</div>
<style>
* {
padding: 0;
margin: 0;
font-family:arial;
}
.center-text {
text-align:center;
position:relative;
top:45%;
}
.white {
color:white;
}
#container {
margin:10px;
width:700px;
height:700px;
}
#fixed {
background-color:red;
position:fixed;
width:200px;
height:500px;
}
#not-fixed {
position:relative;
background-color:green;
width:500px;
height:200px;
float:right;
}
</style>
</body>
I'm currently working on some parent/child CSS code and is struggling to make the images smaller.
I have tried to change the size with [max-width] both in percentages and pixels but it didn't work. Trying to change the size in both the parent element [.entireWoman] and the 4 children elements didn't make any difference also.
<div class="entireWoman">
<div id="Woman">
<img src="../Portfolio/images/Woman.png" alt="Woman">
</div>
<div id="upperRotate">
<img src="../Portfolio/images/Upper_arm.png" alt="Upper arm">
</div>
<div id="downRotate">
<img src="../Portfolio/images/Down_arm.png" alt="Down arm">
</div>
<div id="handRotate">
<img src="../Portfolio/images/Hand.png" alt="Hand">
</div>
</div>
.entireWoman{
animation: enter 5s;
position:relative;
top:0;
left:0;
margin-top:400px;
margin-left:400px;
}
.entireWoman > #Woman {
position: absolute;
max-width:20%;
height:auto;
z-index: 2;
}
.entireWoman > #upperRotate{
max-width:10%;
height:auto;
position: absolute;
z-index: 1;
transform-origin: 90% 90%;
top:0;
left:0;
margin-top:10px;
margin-left:10px;
}
.entireWoman > #downRotate {
max-width:10%;
height:auto;
position: absolute;
z-index: 1;
transform-origin:99% 50%;
top:0;
left:0;
margin-top:5px;
margin-left:-150px;
}
.entireWoman > #handRotate {
max-width:10%;
height:auto;
position: absolute;
z-index: 1;
transform-origin: 99% 50%;
top:0;
left:0;
margin-top:20px;
margin-left:-220px;
}
Overall I just want to make the images smaller but none of the way I tried work.
I suspect the issue you’re having is that the container div is obeying your size rules but the image itself isn’t, and it’s overflowing the div. Try adding a rule to limit images to 100%:
img { max-width: 100%; }
In the snippet below notice that the div is the correct size, but the image extends beyond its boundary. If you set the image max-width to 100% it conforms accordingly.
#container {
position: relative;
width: 400px;
height: 200px;
}
.item1 {
position: absolute;
max-width: 50%;
border: 2px solid red;
}
img {
display: block;
opacity: 0.5;
}
input:checked + #container img {
max-width: 100%;
}
<div>
<p>The red box is the div containing the image.</p>
<p>Check the box to set max image width to 100%.</p>
</div>
<input type="checkbox"/>
<div id="container">
<div class="item1">
<img src="https://placekitten.com/600/300" />
</div>
</div>
How come the higher z-index of a parent for a child gets overridden by another parent?
The child topInner inside top gets overridden by bottom z-index. Is not z-index inherited?
I'll provide a code snippet here.
<style>
.top {
width:300px;
height:20px;
background-color:blue;
z-index:30;
}
.topInner {
width: 300px;
height: 20px;
background-color: green;
z-index: 30;
text-align:center;
}
.bottom {
width: 300px;
height: 60px;
background-color: red;
z-index: 20;
}
<div class="main">
<div class="top">TOP
<div class="topInner">Inner</div>
</div>
<div class="bottom">Bottom</div>
The divs should have position other than static for z-index to work.
working JSFiddle
I have the following markup:
http://jsfiddle.net/dy4TG/3/
<div class="slide-wrap">
<div class="slide">
<div class="text">Text here</div>
<img src="image.jpg" />
</div>
</div>
<div class="overlay"></div>
the .slide div must be absolutely positioned, and .slide-wrap would have position: relative.
Is it possible for the .overlay div to be between the image and the .text div? I need the stacking context to be like this (highest to lowest):
-Text
-Overlay
-Image
Thanks!
Live example here: http://movable.pagodabox.com (inspect the slideshow... in the specific context of this example, "overlay" has the class "kineticjs-content", and the .slide div is inside of the #slides parent div.
The key is to make sure everything is positioned absolutely, this way you can float everything however you wish, with any z-index.
css:
.overlay {
width: 20px;
height: 20px;
background: #fff;
z-index: 50;
position:absolute;
top:0;
left:50px;
}
img{
z-index: 20;
position:absolute;
top:0;
left: 5px;
width:100px;
height: 100px;
background: #000;
}
.text {
z-index: 999;
color: #888;
position:absolute;
top:0;
left: 5px;
}
.slide-wrap{
position:relative;
}
.slide{
position:absolute;
top:0;
left:0;
width:100px;
}
jsfiddle link: http://jsfiddle.net/a7Apz/3
You must give a z-index to .text, and it has to be the highest one if you want it to be on top of everything. And you must not give a z-index to .slide or .slide-wrap, as that would create a new stacking context, with the text and image nested in it. You need the text, the image and the overlay on the same stacking context.
Here is a jsfiddle to demonstrate. And here is the same idea applied to your jsfiddle.
Hi Folks Here is what i got in css:
#loading {
background:#000 url(loading.png) center;
opacity:0.5;
cursor:auto;
min-height:250px;
z-index:15;
}
#main {
padding: 10px;
z-index:1;
}
and in html:
<div id="loading">
<div id="main">Something here</div>
</div>
and i expect the loading.png to cover the div#main but it doesn't and "Something here" stays on the top of loading.png !?
Update: background is in CSS not an image in loading div.
Your HTML is wrong. The div main should be outside the div loading:
<div id="main">
<div id="loading"></div>
Something here
</div>
You also need to position the latter div using CSS so that it does not just push the main content out from underneath it, as well as sizing the div at 100% of its container's width and height:
#main { position: relative; }
#loading {
background: url("loading.png");
opacity: 0.5;
cursor:auto;
width: 100%;
height: 100%;
z-index:15;
/* Positioning */
position: absolute;
left: 0;
top: 0;
}