Z-Index in combination with position: fixed and transitions (CSS) - css

I'm setting up a new portfolio website and use the Onepage Scroll Plugin by Pete R.
I added a fix navigation bar and now want to have elements inside a slide overlapping this navigation. Here's a code example at codepen:
http://codepen.io/terrorpixel/pen/BNxYxq
HTML
<nav></nav>
<div class="container">
<div>Bring me to the front!</div>
</div>
CSS
nav {
height: 82px;
left: 0;
position: fixed;
top: 0;
-webkit-transition: background 1.15s ease-in-out 0s;
-moz-transition: background 1.15s ease-in-out 0s;
transition: background 1.15s ease-in-out 0s;
width: 100%;
z-index: 2;
background:rgba(0,255,0,.85);
}
.container {
background:blue;
position: relative;
-webkit-transform: translate3d(0px, -1%, 0px);
-moz-transform: translate3d(0px, -1%, 0px);
transform: translate3d(0px, -1%, 0px);
-webkit-transition: all 2s ease 0s;
-moz-transition: all 2ms ease 0s;
transition: all 2ms ease 0s;
height: 5000px;
z-index:1;
width: 70%;
margin: 0 auto;
}
.container div {
padding: 250px 100px;
z-index:10;
position:absolute;
right:0;
top:0;
background:red;
}
I try to get the red box to the front. I think the failure belongs to the fact that I'm using z-index in different stacking contexts. The inside the .container hadn't worked, too.. Is there actually a possibility to realize that :/?

You need to move .container div outside of .container.
When you place a positioned element inside a positioned element, the children start a new stacking order but it starts in context with the parents value. So even if you specify a z-index value of 10000 to a child of a parent with a z-index of 2 its like the child has a z-index of 2.10000.
This example is crude but you get the idea:
nav {
height: 82px;
left: 0;
right: 0;
position: fixed;
top: 0;
-webkit-transition: background 1.15s ease-in-out 0s;
-moz-transition: background 1.15s ease-in-out 0s;
transition: background 1.15s ease-in-out 0s;
z-index: 2;
background: rgba(0, 255, 0, .85);
}
.container {
background: blue;
position: relative;
-webkit-transform: translate3d(0px, -1%, 0px);
-moz-transform: translate3d(0px, -1%, 0px);
transform: translate3d(0px, -1%, 0px);
-webkit-transition: all 2s ease 0s;
-moz-transition: all 2ms ease 0s;
transition: all 2ms ease 0s;
height: 5000px;
z-index: 1;
width: 70%;
margin: 0 auto;
}
.front {
z-index: 3;
position: absolute;
right: 15%; /* half of 30% (the left over of 70% container width) */
top: 82px;
background: red;
}
<nav></nav>
<div class="container">
</div>
<div class="front">Bring me to the front!</div>
</div>

Related

Overlay covers whole dive - but keep fonts white

I trying to change the brightess of a div (not only an image brightness). Generaly there is an image in a div, description and caption, the main div background color is white. I want to show ovarlay div onmouse hover. Idea is to cover main div with overlay div. But now I getting only the image brightness change , what I want to achieve is to cover the hole div and keep whithe fonts.
When I add a thumbnail brightness effect it also influence the fonts to became darker. how to do that keeping fonts white.
col-sm-6, caption, thumbnail classes are defined by bootstrap.
The code of:
<div class="hovereffect thumbnail Staffinview1 delay1s">
<img src="./images/photo.jpg">
<div class="overlay">
<?php echo Person_description; ?>
</div>
<div class="caption">
<h3>Name Surname</h3>
</div>
</div>
</div>
The css code:
.thumbnail:hover {
transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-webkit-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.5);
}
.hovereffect {
width: 100%;
height: 100%;
float: left;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
}
.hovereffect .overlay {
position: absolute;
overflow: hidden;
width: 80%;
height: 80%;
left: 10%;
top: 10%;
border-bottom: 1px solid #FFF;
border-top: 1px solid #FFF;
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: scale(0,1);
-ms-transform: scale(0,1);
transform: scale(0,1);
color: #fff;
}
.hovereffect:hover .overlay {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.hovereffect img {
display: block;
position: relative;
-webkit-transition: all 0.35s;
transition: all 0.35s;
}
.hovereffect:hover img{
filter: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="filter"><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="linear" slope="0.6" /><feFuncG type="linear" slope="0.6" /><feFuncB type="linear" slope="0.6" /> </feComponentTransfer></filter></svg>#filter');
filter: brightness(0.3);
-webkit-filter: brightness(0.3);
}
I believe You are trying to achieve a mask
You can use z-index property and postion:absolute for that overlay div
css rule
.overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0%;
z-index: 0;
transition: all 0.5s;
}
.overlay:hover {
z-index: 1;
background: rgb(173, 173, 173);
opacity: 0.5;
}
Snippet below
.thumbnail:hover {
transition: all 0.5s ease - in -out;
- moz - transition: all 0.5s ease - in -out;
- webkit - transition: all 0.5s ease - in -out;
- o - transition: all 0.5s ease - in -out;
- ms - transition: all 0.5s ease - in -out;
box - shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.5);
}
.hovereffect {
width: 100 %;
height: 100 %;
float: left;
overflow: hidden;
position: relative;
text - align: center;
cursor: default;
}
.hovereffect.overlay {
position: absolute;
overflow: hidden;
width: 80 %;
height: 80 %;
left: 10 %;
top: 10 %;
border - bottom: 1px solid# FFF;
border - top: 1px solid# FFF;
- webkit - transition: opacity 0.35s, -webkit - transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
- webkit - transform: scale(0, 1);
- ms - transform: scale(0, 1);
transform: scale(0, 1);
color: #fff;
}
.hovereffect:hover.overlay {
opacity: 1;
filter: alpha(opacity=100);
- webkit - transform: scale(1);
- ms - transform: scale(1);
transform: scale(1);
}
.hovereffect img {
display: block;
position: relative;
- webkit - transition: all 0.35s;
transition: all 0.35s;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0%;
z-index: 0;
transition: all 0.5s;
}
.overlay:hover {
z-index: 1;
background: rgb(173, 173, 173);
opacity: 0.5;
}
<div class="hovereffect thumbnail Staffinview1 delay1s">
<img src="./images/photo.jpg">
<div class="overlay">
<?php echo Person_description; ?>
</div>
<div class="caption">
<h3>Name Surname</h3>
</div>
</div>

Transform scale property not working in Chrome & Safari

.tricky {
width: 200px;
height: 200px;
border-radius: 50%;
border: 0px solid;
background: #2373bd;
display: inline-block;
position: relative;
overflow: hidden;
}
.tricky_image {
width: 100%;
height: 100%;
-moz-transition: all .6s ease;
-webkit-transition: all .6s ease;
-ms-transition: all .6s ease;
-o-transition: all .6s ease;
transition: all .6s ease;
opacity: 0.7;
border-radius: 50%;
filter: alpha(opacity=70);
overflow: hidden;
}
.tricky_image:hover {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
<!doctype html>
<html>
<head>
</head>
<body>
<div class="tricky">
<img class="tricky_image" src="location_images/sanfranciscoweb.png" alt="Example">
</div>
</body>
</html>
my desired effect is only working in Firefox and i assume IE. I am starting with a transparent image with a div wrapper around it with a blue background. When the user hovers over the image, i want it to zoom in and restore the opacity to 100% without breaking the set width and height of the div wrapper. This works perfectly in Firefox, but when i run the animation in Chrome the image exceeds the width of the blue div wrapper behind it. Here is my code and any help would be appreciated & JS Fiddle http://jsfiddle.net/yaLupdzo/1/:
<!doctype html>
<html>
<head>
<style>
.tricky {
width: 200px;
height: 200px;
border-radius: 50%;
border: 0px solid;
background: #2373bd;
display: inline-block;
position: relative;
overflow: hidden;
}
.tricky_image {
width: 100%;
height: 100%;
-moz-transition: all .6s ease;
-webkit-transition: all .6s ease;
-ms-transition: all .6s ease;
-o-transition: all .6s ease;
transition: all .6s ease;
opacity: 0.7;
border-radius: 50%;
filter: alpha(opacity=70);
overflow: hidden;
}
.tricky_image:hover {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
</style>
</head>
<body>
<div class="tricky">
<img class="tricky_image" src="location_images/sanfranciscoweb.png" alt="Example">
</div>
</body>
</html>
This is a known issue as filed here: https://code.google.com/p/chromium/issues/detail?id=157218
In Webkit, with hardware acceleration, animated layers get promoted to a different rendering surface during animation, and then demoted once the animation is complete.
Turns out there is a simple solution. Have the container element 'promoted' to the same rendering layer as the hardware accelerated child by adding a lightweight animation to it:
.tricky {
width: 200px;
height: 200px;
border-radius: 50%;
border: none;
background: #2373bd;
display: block;
overflow: hidden;
-webkit-transform:scale(1.0);
}
.tricky_image {
width: 200px;
height: 200px;
-webkit-transition: all .6s ease;
opacity: 0.7;
}
.tricky:hover {
-webkit-transform:scale(1.0);
}
.tricky:hover .tricky_image {
opacity: 1;
-webkit-transform:scale(1.2);
}
See: http://jsfiddle.net/yaLupdzo/3/
Note that I've also added a simple animation to the parent container's default state, so that the same issue doesn't happen when hovering out.
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-o-transform: scale(1.2);
transform: scale(1.2);
You can repeat your code like that for browser compatibility..

How can i horizontally center this animation?

I've got 3 images superposed for a css animation on a link hover. I'm using position:absolute for overlaying the 2 animated images. But then i don't know how i could center the animation on the page.
Here is the CodePen
http://codepen.io/beng_beng/pen/IHAFD
<div id="avatar">
<img src="http://placehold.it/174x174" alt="rotator">
<a id="rotator" href="#"><img src="http://s28.postimg.org/gfrse4h7d/small.png" alt="rotator"><span><img src="http://s27.postimg.org/j6qdwtowf/small.png" alt="rotator"></span></a>
</div>
body {
margin:0;
padding:0;
}
#avatar img {
position: relative;
height: 174px;
width: 174px;
border-radius: 100%;
}
a#rotator img {
position: absolute;
top: 0;
left: 0;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
}
a#rotator:hover img {
-webkit-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
-o-transform: rotate(-360deg);
-ms-transform: rotate(-360deg);
}
a#rotator span img {
position: absolute;
width: 147px;
height: 147px;
top: 14px;
left: 14px;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
}
a#rotator:hover span img {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
}
Add this to your CSS:
#avatar {
text-align:center;
position:relative;
width:147px;
margin:0 auto;
}
You can use the following trick to center images:
left: 50%;
margin-left:14px;
But changing the position of the parent object like King-King suggested is better.
#avatar {
margin:0 auto;
width:174px;
position:relative;
}
According to http://www.w3schools.com/css/css_positioning.asp
An absolute position element is positioned relative to the first
parent element that has a position other than static.

How to center this rotating image (CSS animation)

My CodePen: http://codepen.io/leongaban/pen/wJAip
The orange gear is 80x80 and so is the white # logo.
I added the blue background so you can see that for some reason the orange gear looks like it is spinning off center.
Here is the image lined up in photoshop:
html:
<div id="spinner">
<div id="logo">
<img src="http://leongaban.com/_codepen/whoat/loader-logo.png"/>
</div>
<div id="gear" class="spin">
<img src="http://leongaban.com/_codepen/whoat/loader-gear.png"/>
</div>
</div>
CSS:
div#spinner {
position: absolute;
width: 80px;
height: 80px;
top: 35%;
left: 50%;
margin-left: -40px;
background: blue;
}
div#logo {
position: absolute;
top: 0;
left: 0;
width: 80px;
height: 80px;
z-index: 3;
}
#logo img {
width: 100%;
height:100%;
}
div#gear {
position: absolute;
top: 0;
left: 0;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
pointer-events: none;
z-index: 2;
}
.spin {
-webkit-animation: rotation 4.5s linear infinite;
animation: rotation 4.5s linear infinite;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
}
Make the image in the #gear div block level.
#gear img{
display:block;
}
http://codepen.io/anon/pen/rjfbl
For whatever reason your gear element is getting a height of 84px. This will cause it to spin off-axis. As an experiment you might wish to try setting height and on #gear to something very small (e.g. 0px) and watching it; it will be as though it's rotating around a point at the top of its bounding box.
Set the width and height of your gear explicitly to 80x, or 100%, and it will work.
div#gear {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
pointer-events: none;
z-index: 2;
}
Codepen (yours with the two added lines, width and height): http://codepen.io/anon/pen/LuBvI

CSS3 Translate across an Arc

Is it at all possible with current CSS3 to translate an object (specifically a DIV) along an arc or curve? Here's an image to help illustrate.
You can use nested elements and make the wrapper and inner element rotate in opposite directions so that the rotation of the inner element compensates for the rotation of the wrapper.
If you don't need to keep the nested element horizontal, you can omit the inner rotation.
Here is a Dabblet. Stack Snippet:
/* Arc movement */
.wrapper {
width: 500px;
margin: 300px 0 0;
transition: all 1s;
transform-origin: 50% 50%;
}
.inner {
display: inline-block;
padding: 1em;
transition: transform 1s;
background: lime;
}
html:hover .wrapper {
transform: rotate(180deg);
}
html:hover .inner {
transform: rotate(-180deg);
}
<div class="wrapper">
<div class="inner">Hover me</div>
</div>
Also, Lea Verou wrote an article on this issue with a way that use only one element: http://lea.verou.me/2012/02/moving-an-element-along-a-circle/
Yes, that animation can be created using the transform-origin CSS3 property to set the rotation point in the far right so it moves like that.
Check it out: http://jsfiddle.net/Q9nGn/4/ (put your mouse over)
#c {
border: 1px solid black;
height: 400px;
}
#c:hover #m {
-webkit-transform: rotate(180deg);
-webkit-transition: all 1s ease-in-out;
-moz-transform: rotate(180deg);
-moz-transition: all 1s ease-in-out;
-o-transform: rotate(180deg);
-o-transition: all 1s ease-in-out;
-ms-transform: rotate(180deg);
-ms-transition: all 1s ease-in-out;
transform: rotate(180deg);
transition: all 1s ease-in-out;
}
#m {
width: 60px;
height: 60px;
position: absolute;
background: green;
border-radius: 30px;
top: 270px;
left: 20px;
-webkit-transform-origin:300px 30px;
-moz-transform-origin:300px 30px;
-o-transform-origin:300px 30px;
-ms-transform-origin:300px 30px;
transform-origin:300px 30px;
}
<div id="c">
<div id="m"></div>
</div>
An alternative to moving the transform origin, is to use a double nested element where an x-transform is applied to the outer container, and a y-transform with an appropriate easing curve is applied to the inner container.

Resources