回答
使用唯一CSS完成規範的方法之一是完美地重疊兩個背景圖像,從而創建您所描述的「透明」效果。這是一個小提琴:http://jsfiddle.net/v780v1Ln/。
注意:填充等會改變元素的尺寸並影響必須爲背景圖像設置的座標。
HTML:
<div id = "wrapper">
<h1><span>DRD</span></h1>
</div>
CSS:
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
background: #e2e2e2;
}
#wrapper {
position: absolute;
width: 70%;
height: 50%;
top: 25%;
left: 15%;
background: url(http://i58.tinypic.com/2vdieso.jpg)
no-repeat
0 0/500px 362px;
}
#wrapper > h1 {
background-color: #fff;
text-align: center;
position: absolute;
padding: 0 55px 0 25px;
top: 25px;
left: 25px;
}
#wrapper > h1 > span {
font: bold 70px/1 Sans-Serif;
text-transform: uppercase;
background: url(http://i58.tinypic.com/2vdieso.jpg)
no-repeat
-45px -25px/500px 362px;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
在Chrome中看起來很棒。在FireFox – Christina 2014-08-29 19:50:08
中不起作用WebKit瀏覽器和Opera支持'background-clip:text'。沒有FF支持:https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip。 – DRD 2014-08-29 20:56:12
這個效果很好。我已經做了一箇中心文本和非webkit瀏覽器回退的示例:http://jsfiddle.net/g2tf68v7/23/ – JamesPlayer 2014-08-31 05:55:56
- 1. 文本透明div
- 2. 使文本透明與div與黑色背景,但透明文本
- 3. 通過不透明父項透明內部div非透明
- 4. 爲外部div設置不透明度,不是內部文本
- 5. 透明div內的非透明div
- 6. JFrame部分透明
- 7. UIbutton部分透明?
- 8. 使文本透明的Shoes.app
- 9. 不透明度使div更不透明
- 10. 透明部分的視圖?
- 11. TableViewController中的透明部分
- 12. jQuery - 我如何淡化部分透明的div並保留不透明度?
- 13. 使圖像的一部分透明
- 14. 使UIView的一部分透明
- 15. 使UIImageView的一部分透明
- 16. 使UIView的一部分變得透明
- 17. 使圖像的一部分透明
- 18. 使文本框透明
- 19. 透明div上的不透明字體
- 20. 使浮動按鈕部分透明android
- 21. 如何使Android ImageView部分透明
- 22. 麻煩使部分位圖透明
- 23. 如何使HTML表部分透明?
- 24. 如何使文本在DIV較低的不透明度在HTML
- 25. 減少不透明度的元素部分是去除div
- 26. Div透明。裏面的文字不透明
- 27. 重疊部分透明元素的不透明度
- 28. IE 8透明div頂部內容
- 29. 使用透明div禁用div
- 30. 把透明度除div div
這個問題是許多其他問題重複。 http://stackoverflow.com/questions/2289159/can-i-do-knock-out-punch-through-transparency-with-css-fonts?lq=1和http://stackoverflow.com/questions/7626219/我該如何做 - 穿透透明的文本在html-css中?lq = 1 – CRABOLO 2014-08-28 22:37:04
這兩個問題都過時了。例如,它可以通過CSS完成。 http://css-tricks.com/image-under-text/ – Turnip 2014-08-28 22:42:37
是的,我看到了,但不幸的是,它不完全符合我的需求。我需要能夠看到更大的包含div的背景,而不是僅僅看到實際元素上的背景圖像。 – JamesPlayer 2014-08-28 22:54:40