How can I easily convert a hex color value to a transparent one in CSS?
For example, I have the color #ECC040
. How can I add opacity to it by adding a suffix #ECC040xx
where xx
is the alpha value.
This question has been asked before long ago and similar here but I'm asking again since I can see that if I add an alpha value of 33
or 66
(#ECC04033
or #ECC04066
) then the hex color becomes transparent accordingly in CSS but most of the other values don't seem to work.
According to this source the #rrggbbaa notation is supported by most of the modern browsers.
Update: I managed to solve my problem. It was fairly simple in the end.
.background{
background-color:red;
}
.container1{
height: 30px;
width: 100%;
background-color: #ECC0401A; /*Opacity 10%*/
}
.container2{
height: 30px;
width: 100%;
background-color: #ECC04033; /*Opacity 20%*/
}
.container3{
height: 30px;
width: 100%;
background-color: #ECC04066; /*Opacity 40%*/
}
.container4{
height: 30px;
width: 100%;
background-color: #ECC04099; /*Opacity 60%*/
}
.container4{
height: 30px;
width: 100%;
background-color: #ECC04099; /*Opacity 60%*/
}
.container5{
height: 30px;
width: 100%;
background-color: #ECC040CC; /*Opacity 80%*/
}
.container6{
height: 30px;
width: 100%;
background-color: #ECC040FF; /*Opacity 100%*/
}
<div class="background">
<div class="container1"></div>
<div class="container2"></div>
<div class="container3"></div>
<div class="container4"></div>
<div class="container5"></div>
<div class="container6"></div>
<div class="container7"></div>
</div>