Transition-delay not working in Chrome and Safari - css

EDIT
I've got it working now, but I'm still not to sure how what I did fixed it. If anyone understands what was happening I'd love to hear about it.
I'm making an animated menu icon and it's is working great...except for the middle bar's transition. It's supposed to disappear using a transition-delay after the top and bottom bars come together during the first animation, and appear after the top and bottom ones meet again for the second one (one third of the way through in both instances). There is no animation on the middle bar, only a transition on the background-color property. I've tried it with both the shorthand transition and with the explicit transition-delay properties. Both give the exact same results. The whole process works great in IE and Firefox, but fails in Chrome and Safari, which makes me think it's a possible webkit issue.
I'm only going to post the relevant code here (since there's almost two hundred lines for the whole thing). The rest is available at this codepen. If you think I should add more code then let me know and I will add more.
CSS:
#menu label span.icon,
#menu.lightbox label span.icon {
height: 5em;
width: 5em;
display: block;
background-color: rgba(255, 255, 255, 1);
background-clip: content-box;
padding: 2em 0;
transition: background-color 0s 1.66s;
}
#menu input[type=checkbox]:checked ~ label span.icon {
background: rgba(255, 255, 255, 0);
background-clip: content-box;
}
HTML:
<form id="menu" name="dateChooser">
<input id="toggle" type="checkbox">
<label for="toggle" onclick="addLightBox(this)"><span class="icon"></span></label>
<fieldset>
</fieldset>
</form>
What really baffles me is that I'm using transition-delay elsewhere and it's working just fine. I use it on the <fieldset> in order to create the lightbox effect. Just in case here's that code too:
fieldset {
background: rgba(0, 0, 0, 0);
transition: background 5s, width 0s 5s, height 0s 5s;
}
#menu.lightbox input[type=checkbox]:checked ~ fieldset {
background-color: rgba(0, 0, 0, .6);
transition: background 5s;
}
Any ideas what I'm doing wrong?
Just a bit more info. I'm using the checkbox hack to initiate the animations/transitions, pseudo elements for the top and bottom bars, and a little bit of javascript to keep the animations from running on load. But all of those seem to be working just fine. I'm also using autoprefixer in codepen, so I'm pretty sure it's not a prefix issue.
Here some gifs showing the correct animation and the faulty one.
Works properly:
No delay for middle bar:

After removing each group of css rules one by one, I finally found the culprit. It turns out that the code causing the issue never made it onto stackoverflow, but was in the codepen. Here's the offending bit of code:
CSS:
#menu input[type=checkbox]:checked ~ label {
margin: 0;
height: 100vh;
width: 100vw;
display: block;
background: rgba(0, 0, 0, 0);
position: relative;
z-index: 99;
top: 0;
left: 0;
cursor: default;
}
HTML:
<form id="menu" name="dateChooser">
<input id="toggle" type="checkbox">
<label for="toggle" onclick="addLightBox(this)"><span class="icon"></span></label>
<fieldset>
</fieldset>
</form>
The issue isn't with span.icon, but came about because it's parent was changing whenever the checkbox was toggled. Label's changes were immediate, so I'm assuming that they forced span.icon to change quickly as well. I'm really not sure why Chrome and Safari had an issue with this, when Firefox and IE11 didn't (I got curious and downloaded Opera as well. It failed just like Chrome did).
The fix is fairly simple. Just make sure that label is set to something that won't disrupt the transition (meaning I fiddle around until I got it working). I'd love for someone to help me understand what was happening and why it's fixed now, but I'm mostly just glad it's working.
Here's the added CSS rule that fixed it:
#menu label {
margin: 0;
display: block;
}
Such a tiny fix.
Here's a demo of the working code (sped up so it's not so painfully slow).

Related

Firefox transform scale image bug. Image flashes a small version of itself when using hover transform transition

While trying to fix one bug I've come across another, pretty sure it was when my version of Firefox updated today. I'm trying to scale an image slightly on hover for a zoom effect.
I was having trouble in Firefox with the image shifting / wiggling after using transform: scale/scale3d. Something to do with half pixels I assume. I've seen this issue being discussed before - ie. here and here, but none of the solutions mentioned anywhere worked for me. In the end I managed to 'fix' it by tweaking either the scale ratio or the actual size of the image file.
But then a stranger bug started happening in Firefox (v.45.0.1) , where the image flashes a small version of itself when you first hover over it. This only happens once, but can be recreated again by doing a normal page refresh. Happens with other transforms as well as scale, eg. rotate(). Is there anything I can do about this other than submit a bug report & wait for Firefox to fix? And has anyone else noticed this / does it happen in older Firefoxes?
Also if anyone has a better fix for the image wiggle issue, that would be amazing :)
I've set up a Codepen example here trying different fixes for the wiggle issue, but the Firefox bug can currently be seen on all the icons.
.hoverPop {
-webkit-transition: all 0.5s cubic-bezier(0.42, 0, 0.42, 1);
-webkit-transition: all 0.5s cubic-bezier(0.42, 0, 0.42, 1.75);
transition: all 0.5s cubic-bezier(0.42, 0, 0.42, 1.75);
}
.hoverPop:hover {
-webkit-transform: scale3d(1.2, 1.2, 1.2);
transform: scale3d(1.2, 1.2, 1.2);
}
img {
border: 0;
vertical-align: middle;
max-width: 100%;
}
.imgwrap {
width: 65px;
margin: 0 auto 12px auto;
height: 65px;
}
<div class="imgwrap">
<img class="hoverPop" src="http://i1175.photobucket.com/albums/r631/Bananafarma/testIcon_zpsfrhmw5qd.png" alt="test">
</div>
Cheers :)
I solved this by adding following. This fixes FF v45.0.1 bug which displayed the smaller image on hover with transition for me.
img {
image-rendering: optimizeQuality;
}

mix-blend-mode is broken by 3D transformations on page

I was fiddling with the mix-blend-mode property. Everything works fine until I add something like transform: perspective(100px) or any other 3d transformation anywhere on the page, then it breaks completely. The transformation is applied but the blend mode is gone.
I tested on chrome and firefox and on linux and windows and it's the same everywhere, however on a different computer it worked fine (I don't remember what version of chrome it had and was running ubuntu).
Is that something that can be fixed with CSS or is it possibly just a hardware / GPU drivers issue?
I put background-blend-mode in tags because the mix-blend-mode tag doesn't exist yet, however this property strangely works completely fine and isn't broken by transformations.
Here is a codepen of what I am trying to achieve:
http://codepen.io/vnenkpet/pen/avWvRg
The lightning shouldn't have it's black background flashing with it but should be blended smoothly with the page background.
EDIT:
I have just found out that it actually DOES work in Firefox. Is this therefore a chrome bug? 3D Transforms shouldn't break blend mode as far as I know...
I was having a similar issue, except that applying a mix-blend-mode (multiply) higher on the page broke my transforms lower on the page (using Chrome on Mac). I was able to fix this by applying a z-index rule to the mix-blend-mode div (don't forget to set a position, too).
I'm not entirely sure if this is a bug or if it is expected behavior due to the properties of stacking contexts, though.
You can try to also apply a null transform (3D layer promotion) to the element that has mix-blend-mode specified:
.content {
mix-blend-mode: difference;
transform: translate3d(0, 0, 0);
}
This way, Chrome can successfully blend the two 3D layers together, instead of failing to blend a 3D layer and a 2D layer.
Here's a snippet demonstrating the problem and the solution:
function change(event) {
var content = document.querySelector(".content")
content.className = event.target.checked ? "content content-with-transform" : "content"
}
.parent {
text-align: center;
padding: 2rem;
font-size: 5rem;
font-weight: 700;
}
.fixed {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 4rem;
background-color: #AB1795;
transform: translate3d(0, 0, 0);
z-index: -1;
}
.content {
mix-blend-mode: difference;
background-color: #167CFB;
}
.content-with-transform {
transform: translate3d(0, 0, 0);
}
<div class="parent">
<div class="fixed"></div>
<div class="content">Content</div>
</div>
<label><input type="checkbox" onchange="change(event)"/> Also transform other element</label>
(I stumbled onto this problem when using will-change: transform, not an actual transform, but the solution is the same.)
I realise this is a pretty old thread, but I was having the same issue with janky transforms in Webkit/Blink using the Masonry Isotope plugin with a mix-blend-mode overlay on the grid sections until I added the following CSS to the element that was being transformed. i.e. the masonry grid element
I'm answering this in case it helps someone in future.
[your-selector-goes-here] {
perspective:1000px;
-webkit-backface-visibility: visible;
backface-visibility: visible;
}

Is the 'frosted glass' effect implementable with CSS only at this time?

The frosted glass effect (where an overlay both blurs and tints what is below it) is a common UI element in iOS.
Is there currently anyway to implement that with CSS? There are a lot of questions pertaining to this, but they are limited in what they can do. They typically are limited to putting an overlay over an image--rather than a completely rendered UI.
So, to be clear, I'm not looking for a way to blur an image by itself, but a way to blur the UI below an element. So say I have an HTML form with HTML buttons and HTML text, and I want to place a div above them all so that whatever is below looks blurred. And then I can perhaps scroll what is below and as elements come in and out of the overlay, they are blurred only while under the div.
My understanding is that the answer to this is no, this is not currently possible with CSS but I'm also a bit rusty on the new bells and whistles...
What you are looking for is backdrop-filter, which has been in webkit since August 2015 (see post). It was shipped in Safari 9 (September 30, 2015, part of OS X El Capitan) and works in Chrome today by enabling the Experimental Web Platform features [...] flag.
With backdrop-filter, getting the 'live blur' is as easy as adding backdrop-filter: blur(10px) to a given element.
Demo here.
It's probably going to be a while until it becomes mainstream though, but it's going to enable us to do so much more than the frosted glass effect (i.e. night mode, read more here).
The good news is that tons of people are excited about it, so let's hope we don't have to wait long. If curios, here's the spec for it.
If you want to track progress on this feature, check out:
Mozilla bug
Chrome bug & Chrome status
Microsoft bug
As far as I know, this is achievable only in Firefox.
The key is background-image: element. One of the properties that would prove most useful , in my opinion, of the ones in the "may be some day" list
Demo working only in FF .. Notice that frost is not a child or a parent of test
img {
margin-top: 5px;
margin-left: 40px;
animation: move 1s infinite;
}
#frost {
border: solid 1px blue;
width: 250px;
height: 250px;
position: absolute;
left: 50px;
top: 120px;
background-color: white;
background-image: linear-gradient(rgba(0,0,100,0.2), rgba(0,0,100,0.2)), -moz-element(#test);
background-position: -45px -112px;
background-repeat: repeat, no-repeat;
filter: blur(4px);
opacity: 1;
}
button:hover {
background-color: red;
}
#keyframes move {
from {transform: translate(0px);}
to {transform: translate(40px);}
}
<div id="test">
<button>BUTTON</button>
<img src="http://placekitten.com/1000/750" width="300px" height="300px"/>
</div>
<div id="frost"></div>

CSS - Apply Opacity to Element but NOT To Text Within The Element

I have created a menu block element which I have applied an opacity of 0.4/40 to.
The problem I have is that the opacity affects the text within the menu block and I am looking to have the opacity ONLY applied to the menu block, but not the text.
Hopefully I have just missed something silly. Here is my code:
#menuLeft{
background-color: #33AAEE;
float: left;
width: 20%;
clear: both;
opacity:0.4;
filter: alpha(opacity = 40);
}
I am looking for a way to keep the text colour the same/set the opacity to exclude the text.
Thank you.
This is a very, very, very popular problem. Try using rgba():
//Your opacity is the latest value here for Firefox 3+, Safari 3+, Opera 10.10+
background-color: rgba(51, 170, 238, 0.6);
//Your opacity is the first pair here (in HEX!) for IE6+
progid:DXImageTransform.Microsoft.gradient(startColorstr=#9A33AAEE,endColorstr=#9A33AAEE);
zoom: 1;
float: left;
width: 20%;
clear: both;
/*opacity:0.4;
filter: alpha(opacity = 40);*/
You also can use http://css3please.com/ to easily convert from HEX to RGB and back.
You could also put a transparent picture as the background.
The text should display normally.
http://css-tricks.com/snippets/css/transparent-background-images/

Changing opacity for div in div - is this possible? How?

I got from web designer layout, which contains (probe):
<div id="subMenuRow">
<div id="subMenuRowHTML">
Link
</div>
</div>
and respectively css for it:
#subMenuRow{
width: 900px;
height: 40px;
background: #000000;
float: left;
clear: both;
filter:alpha(opacity=30);
-moz-opacity:0.3;
-khtml-opacity: 0.3;
opacity: 0.3;
}
Opacity is used to make transparent bar for html menu. The problem is, that every text including links contains transparency as well, which is very unnecessary. How to avoid opacity for subMenuRowHTML?
First you don't need to use -moz-opacity and -khtml-opacity anymore. They are very very old.
There is no solution fully supported today. CSS3 RGBA solves this in modern browsers but if you need to support old browsers you will need to use semi transparent png:
#subMenuRow { background: url(semi-trans.png); }
IE6 will degrade gracefully with this:
* html #subMenuRow { background: url(full-opacity.gif); }
There are also easy options for png transparency on IE6. It's up to you.
If you have many instances of opacity on your code and don't want to mess up your code with * html everywhere you can use conditional comments.
use a semi transparent .png as a background image:
css:
background: transparent url(/url/image.png) top left repeat;
Add:
#subMenuRowHTML {
filter:none;
-moz-opacity:1;
-khtml-opacity:1;
opacity:1;
}

Resources