In the following code, I want to set the opacity only for the background color of the li (not the text). However, it is important NOT to use the rgba for the background.
I'm trying following, but it sets the opacity for the link text as well.
HTML:
<ul>
<li>Hello World</li>
</ul>
CSS:
body{
background: red;
}
ul{
margin: 100px;
}
li{
padding: 10px;
background: #000000;
opacity: 0.1;
}
a{
color: #fff;
font-weight: 700;
opacity: 1;
}
JSFiddle:
http://jsfiddle.net/2uJhL/
Old question, but new answer! :)
Fortunately, the new versions of Chrome and Firefox support 8 digit colors. That's really cool, especially when you're developing and testing software.
For example:
background-color: #ff0000; (Red)
If you want a opacity of 0.5, you can do this:
background-color: #ff00007f (The 7F is half of FF)
So, from now on you won't need to use the rgba() if you don't want or have the entire div fade away - because of the opacity: 0.x - when you only want the background color a little bit transparent.
But remember that not all browsers support that. So, please test the snippet below on Chrome or Firefox, ok?
Isn't that cool???
<div style="background-color: #ff00003f;">better than [opacity: 0.25]</div>
<div style="background-color: #ff00007f;">better than [opacity: 0.50]</div>
<div style="background-color: #ff0000bf;">better than [opacity: 0.75]</div>
<div style="background-color: #ff0000ff;">better than [opacity: 1.00]</div>
Source: https://css-tricks.com/8-digit-hex-codes/
You can set a PNG or GIF image as background, i.e:
li {
background-image: url('path/to/your/image.png');
}
The opacity is applied at the content and all children. You can't set a different opacity for the children.
However if you don't want to use rgba you can use a png with opacity that you want.
And setting a png to your li in the background is the best solution in this case
tl;dr Cmiiw, you can't setting the background opacity without RGBA
Let me try to give another solution.
This solution is not the real answer for the problem, but it may helps.
For me, you just need to convert the background color (hex value) to RGBA, using tools something like this https://cssgenerator.org/rgba-and-hex-color-generator.html.
Then, just use the RGBA value in your background color.
Related
I have a few photos and I want on hover I want to cover them with background: black; I want to cover the whole image with black for example. The hover effect just doesn't appear. I suspect the problem is in the CSS selectors.
Here is the fiddle: http://jsfiddle.net/20oomme4/3/
I tested your fiddle and it is working. I modified the colors and tested again - and it worked again. However, you images were broken links, so I could easily see the background color. My guess is that your images are opaque and, therefore, you cannot see the color that is BEHIND them.
Your best bet is to create two images - one with normal color and one with black color. Call the normal image "NormalImage.jpg" and call the black background one "NormalImage_black.jpg". Then, onhover, replace ".jpg" with "_black.jpg" - and on mouseout, replace "_black.jpg" with ".jpg". If you are having trouble doing this with css, try using Javacsript - and remember to load all images (but hide the backgorund ones) upon page_load, so that when someone hovers, the browser doens't have to load the image - it only needs to display it.
I'm unsure of what you want exactly. If you want a transparent background to cover the image.
jsfiddle
Other wise you would need to use transparent png's to change the white to black background on the image itself.
.img-responsive.products {
border: 1px solid black;
cursor: pointer;
}
figcaption {
position: absolute;
top: 0;
left: 0;
padding: 20px;
background: #2c3f52;
color: #ed4e6e;
}
figcaption {
height: 100%;
width: 100%;
opacity: 0;
color:#fff;
text-align: center;
backface-visibility: hidden;
transition: transform 0.3s, opacity 0.3s;
}
.col-sm-3:hover figcaption {
opacity: 0.4;
}
The hover effect is working as it is intended, the problem is the images are taking up the full area so you can't see any background effects. Try giving the images a padding:20px; to see the background changes. As mentioned above you will need to either create an image sprite or change the image to a transparent .png in order for the full background to change.
ex: http://jsfiddle.net/20oomme4/6/
Check this fiddle
This is the same CSS that you used, ie.
.img-responsive.products:hover {
background-color: black;
}
Only thing is that i've used a png image with no background. And as you can see in the fiddle your code works correctly.
So, As i mentioned in my comments, i would suggest you to use a png image without any background.
The background of a lot of websites is not actually white: it's more of a greyish color:
How do they do this? Is it just a picture they made or is there some CSS?
Short answer: Picture and CSS: both are possible.
Long answer:
To add a background image, you will have to do something like
body {
background-image: url('bgpic.png');
}
where bgpic.png is the image that you want to use as a background.
I believe using a background image for a simple background as this one will only increase your loading time, and in turn, frustrate your users. The CSS alternative is faster and easier, as you might have probably guessed from the other answers.
In CSS, you can style your background like this:
body {
background-color: #efefef;
}
Or, as someone pointed out, use the rgb equivalent:
body {
background-color: rgb(239, 239, 239);
}
And might I add that it is also possible to specify the transparency of the background. Say, you have a background picture, and you have a <div class="foo"> that could use a semi-transparent background; then you would do something like:
body {
background-image: url('bgpic.png');
}
.foo {
background-color: rgba(0, 0, 0, .5);
}
Notice that the last value given to rgba is the % transparency that you want. It is a value less than 1.
Here's a JSFIDDLE.
http://jsfiddle.net/ccnZt/
body {
background: rgb(248,248,248);
}
Just CSS.
body {
background: #f0f0f0;
}
Notice that if the website does not specify a background color, your browser will display a default color. Older browsers used grey colors, while new browsers use white.
They could have used either a picture image or CSS; either setting the background image with an image of that solid color or setting the background color with RBG colors through CSS.
body {
background-image: url('yourbgimage.jpg');
}
or
body {
background: rgb(244,244,244);
}
If you want to set your background to this color (or any other solid colors), it's better to go with CSS as it will load faster and improve the user experience!
I'm trying to make a wrapper at the back off all of my DIV's that will appear transparent (opacity: 0.6), but everything in front of that is appearing transparent too.
Any ideas how to fix this?
You can find the example here: http://testing.squaretise.com/ (I have given the wrapper (#wrap) a red border so you can interpret easier)
Use instead of:
opacity: 0.6;
this:
background: rgba(255, 255, 255, 0.6);
The color is in RGB and the last digits are for the transparency level.
You'll need to position your transparent div absolutely.
http://www.w3.org/TR/css3-color/#transparency explains how the descendants pick up the transparency.
Opacity is inherited. If the parent is see through, so are the children.
A better way to do this is to remove opacity and set the background color to be transparent:
.foo {
background: rgba(0,0,0,.5);
}
You should use transparent background, instead of opacity.
Background-image is the best way if you want to support IE8. (CSS3 Colours: http://caniuse.com/#search=rgba)
Use data-uri for better performance.
You could even do it with opacity. Here's an example:
HTML
<div id="wrapper">
<div id="contentOrWhatever">
</div>
</div>
CSS
body {
z-index:0;
}
#wrapper {
z-index:1;
opacity:0.6;
}
#contentOrWhatever {
z-index:99;
opacity:1;
}
So #wrapper ist now transparent and is ALWAYS behind #contentOrWhatever.
Hope I could help you.
So I'm using this form from this site here
When I post the form in my website the entire form area is white background. Yet I keep looking through the code and I don't see anything specifying the color. Is there a way to make it so that it has an opacity of 0 or anything of the like? Thanks in advance.
Use this css rule:
#my_form
{
background-color: transparent;
}
Background color is the answer as previously posted by dotoree however as a side tip, use this CSS class to change the opacity of a div.
.transparent {
zoom: 1;
filter: alpha(opacity=50);
opacity: 0.5;
}
I would go with a rgba value for the background color.
background: rgba(255,255,255,0.5); - white with a 50% transparency.
Hi i am using CSS Opacity Property for a div tag and it works well but the problem is when I write some text or paste images on that div tag they also become fade. I just need div back color to be fade and not the div content. My code is ...
#fade div
{
opacity:0.1;
filter:alpha(opacity=10); /* For IE8 and earlier */
width:750px;
height:150px;
background-color:#FFFFFF;
}
#text in fade div
{
font-weight:bold;
color:#8A2BE2;
}
Thankyou !!!
It's much easier to use rgba() or a transparent PNG for the background.
rgba(0, 0, 0, .1);
rgba(0, 0, 0); //fallback
You can use rgba() property for this:
write like this:
#fade div
{
background-color: rgba(0,0,0,0.1);
width:750px;
height:150px;
background-color:#FFFFFF;
}
For IE you can use IE filter
background: transparent;-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#19000000,endColorstr=#19000000)"; /* IE8 */ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#19000000,endColorstr=#19000000); /* IE6 & 7 */ zoom: 1;
You can generate your filter from here http://kimili.com/journal/rgba-hsla-css-generator-for-internet-explorer/
Just use 1px semi transparent gif and repeat it by x and y. As far as I know it is the most easy way to set semi transparent background.
Ofcourse the opacity applies to the child elements as well.What you can do is to segragate your markup.
<div id='Div-With-Opacity-set'>
</div>
<div id='Child-Elements-for-the-above-div'>
</div>
Align your markup carefully such that the markup resembles what you want.
Why don't you reset the opacity then?
#text in fade div
{
font-weight:bold;
color:#8A2BE2;
opacity:1;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
Your best bet without CSS3 is probably to create a div and put another div positioned on top of it, but not nested inside of it. Opacity filters down to ALL elements inside of the element with the opacity set.
If you put a div immediately to the right, and then gave it a margin of -750px;, you could give it an opacity of 1, but the div behind it could have an opacity of 0.1, and this would work fine.
With CSS3 you could do this:
#fade
{
width:750px;
height:150px;
background-color: rgba(255,255,255,0.1);
}
and just the background would be 0.1 opacity. The text would still be 1.
What I personally do most often though, is I create a small .png with the transparent background that I want, and then I set that .png as the background of an element. In photoshop I could set the opacity of the white background to 0.1, then save a 50X50 square, and then I've got nearly perfect transparency (no IE6).
something like http://jsfiddle.net/PWM5f/ you need