In one of my other questions, the solution to fixing a rendering issue was by using the value rgba(255, 255, 255, 255)
instead of transparent.
We tested using rgba(0, 0, 0, 0)
and this still corrected the problem, meaning that it is the definition of transparent
that causes the error. However, looking at the W3C CSS3 Specification (and MDN reference) for transparent
reveals that rgba(0, 0, 0, 0)
and transparent
should be equal:
transparent
Fully transparent. This keyword can be considered a shorthand for transparent black, rgba(0,0,0,0), which is its computed value.
So what gives? Why can two, seemingly, identical values produce different results? I've looked into the formatting of RGBA, and looked for similar questions (to no avail). Every question/answer that mentions the conversion from transparent
to rgba(0,0,0,0)
always has the words 'should' or 'according' in. (For example here). What is the actual difference, and why does it change the output so much?
N.B: This occurs in most, if not all, versions of Internet Explorer. We also know that it occurs in some versions of Firefox. However Chrome and Safari do not display this behaviour, leading us to believe that there is some sort of patch for this in -webkit
.
To be able to submit this as a bug we need to reproduce the problem using the minimal amount of code. So, transferred from my other question, here is a comparison of using transparent
vs rgba(0,0,0,0)
, and what happens when we use both.
Transparent
@keyframes spin{
0% {transform:rotateZ(0deg);}
50% {transform:rotateZ(360deg);border-radius:60%;}
100%{transform:rotateZ(720deg);}
}
.spinme{
display:inline-block;
position:relative;
left:0;
top:0;
margin:0.2rem;
width:0.8rem;
height:0.8rem;
border:0.2rem solid black;
border-radius:0%;
outline: 1px solid transparent;
transform:rotateZ(0deg);
animation: spin infinite 4s;
}
<div class="spinme"></div>
RGBA(0,0,0,0)
@keyframes spin{
0% {transform:rotateZ(0deg);}
50% {transform:rotateZ(360deg);border-radius:60%;}
100%{transform:rotateZ(720deg);}
}
.spinme{
display:inline-block;
position:relative;
left:0;
top:0;
margin:0.2rem;
width:0.8rem;
height:0.8rem;
border:0.2rem solid black;
border-radius:0%;
outline: 1px solid rgba(0,0,0,0);
transform:rotateZ(0deg);
animation: spin infinite 4s;
}
<div class="spinme"></div>
Both
As pointed out by @andyb, there is strange behaviour when using both on separate elements. You would expect only one to wobble, however they both do. As demonstrated:
@keyframes spin{
0% {transform:rotateZ(0deg);}
50% {transform:rotateZ(360deg);border-radius:60%;}
100%{transform:rotateZ(720deg);}
}
.spinme{
display:inline-block;
position:relative;
left:0;
top:0;
margin:0.2rem;
width:0.8rem;
height:0.8rem;
border:0.2rem solid black;
border-radius:0%;
outline: 1px solid rgba(0,0,0,0);
transform:rotateZ(0deg);
animation: spin infinite 4s;
}
.spinme:nth-of-type(2){
outline: 1px solid transparent;
}
<div class="spinme"></div>
<div class="spinme"></div>
For those who can't test this in Internet Explorer, here is an animated .gif of the problem:
This is with transparent
on the left, rgba
in the middle, and both on the right.
As pointed out by @Abhitalks I misread the reference, however I will leave the below in the question to show that we've already considered this possibility, or in case something was missed/overlooked.
Thanks to @juan-c-v's answer I decided to attempt to create a test to find the computed value for transparent
in each browser, and came up with the following:
$('p').text($('p').css("background-color"));
p{background-color:transparent;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p></p>
If you are viewing this in Chrome/Safari, then you will most likely see (comment if you don't) rgba(0,0,0,0)
. However in IE, you will probably see transparent
still. I was reading the MSDN reference and found that:
The transparent keyword is not supported.
Which explains why the browsers display different results. However it doesn't explain anywhere what their version of transparent
is actually defined as. I looked through the old CSS1 and CSS2 w3c specs and couldn't find an old definition. What does transparent
mean?