HTML and CSS to achieve a text shading Picture

Look at the effect the ultimate realization of

 

Figure hello text instead of images


 

So how do you achieve this effect?

HTML part:

Create an h1 tag, label content (hello). External style sheet style.css link by link tags.

style.css part:

1, the main body portion of the unified style settings:

Eliminate some margin and padding defaults body; set the font bold; background is # 000 (black).

2, set the h1 style:

  1. Set the text font size 200px;
  2. Custom text only uppercase letters (UPPERCASE); thickness 900; 1px letter spacing;
  3. position & transform: translate (-50%, -50%) achieved a percentage of the center block elements;
  4. 1.jpg background image path; 50% image horizontal scale, vertical scale is 50%;
  5. Maintaining the aspect ratio of the image, and the image is scaled to the minimum size to completely cover the background.
  6. Fill color specified text, transparent transparent; (-webkit- using prefix)
  7. BACKGROUND specified text within the drawing area, the text cut into a shape; (-webkit- using prefix)

 

 

 Implementation code

HTML part:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Awesome Text Effect</title>
 6     <link rel="stylesheet" href="style.css">
 7 </head>
 8 <body>
 9     <h1>hello</h1>
10 </body>
11 </html>

CSS部分:

 1 body{
 2     margin:0px;
 3     padding:0px;
 4     font-family:"黑体";
 5     background:#000; 
 6 }
 7 h1{
 8     font-size: 200px;
 9     text-transform:uppercase;
10     /*定义文本中的大小写,uppercase仅有大写字母 */
11     font-weight: 900;
12     /*定义文本的粗细,从100~900*/
13     letter-spacing:1px;
14     /*设置字母间距*/
15     position:absolute;
16     top:50%;
17     left:50%;
18     transform: translate(-50%, -50%);
19     /*position & transform: translate(-50%, -50%) 
20     实现块元素百分比下居中*/
21     margin:0;
22     background:url(1.jpg) 50% 50%;
23     /*背景图片路径和size大小*/
24     background-size: cover;
25     /*此时会保持图像的纵横比*/
26     /*并将图像缩放成将完全覆盖背景定位区域的最小大小。*/
27     -webkit-text-fill-color:transparent;
28     /*text-fill-color是设置指定文字的填充颜色,transparent透明*/
29     -webkit-background-clip: text;
30     /*背景绘制在text区域内,剪切成文字形状*/
31 }

 

Guess you like

Origin www.cnblogs.com/nyw1983/p/11363562.html