简体   繁体   English

如何在CSS中创建图案覆盖

[英]How do I create a pattern overlay in CSS

I'm trying to create a header for my website but I'm having a bit of difficulty as I'm new to HTML and CSS. 我正在尝试为我的网站创建标题,但是由于对HTML和CSS陌生,所以遇到了一些困难。 I want to create a banner with the same font and background as shown below. 我想用相同的字体和背景创建横幅,如下所示。 They consist of a certain colour with a pattern overlay at 44% opacity, which I'm not sure how to do. 它们由某种颜色组成,并以44%的不透明度覆盖图案,我不确定该怎么做。

I originally uploaded the header as an image, but I was told it's bad to use large images on websites as it make it longer to load. 我最初将标头作为图像上传,但是有人告诉我在网站上使用大图像很不好,因为它会使加载时间更长。 So I tried creating it via code. 所以我尝试通过代码创建它。 If anybody could please help replicate the header below, I'd greatly appreciate it. 如果有人可以帮助您复制下面的标头,我将不胜感激。 Thanks. 谢谢。

Link to my current HTML & CSS Code via Fiddle 通过小提琴链接到我当前的HTML和CSS代码

Link to Banner I want to replicate 链接到我要复制的横幅

Here you have your fiddle updated: FIDDLE 在这里,您的小提琴已更新: FIDDLE

I've fixed a few things in the html like tags not closed (your headers) and now the "container" contains the banner propely. 我已经修复了html中的一些东西,例如未关闭的标签(您的标头),现在“容器”适当地包含了横幅。

So now you just have to add a background image with the pattern you want and (as you did) play with the opacity value of your text. 因此,现在您只需要添加具有所需图案的背景图像,并(如您所做的那样)使用文本的不透明度值即可播放。

#container {
    background-image:url(http://zimasolutions.com/Images/pattern.png);
    repeat:repeat;
}

Use the repeat option for the background image so you just need a little image. 对背景图像使用重复选项,因此只需要一点图像。

I uploaded temporally the image pattern.png I have used as an example. 我暂时上传了我用作示例的image pattern.png。 I took the sample for the image you linked. 我为您链接的图像取了样本。 In a few hours I may delete that image. 几个小时后,我可能会删除该图像。

Edited: IF you want the pattern image OVER the text insteed of under it may be more complicated. 编辑:如果您希望图案图像超过其下方指示文字的上方,可能会更加复杂。 You could absolute position a container over the banner but in this case you may need to change the image opacity with an image editor (like photoshop). 您可以将容器绝对定位在横幅上,但是在这种情况下,您可能需要使用图像编辑器(例如photoshop)更改图像的不透明度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM