Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divs with transparent text in CSS?

Tags:

html

css

masking

I’ve been asked to create a CSS (non-HTML5) based site that has a filled div with a cutout that shows an image underneath it.

Text Cutout Example

There are additional overlays and other images which makes using static images a pain. Plus, I suspect that I am going to need to be able to scale the background as the browser window changes size.

I realize that I can create an image of the GROW text and simply place it on top of the background image, but I would rather see if this effect can be accomplished “for real.”

This needs to work in IE8, 9, and FF 4. I can fallback to another effect for older browsers.

Any suggestions?

like image 944
rboarman Avatar asked Sep 16 '11 17:09

rboarman


People also ask

How do I make text transparent in CSS?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).

How do I make a div transparent but not the text?

The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.

Is there a transparent color in CSS?

The CSS color name transparent creates a completely transparent color. Using rgba or hsla color functions, that allow you to add the alpha channel (opacity) to the rgb and hsl functions. Their alpha values range from 0 - 1.

How do I make a div semi transparent?

To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.


2 Answers

That affect can be achieved using CSS 3 image masking. However, at the moment, only webkit supports the property. I would implement something like this, then use a fallback for other browsers until everybody catches up to speed.

As a side note:You can also increase the CSS adoption be using ChromeFrame, or something similar

An Example from that link:

SVG images can be used as masks. For example, a partially transparent circle can be applied as a mask like so:

<img src="kate.png" style="-webkit-mask-image: url(circle.svg)">

enter image description here

like image 79
Michael Jasper Avatar answered Sep 30 '22 17:09

Michael Jasper


I ended up using two images without any holes or transparency. It's a hack but works in all browsers.

like image 33
rboarman Avatar answered Sep 30 '22 16:09

rboarman