Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clip a background on a colored text (only in css)

Tags:

css

I have a product configurator on my website. The user can write a word on a clothe and a text appears on the product image.

I want to style this text to look like an embroidery. So i put a text shadow, the text color changes in function of the product color, but now, i want to put a "filter" over the color.

Constraint: i just have access to the CSS.

here's a fiddle i did:

  #text
{
    font-size:90px;
    text-align:center;
    font-family:'petit_formal_script';
    -webkit-font-smoothing:antialiased;
    text-shadow: 2px 2px 2px black;
    color:lightblue;
}

#text:after
{
    content:'';
    position:absolute;
    left:0;
    top:0;
    right:0;
    bottom:0;
    background-image:url('http://hdwbin.com/wp-content/uploads/2014/11/red-background.jpg');
    -webkit-background-clip:text;
    -moz-background-clip:text;
    -webkit-text-fill-color:transparent;
}

http://jsfiddle.net/u2to713t/

Thanks in advance.

like image 633
Adrien QUINT Avatar asked May 12 '15 13:05

Adrien QUINT


People also ask

How do I make the background of text a color in CSS?

Changing Text Background Color in CSS. To change the background color of the inline text, go to the <head> section. Simply add the appropriate CSS selector and define the color and background-color property with the values you want.

How do I remove background color from text in CSS?

You can use background-color: rgba(0,0,0,0); The a is for alpha , it sets the opacity. But the background-color: transparent; is the way to go.

Can I use background-clip text?

The “background-clip: text” is supported in all main browsers with the Webkit prefix, it allows a background image to be clipped by a text element. In this guide we will look at examples using the background-clip property and the different values you can use.

How do you override background color in CSS?

If that class has a background-color of blue, and you want your <div> to have a red background instead, try to change the color from blue to red in the class itself. You could also create a new CSS class that defined a background-color property with a value of red and let your <div> reference that class.


1 Answers

I Finally did it.. The result is not what i expected but it works. Here's the final fiddle for the one who will try one day to do the same thing:

http://jsfiddle.net/u2to713t/13/

#text
{
    font-size:90px;
    text-align:center;
    font-family:'petit_formal_script';
    -webkit-font-smoothing:antialiased;
    text-shadow: 1px 2px 3px #474747;
    color:lightblue;
}

#text:before
{
     content: attr(data-text);
    position:absolute;
    left:-1px;
    top:7px;
    right:0;
    bottom:0;
    opacity:1.0;
    z-index: 1;
   color:transparent;
    text-shadow:0px 0px 0px;
    background:url("http://image.noelshack.com/fichiers/2015/20/1431421588-brodrwhite.png"); 
    -webkit-background-clip:text;
    -moz-background-clip:text;
     background-clip:text;



}
like image 113
Adrien QUINT Avatar answered Oct 30 '22 19:10

Adrien QUINT