用CSS添加“水印”效果?

我有一个div的形象.我需要添加一个水印效果,或者基本上另一个图像,上面的图像的div.如何用css这样做?

示例代码

<div id="image">
</div>

CSS:

#image {
   background:url(images/images.png) no-repeat;
}

解决方法

至少有两种方法可以做到这一点,其中一种被@ erenon的答案所触动.

满足您的要求并使用图像:

<div id="image">
    <img src="path/to/watermarking_image.png" alt="..." />
</div>

使用以下CSS:

#image {
/* the image you want to 'watermark' */
height: 200px; /* or whatever,equal to the image you want 'watermarked' */
width: 200px; /* as above */
background-image: url(path/to/image/to/be/watermarked.png);
background-position: 0 0;
background-repeat: no-repeat;
position: relative;
}

#image img {
/* the actual 'watermark' */
position: absolute;
top: 0; /* or whatever */
left: 0; /* or whatever,position according to taste */
opacity: 0.5; /* Firefox,Chrome,Safari,Opera,IE >= 9 (preview) */
filter:alpha(opacity=50); /* for <= IE 8 */
}

这应该产生如下所示:

+--------------+--------------+
   |              |              |
   | 'watermark'  |              |
   |              |        __    |
   +--------------+       /  \   |
   |                     (    )  |
   |               /\     \  /   |
   |              /  \     ||    |   <-- Picture. Of...something. O_o
   | /\          /    \    ||    |
   |/  \________/      \_()||_()(|
   +-----------------------------+

另一种方式,假设你所有的“水印”都是“一个字”,就是使用单词:

<div id="image">
    <p>Watermark text</p>
</div>

和以下CSS:

#image {
/* the image you want to 'watermark' */
height: 200px; /* or whatever,equal to the image you want 'watermarked' */
width: 200px; /* as above */
background-image: url(path/to/image/to/be/watermarked.png);
background-position: 0 0;
background-repeat: no-repeat;
position: relative;
}

#image p {
/* the actual 'watermark' */
position: absolute;
top: 0; /* or whatever */
left: 0; /* or whatever,IE >= 9 (preview) */
filter:alpha(opacity=50); /* for <= IE 8 */
}

这应该产生如下所示:

+--------------+--------------+
   |              |              |
   |  watermark   |              |
   |    text      |        __    |
   +--------------+       /  \   |
   |                     (    )  |
   |               /\     \  /   |
   |              /  \     ||    |   <-- Picture. Of...something. O_o
   | /\          /    \    ||    |
   |/  \________/      \_()||_()(|
   +-----------------------------+

我意识到这个问题可能是您的满意答案,但我希望这对您有用,即使只是一般信息.

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效