Problem
I don’t use CSS3. As a result, I’m unable to use the opacity or filter attributes. How can I make a div’s background-color translucent without utilising these attributes? It should look similar to the text box in this link. Here the text box background color is transparent. I want to make the same, but without using the above mentioned attributes.
Asked by Mistu4u
Solution #1
The issue with opacity is that it can alter the content, which is something you don’t want to happen.
If all you want is for your element to be transparent, it’s as simple as:
background-color: transparent;
If you want it to be colored, though, you can use:
background-color: rgba(255, 0, 0, 0.4);
Alternatively, specify a backdrop picture (1px by 1px) with the appropriate alpha. (You can accomplish this with Gimp, Paint.Net, or any other image editing software.) Simply make a new image, erase the background, and fill it with a semi-transparent color before saving it as a png.)
As René suggested, the best approach is to combine the two, with the rgba picture coming first and the 1px by 1px image serving as a fallback if the browser doesn’t support alpha:
background: url('img/red_transparent_background.png');
background: rgba(255, 0, 0, 0.4);
Visit http://www.w3schools.com/cssref/css colors legal.asp for further information.
My JSFiddle as an example
Answered by Jerska
Solution #2
Translucency or transparency is achieved through opacity. Here’s an example of Fiddle.
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Netscape */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */
This is not a list of CSS3 properties.
See http://css-tricks.com/snippets/css/cross-browser-opacity/
Answered by Paul Fleming
Solution #3
The background-color setting is set to transparent by default.
http://www.w3schools.com/cssref/pr_background-color.asp
Answered by user1147171
Solution #4
From https://developer.mozilla.org/en-US/docs/Web/CSS/background-color
To set background color:
/* Hexadecimal value with color and 100% transparency*/
background-color: #11ffee00; /* Fully transparent */
/* Special keyword values */
background-color: transparent;
/* HSL value with color and 100% transparency*/
background-color: hsla(50, 33%, 25%, 1.00); /* 100% transparent */
/* RGB value with color and 100% transparency*/
background-color: rgba(117, 190, 218, 1.0); /* 100% transparent */
Answered by randominstanceOfLivingThing
Solution #5
It may be a little late to the party, but someone, like myself, will inevitably come across this post. I got the answer I was looking for and decided to share my thoughts on it. How to layer.PNGs with transparency is demonstrated in the JSfiddle below. The solution was Jerska’s mention of the transparency attribute for the div’s CSS: http://jsfiddle.net/jyef3fqr/
HTML:
<button id="toggle-box">toggle</button>
<div id="box" style="display:none;" ><img src="x"></div>
<button id="toggle-box2">toggle</button>
<div id="box2" style="display:none;"><img src="xx"></div>
<button id="toggle-box3">toggle</button>
<div id="box3" style="display:none;" ><img src="xxx"></div>
CSS:
#box {
background-color: #ffffff;
height:400px;
width: 1200px;
position: absolute;
top:30px;
z-index:1;
}
#box2 {
background-color: #ffffff;
height:400px;
width: 1200px;
position: absolute;
top:30px;
z-index:2;
background-color : transparent;
}
#box3 {
background-color: #ffffff;
height:400px;
width: 1200px;
position: absolute;
top:30px;
z-index:2;
background-color : transparent;
}
body {background-color:#c0c0c0; }
JS:
$('#toggle-box').click().toggle(function() {
$('#box').animate({ width: 'show' });
}, function() {
$('#box').animate({ width: 'hide' });
});
$('#toggle-box2').click().toggle(function() {
$('#box2').animate({ width: 'show' });
}, function() {
$('#box2').animate({ width: 'hide' });
});
$('#toggle-box3').click().toggle(function() {
$('#box3').animate({ width: 'show' });
}, function() {
$('#box3').animate({ width: 'hide' });
});
And here’s where I got the idea: http://jsfiddle.net/5g1zwLe3/ Paint.net was also used to make the translucent PNGs, or PNGs with transparent backgrounds.
Answered by user3241848
Post is based on https://stackoverflow.com/questions/11807286/how-to-make-div-background-color-transparent-in-css