CSS 不透明度/透明度
cssweb developmentfront end technology更新于 2025/11/27 1:48:17
CSS 不透明度/透明度使用 opacity 属性。例如:
opacity: 0.3;
以下代码展示了使用 CSS 实现的不透明度/透明度 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
div {
width: 200px;
height: 200px;
background-color: rgb(0, 0, 255);
color: white;
display: inline-block;
}
.transparent {
background-color: rgba(0, 0, 255, 0.582);
}
img{
width: 200px;
height: 200px;
}
.transparent-img{
opacity: 0.3;
}
</style>
</head>
<body>
<h1>Tansparency/Opacity Example</h1>
<div class="transparent">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Hic, accusantium.
</div>
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Eum, nisi!
</div>
<hr>
<img src="https://i.picsum.photos/id/487/300/300.jpg">
<img class="transparent-img" src="https://i.picsum.photos/id/487/300/300.jpg">
</body>
</html>
输出
上述代码将产生以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

