CSS實(shí)現(xiàn)背景圖片透明而文字不透明效果的兩種方法
發(fā)布時(shí)間:2017-04-25 14:27:43 作者:佚名
我要評(píng)論

這篇文章主要介紹了CSS實(shí)現(xiàn)背景圖片透明而文字不透明效果的兩種方法,需要的朋友可以參考下
摘要:
方法一(毛玻璃效果):背景圖 + 偽類(lèi) + flite:blur(3px)
方法二(半透明效果):背景圖 + 定位 + background:rgba(255,255,255,0.3)
CSS實(shí)現(xiàn)背景圖片透明,文字不透明效果的兩種方法
項(xiàng)目中經(jīng)常會(huì)用到背景圖上放一些文字介紹,這里介紹兩種技術(shù)來(lái)實(shí)現(xiàn)背景圖片透明,文字不透明效果,記錄一下,方便日后學(xué)習(xí)。
1.毛玻璃效果:
背景圖 + 偽類(lèi) + flite:blur(3px)
.demo1{ width: 500px; height: 300px; line-height: 50px; text-align: center; } .demo1:before{ background: url(http://csssecrets.io/images/tiger.jpg) no-repeat; background-size: cover; width: 500px; height: 300px; content: ""; position: absolute; top: 0; left: 0; z-index: -1;/*-1 可以當(dāng)背景*/ -webkit-filter: blur(3px); filter: blur(3px); }
<div class="demo1">背景圖半透明,文字不透明<br />方法:背景圖+ filter:blur</div>
2.半透明效果:
背景圖 + 定位 + background:rgba(255,255,255,0.3)
.demo2-bg{ background: url(http://csssecrets.io/images/tiger.jpg) no-repeat; background-size: cover; width: 500px; height: 300px; position: relative; } .demo2{ position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 500px; height: 300px; line-height: 50px; text-align: center; background:rgba(255,255,255,0.3); } <div class="demo2-bg"> <div class="demo2">背景圖半透明,文字不透明<br />方法:定位+ background:rgba(255,255,255,0.3)</div> </div>
以上所述是小編給大家介紹的CSS實(shí)現(xiàn)背景圖片透明而文字不透明效果的兩種方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
DIV+CSS中讓布局、背景圖片、文字內(nèi)容居中的方法
這篇文章主要為大家介紹了在DIV+CSS布局的頁(yè)面里,讓布局、背景圖片、文字內(nèi)容居中的方法,從布局內(nèi)容到頁(yè)面里文章文字居中都是非常重要的,而css來(lái)設(shè)置居中也是非常簡(jiǎn)單的2014-10-09- 這篇文章主要介紹了css實(shí)現(xiàn)文字在背景圖片之上,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-21