Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transparent background image using "data:"

I've seen on some sites that you can include images in CSS using a "data" keyword:

.stuff {
  background: transparent url(data:image/gif;base64,SOMEWEIRDCODEHERE) repeat center top;
}

the weird code looks like a base64 ecoded string like:

R0lGODlhMwAxAIAAAAAAAP/// yH5BAAAAAAALAAAAAAzADEAAAK8jI+pBr0PowytzotTtbm/DTqQ6C3hGX ElcraA9jIr66ozVpM3nseUvYP1UEHF0FUUHkNJxhLZfEJNvol06tzwrgd LbXsFZYmSMPnHLB+zNJFbq15+SOf50+6rG7lKOjwV1ibGdhHYRVYVJ9Wn k2HWtLdIWMSH9lfyODZoZTb4xdnpxQSEF9oyOWIqp6gaI9pI1Qo7BijbF ZkoaAtEeiiLeKn72xM7vMZofJy8zJys2UxsCT3kO229LH1tXAAAOw==

look pretty cool :D

I was wondering how can I include a transparent 1x1 pixel GIF like this? Does anyone know the data code for such a image?

Is it a good idea to do this for small and very common images? Do all browsers support this?

like image 452
Alex Avatar asked Apr 07 '11 21:04

Alex


People also ask

How do I make background image transparent in CSS?

opacity is a CSS property that allows you to change the opaqueness of an element. By default, all elements have a value of 1 . By changing this value closer to 0 , the element will appear more and more transparent. A common use case is using an image as part of the background.

How do I make a background transparent in CSS but not 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.


1 Answers

this is a transparent GIF of one pixel

background-image: url( data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== );
like image 89
rushkeldon Avatar answered Oct 18 '22 22:10

rushkeldon