我正在嘗試創建一個背景模糊且前面有可見文本的橫幅,但是當我運行代碼時,文本最終會與背景一起模糊。我找到了各種解決方案,但都沒有奏效。請幫我。
.bg-image {
background-image: url("PHT4.jpg");
filter: blur(8px);
-webkit-filter: blur(8px);
height: 40%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.bg-text {
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.4);
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
<body>
<div class="bg-image"</div>
<div class="bg-text">
<h1 style="font-size:50px">Elemental</h1>
</div>
</body>
uj5u.com熱心網友回復:
嘗試改為使用過濾器屬性,使用:
背景過濾器:模糊();
uj5u.com熱心網友回復:
如果在 之后添加 > ,效果會很好。正如 A Haworth 在評論中指出的那樣。
.bg-image {
background-image: url("PHT4.jpg");
filter: blur(8px);
-webkit-filter: blur(8px);
height: 40%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.bg-text {
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.4);
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
<body>
<div class="bg-image"></div>
<div class="bg-text">
<h1 style="font-size:50px">Elemental</h1>
</div>
</body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/397356.html
