如何使用 CSS 创建"黑白"图像?

cssweb developmentfront end technology更新于 2025/9/28 8:12:17

以下是使用 CSS 创建黑白图像的代码 −

示例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
img{
   margin: 20px;
}
img.normal{
   margin-left: 30%;
   width: 300px;
   height: 300px;
}
img.filter {
   width: 300px;
   height: 300px;
   filter: grayscale(100%);
}
</style>
</head>
<body>
<h1 style="text-align: center;">CSS Black and White Image example</h1>
<img class="normal" src="https://i.picsum.photos/id/59/500/500.jpg">
<img class="filter" src="https://i.picsum.photos/id/59/500/500.jpg">
</body>
</html>

输出

上述代码将产生以下输出 −


相关文章


有用资源