初学者 CSS => 仅将属性应用于一个元素



所以我有这段代码:

<html>
<head>
<style>
html { 
background: url(bg_image.jpg) no-repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
</head>
<body>
<img src="logo.png">
</body>
</html>

如何在不影响徽标的情况下为背景图像添加亮度.png ?

编辑:我尝试将"过滤器:亮度(0.5(;"行添加到css中,但是徽标和其他所有内容都会受到影响,因为此属性适用于整个HTML代码。我怎样才能克服这个问题?

谢谢

您可以将

背景放在它自己独特的元素中,并使用负z-index将其放在其余内容后面。

body {
  min-height: 300vh;
}
.bg {
  background: url('http://3.bp.blogspot.com/_EqZzf-l7OCg/TNmdtcyGBZI/AAAAAAAAAD8/KD5Y23c24go/s1600/homer-simpson-1280x1024.jpg') no-repeat center center / cover;
  filter: brightness(0.5);
  position: fixed;
  z-index: -1;
  top: 0; left: 0; right: 0; bottom: 0;
}
<div class="bg"></div>
<img src="http://kenwheeler.github.io/slick/img/fonz1.png">

您可以使用其他库来简化工作;像Material Ui 这样的库为您提供了一种称为纸张的东西,它充当包装器,因此您可以轻松更改它的属性和属性。

如上文所述,更改 z 索引:-1 是一个很好的起点。

最新更新