Nov 19

Optimized Css Text Gradient

Front-end web developers always want to find ways to optimize your HTML and CSS code. I saw a post on Cssglobe.com by Alen Grakalic about CSS Text Gradient and it opened me the idea about CSS Text Gradient. So maybe I can have this look gradient without using a transparent gradient PNG file. Bestwebbuzz.com presents text gradient without transparent gradient PNG file. This is how it works.

css gradient

css gradient

CSS
h2 {
 font-size:250%;
 color:#0079b6;
 font-weight:normal;
 letter-spacing:-.05em;
 margin:.6em 0;
 position:relative; 
 font-weight:bold;
}
h2 span{
 position:absolute;
 display:block;
 top:0;
 left:0;
 height:60%;
 width:100%;
 background-color:#FFFFFF;
 filter: alpha(opacity=65); /*     <—-this part do the magic——*/
  -moz-opacity: 0.65;/*       <—–this part do the magic———*/
  opacity: 0.65;/*          <—-this part do the magic———-*/
}

HTML
<h2>My Cool Title<span></span></h2>
<h3>My Cool Title<span></span></h3>

You can download the demo file here demo

I would like to thank Alen of cssglobe and Virgil of jampmark.com for the idea and concept.

15 Responses to “Optimized Css Text Gradient”

  1. Good trick but using an image is a better solution for anti-aliasing.

  2. [...] teniendo en cuenta dicho artículo como base, nos dejan otra variante en este otro artículo Optimized Css Text Gradient, con la posibilidad de darle un aspecto degradado sin usar un gradiente con un archivo PNG [...]

  3. Art Lawry says:

    To be fair, this is really not a gradient. The top of the text is one color, thanks to the overlay, and the bottom of the text is another, but there is no smooth transition from one color to the other.

    A better title might be “Optimized Css Gloss Effect”

  4. admin says:

    art i i agree i should have name this optimized css gloss effect. thanks for the correction.

    Hasan, yeah image is better to make it smooth but i want it optimized.

    thanks for the comment though

  5. virgil says:

    i think the title “Pure CSS Text Gloss Effect” is cool. Nicely done cris.

  6. [...] Optimized Css Text Gradient [...]

  7. Dimox says:

    Thanks for the great trick! But this not working in IE6. CSS must be like this for IE6:

    h2 span{
    position:absolute;
    display:block;
    top:0;
    left:0;
    height: 22px; /* for IF6 */
    width:100%;
    background-color:#FFFFFF;
    filter: alpha(opacity=65);
    -moz-opacity: 0.65;
    opacity: 0.65;
    overflow: hidden; /* for IF6 */
    }

  8. [...] Источник описанной техники – Optimized Css Text Gradient. [...]

  9. Adam says:

    Thanks for this…looking at ways to optimise my site!

  10. uujka says:

    h2 {
    font-size:250%;
    color:#0079b6;
    font-weight:normal;
    letter-spacing:-.05em;
    margin:.6em 0;
    position:relative;
    font-weight:bold;
    }
    h2 span{
    position:absolute;
    display:block;
    top:0;
    left:0;
    height:60%;
    width:100%;
    background-color:#FFFFFF;
    filter: alpha(opacity=65); /* <—-this part do the magic——*/
    -moz-opacity: 0.65;/* <—–this part do the magic———*/
    opacity: 0.65;/* <—-this part do the magic———-*/
    }

    HTML
    My Cool Title
    My Cool Title

  11. JuksWebGuy says:

    Topic bookmarked.

  12. Black Shirt says:

    Nice job mate. rocks.

  13. telmac says:

    i dont understand why you are calling this a gradient. its an interesting effect, but its no gradient.

  14. Bobb says:

    I think it is a gradient, well done !!

Leave a Reply

preload preload preload