Category Archives: CSS

How-to for CSS

CSS3 Background Gradients

Using CSS for Gradients in Backgrounds

CSS logo

Gradients may be used in backgrounds via CSS. This is not available by CSS in all browsers, but, the feature is coming along. Even browsers that support gradients may have some holes in their functionality. This feature is defined in CSS3, use it and include fallback handling. Though the CSS3 version is not supported by all new browsers, it will be available soon. It has been available for webkit, opera, mos, and ms for some time, at least to some level. The following explains how the gradient can be used reasonably reliable across browsers. While the oldest Safari and Chrome syntax is shown in the cross browser samples, they are very different format from the current CSS3 syntax. That will be used, but, not discussed here. Meanwhile the new Mozilla, and the more recent webkit, mos and ms are very similar in format to the CSS3 syntax, and will be discussed below.

Plan for the following format in the future:

linear-gradient (angleOrlocation, stop1 [%], stop2 [%], [stop3 [%], […]]])

  • angleOrlocation – This indicates the location/direction that the gradient will go. The value may be:

    • Defined in degrees, such as 30degree, or 190deg
    • Listed as {top, bottom, left, right, top left, top right, bottom left, bottom right, circle}, indicating where the gradient starts. Top would result in vertical gradient from top to bottom. Left would result in horizontal running left to right
  • stop1 x% – the color to start gradient and an optional percent, identifying where the stop is located, effecting the width of the transition band.
  • stop2 x% – the color to blend to from stop1 and an optional percent, identifying where the stop is located, effecting the width of the transition band
  • stop3 x% – the color to blend to from stop2 and an optional percent, identifying where the stop is located, effecting the width of the transition band
  • stop x% …. as many color and optional percent, identifying where the stop is located, effecting the width of the transition band
  • stopN – the color to blend to from the previous stop.

Note: In the previous discussion, I refer to the positioning of the color by %. Actually, the value can be given in % or other measuring method, such as; px, rem, em, …

radial-gradient([% %,] [type,] [size,] stop1 [%], stop2 [%], [stop3 [%], […]]])

  • [% %] – this is the location of the center of the shape, such as 80% 20%. If this field is not present, the shape is centered in the DIV.

  • type – identify if the shape will be {circle, ellipse }. If this field is not present, ellipse is used
  • size – the size is specified relative to { closest-side, farthest-side, closest-corner, farthest-corner, contain, cover }
  • stop1 x% – the color to start gradient and an optional percent, identifying where the stop is located, effecting the width of the transition band
  • stop2 x% – the color to blend to from stop1 and an optional percent, identifying where the stop is located, effecting the width of the transition band
  • stop3 x% – the color to blend to from stop2 and an optional percent, identifying where the stop is located, effecting the width of the transition band
  • stop x% …. as many color and optional percent, identifying where the stop is located, effecting the width of the transition band
  • stopN – the color to blend to from the previous stop.

Note: In the previous discussion, I refer to the positioning of the color and center by %. Actually, the value can be given in % or other measuring method, such as; px, rem, em, …

Using CSS to create a Horizontal Gradient Background on a DIV

Using CSS to Create a Vertical Gradient on a DIV

Using CSS to Include Multiple Band Gradients on a DIV

Using CSS to Create an Even Stop Gradient on a DIV

If you would like an even stop gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.

Using CSS to Create an arbitrary Stop Gradient on a DIV

If you would like an arbitrary stop gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.

Notice the use of 5% and 95% to affect the location at which the color band is to start, and therefore affects the width of the transition bands.

Using CSS to Create a Diagonal Gradient on a DIV

If you would like a diagonal gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.

Notice: To go from top left to bottom right, the standard requires the specification of the end location, bottom right. Safari (webkit) reverses the logic of the location to specify in the first parameter. Webkit expects the use of the begin point of the diagonal. If you want to go from top left to bottom right, specify top left.

Using CSS to Create an Angled Gradient on a DIV

If you would like a gradient at a specific angle on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.

Using CSS to Create a Radial Gradient on a DIV

Notice: for circular gradients, the first parameter is replace with the value circle. You may use the percent on the color bands to position from the center of the circle.

Using CSS to Create a Positioned Radial Gradient on a DIV

If you would like a positioned radial gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.

How can I use CSS:before to add new line

CSS logoHow can I use CSS:before to add newline before an element???

That is the question that I researched today. My answer was semi-satisfying. I found that you can, and can’t do it … kinda.

What does that mean? Well, the intuitively obvious ways don’t work. The CSS method I did find will work on all browsers except the wonderful IE browser. What else in new! Love you IE …

In my situation, I wanted to customize where a link (<a>) was sitting. It was embedded in generated text I couldn’t touch. I wanted the link on the next line to highlight its existence.

I tried several things that didn’t work and wasn’t surprised by the results:

  • does not work, not a surprise.
  • doesn’t work, the content is processed as text, not as a tag.
  • failed as badly as the others … not a surprise.

What surprised me was the following works, on browsers other than IE:

There is no CSS solution, but, there is a jQuery solution. Try jQuery:

  • $(“<br/>”).insertbefore(“a”)

CSS Elliptical Corners

Create Elliptical Corners on a DIV

CSS logoIf you would like to create elliptical corners on a div, you can accomplish this with CSS3. Most new browsers will recognize elliptical corners, available with CSS3. However, browsers not recognizing CSS3 may appreciate -webkit variations (the -mos-border-radius does not support elliptical corners).

In each case, there are 2 parameter to the border radius declaration. That is:

  • param 1: The horizontal radius.
  • param 2: the vertical radius.

Create Selected Elliptical Corners

If you would like to create elliptical corners on selected corners, there is an option to handle this situation. This is available in CSS3, and special case options for old -webkit browsers.

The parameters are the same as the standard border radius, but affects only the selected corner.”

CSS Rounded Corners

Create a Rounded Corner on a DIV

CSS logoIf you would like to create rounded corners on a div, account for old and new browsers. Most new browsers will recognize rounded corners, available with CSS3. However, browsers not recognizing CSS3 may appreciate -mos, -webkit and -khtml variations.

In each case, there is 1 parameter to the border radius declaration. That is:

  • param 1: The corner radius.

Create Selected Rounded Corners

If you would like to create rounded corners on selected corners, there is an option to handle this situation. This is available in CSS3, and special case options for -moz and -webkit browsers.

The parameters are the same as the standard border radius, but affects only the selected corner.”

CSS Box Shadow

Create a Drop Shadow

CSS logoIf you would like to create drop shadows, account for old and new browsers. Most new browsers will recognize box-shadow, available with CSS3. However, browsers not recognizing CSS3 may appreciate -mos and webkit variations.

In each case, there are 4 parameters to the shadow declaration. These are:

  • param 1: horizontal offset of shadow.
  • param 2: vertical offset of shadow.
  • param 3: blur of shadow. (0 = no blur)
  • param 4: spread of shadow. (0 = shadow is same size as blur)

Create an Inner Shadow

If you would like to create a 3D curve effect on the edge of a box, there is an option in the box shadow. This is available in CSS3, and special case options for moz and webkit browsers.

The parameters are the same as the standard box-shadow, with the addition of a clarifying parameter “inset.”