Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS 3 Gradient n pixels from bottom - Webkit/Safari

Is there a way to creat a gradient with a stop n pixels from the bottom edge of the element?

For example with Moz/Firefox it would look like:

-moz-linear-gradient(center bottom , #f00 2%, #d00 31px)

It should also be noted that this gradient has a companion gradient to do the same thing to the very top of the box. So really the css looks like this for FF and i need to reproduce for webkit:

background-image:
      -moz-linear-gradient(center top , rgba(255,0,0,0.75) 2%, rgba(255,0,0,0) 31px), 
      -moz-linear-gradient(center bottom , rgba(255,0,0,0.75) 2%, rgba(255,0,0,0) 31px);
like image 624
prodigitalson Avatar asked Jan 16 '11 20:01

prodigitalson


People also ask

Does Safari support linear gradient?

Safari supports two types of CSS gradients: linear and radial.

What is Webkit gradient in CSS?

First, -webkit-gradient uses a two-point syntax that lets you explicitly state where a linear gradient starts and ends. linear-gradient does away with this in favor of convenient box-filling behavior. If you really want the gradient to stop before the edges of the box, you can do so via color stop placement.

Can I use CSS linear gradient?

CSS Linear GradientsTo create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.

How do you add transparency to a gradient in CSS?

To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).


1 Answers

You can't do that with the current webkit syntax. Good news though! There will be a new -webkit-linear-gradient property (just announced on the webkit blog) that basically matches the -moz syntax and will allow you to do this. This syntax should become the definitive CSS3 syntax, so you'll be able to drop the -webkit and -moz entirely at some point. (The old -webkit-gradient property will continue to work indefinitely, but is not favored going forward.)

like image 169
Michael Mullany Avatar answered Sep 24 '22 19:09

Michael Mullany