Since the pseudo-element is a sort of child of the parent, you can change the opacity of it without affecting the text content. But what if we only wish to set the opacity on the background color whilst keeping the content (such as text and images) opaque? However, if you get creative, there are a ton of creative work-arounds you to make it seem like you’re changing the CSS background image’s opacity. Changing background color. In print design, opacity is sometimes referred to as transparency and may be adjusted for both graphic elements and text. How to change the opacity of an element's background without affecting the child elements or text content. …, Change the value of the opacity property in the CSS ccode to make sure that only the background image is affected. .block:hover {text-shadow: 0 0 3px #000;}. If the parent has an opacity of 0.5, the child has it too (in relation to the parent's stacking context). You can simply use rgba() instead (the last value being hte opacity) and it’ll only affect the background color, not anything else. The opacity property in CSS specifies how transparent an element is. But if we use only three last rules (without background-color: rgb(0, 0, 0);) - all just fine – Donotello Aug 26 '11 at 9:13 7 I tried this solution and it did not work in IE8 because IE8 correctly applies the background color. Both of the following methods have excellent browser support down to Internet Explorer 8. How to set a background opacity without affecting the text, You can use rgba to make only the background color transparent, e.g. If you're not using sass/scss then move the &:after out to its own, #flag-top:after{} - foo.scss Over the top of the photo I would like to place text inside a box that has white fill color set to 80% opacity. Here is a fully working example with inline image. I need to remove the text saying "A Innland", but the background isn't quite the same at all points - the further right you go, the lighter it becomes. On that second form, you use an otherwise unused color for the background where you want transparency. Change opacity of background colour, but not text [duplicate] I am using Photoshop CS6. ALL TECHNOLOGY ARTICLES FULL FORMS NEW; WEBINARS ERRORS & FIXES INTERVIEW FORUMS VIDEOS. Required fields are marked *. However, the opacity property may affect the inner element of the div also and make them transparent too. To make that pseudo-element the same size as the parent, you’ll have to absolutely position it and set its top, right, bottom, and left values to zero so it doesn’t collapse. This can be useful when you want to add a text to the container. Dresden beat me to it but I was also going to suggest using a pseudo element for the opacity fade on the image. Example: another thing you could do is have multiple images , and swap them on :hover. here are some options: it also changes the opacity in its child elements. I'm working on my boyfriend's profile layout on myspace. I want to make the tables have a black background at 50% opacity. So long as the second box isn’t a child of one of the text elements, then it won’t inherit the opacity. Answer: Use the CSS RGBA colors. Click Set Transparent Color, and then click the color in the picture or image that you want to make transparent. When I bring in some text overlays above this, I usually keyframe the opacity of the animated background down to 20% or lower. CSS Tutorial » CSS background image opacity without affecting child elements. There are instances when you think that would be great idea if you can able to change opacity of background color of div without affecting text, image & other web properties present inside same div of HTML & CSS. Your workaround it’s implementing a separated div/container to handle the background image with the opacity attribute applied at the same level as the item or container holding the text you are showing in your demo. The default background is light gray. Using a blending mode to change how colors interact among overlapping objects. Here is my code. I’ve added the font size to the .block class (I also tried it in the .block:hover class but that didn’t work either. Opacity refers to the amount of light that travels through an object. This is what I’ve got: I also tried this but it didn’t work at all: It works if I roll over the text but not if I roll over the div itself. I have the following code: