CSS页面水印是一种在网页上添加半透明背景图像或文字的技术,用于标识网页的来源或版权信息。水印通常不会干扰用户的主要操作,但可以在一定程度上防止网页内容被非法复制或盗用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Watermark</title>
<style>
body {
position: relative;
overflow: hidden;
}
.watermark {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
color: rgba(255, 255, 255, 0.2);
pointer-events: none; /* 确保水印不会干扰用户操作 */
z-index: 9999; /* 确保水印在最上层 */
}
</style>
</head>
<body>
<div class="watermark">© 2023 MyWebsite</div>
<h1>Welcome to My Website</h1>
<p>This is some content.</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Watermark</title>
<style>
body {
position: relative;
overflow: hidden;
}
.watermark {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('watermark.png');
background-repeat: repeat;
pointer-events: none; /* 确保水印不会干扰用户操作 */
z-index: 9999; /* 确保水印在最上层 */
opacity: 0.2;
}
</style>
</head>
<body>
<div class="watermark"></div>
<h1>Welcome to My Website</h1>
<p>This is some content.</p>
</body>
</html>
position
属性设置为absolute
,并通过top
、left
、transform
等属性调整位置。z-index
属性设置得足够高,以确保它在页面的最上层。opacity
属性,使其达到合适的透明度。pointer-events
属性为none
,以确保水印不会干扰用户的鼠标操作。通过以上方法,可以有效地在网页上添加水印,并解决常见的问题。
领取专属 10元无门槛券
手把手带您无忧上云