Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background image for font color?

Tags:

html

css

Say I have the following code:

<span>Hello world!</span>

And the following CSS:

span{
color:red;
}

Is there any way I can change the red to an image? Like url(images/text-bg.png);? I want to put a texture on my text and decided that I would just make the text "color" an image, but I'm not sure if this can be done with CSS.

like image 978
Charlie Avatar asked Aug 31 '11 18:08

Charlie


2 Answers

it is possible, take a look at this pen here

https://codepen.io/feferonka/pen/eoWLZp

Use this on parent of text:

  background-image: url(url);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
like image 114
Martin Hetfield Mali Avatar answered Sep 21 '22 15:09

Martin Hetfield Mali


Yes it's possible using svg , you can embed <svg> over one <div> and background image over another <div>, later apply z-index to <div>. You can use Vector applications like illustrator to create the svg the way you want.


<html>
<head>
<title>Untitled Document</title>
<style>
html
 {
    background-image:url('lauch.jpg');
    background-repeat:no-repeat;
    background-position:center;
    padding-top:200px;
 }
</style>
</head>
<body>

<div align="center">
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="140px" height="80px" viewBox="0 0 76.25 39.167" enable-background="new 0 0 76.25 39.167" xml:space="preserve">
<text transform="matrix(1 0 0 1 5.9336 30.417)" fill="none" stroke="red" stroke-width="0.25" stroke-miterlimit="10" font-family="'Tahoma'" font-size="36">Text</text>
</div>
</body>
</html>
like image 40
akthktd Avatar answered Sep 19 '22 15:09

akthktd