我試圖用HTML中的彩色div大文本實現掩碼類效果。我想要這個蒙版文本顯示div後面的圖像的一部分。然而;而不是在div本身上使用background-clip
屬性和background-image
- 我希望簡單地揭示元素下方(在我的情況下,圖像)。 我曾嘗試使用svg圖像與複合路徑,他們證明太難處理。 有沒有其他辦法可以做到這一點? CSS? jQuery插件? 以文本爲掩碼的CSS div
2
A
回答
2
根據this article for applying a text mask,你可以用一個畫布標籤來做到這一點。
<div id="bg"><canvas id="overlay" width="240" height="70"></canvas></div>
<script>
// Get a handle to our canvas
var ctx = document.getElementById('overlay').getContext("2d");
// Choose font
ctx.font = "Bold 36px 'Helvetica'";
// Draw black rectangle
ctx.fillStyle = "black";
ctx.fillRect(0,0,230,70);
// Punch out the text!
ctx.globalCompositeOperation = 'destination-out';
ctx.fillText("Some Text", 25, 50);
</script>
-2
1
你可以使用Canvas對象做到這一點: http://jsfiddle.net/JackKalish/g3BDa/3/
var canvas1 = document.getElementById("canvas1");
var canvasContext1 = canvas1.getContext("2d");
// destination-out
// Text cuts-out everything under it
// background is revealed in the cut-out
makeGradientAndFont(canvasContext1, canvas1);
canvasContext1.globalCompositeOperation = 'destination-out';
canvasContext1.fillText("Portfolio", 175, 50);
function makeGradientAndFont(ctx, canvas) {
var grad = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
grad.addColorStop(0, '#0000FF');
grad.addColorStop(.3, '#00FFFF');
grad.addColorStop(.4, '#99FFFF');
grad.addColorStop(.5, '#00FF00');
grad.addColorStop(.6, '#FFFF00');
grad.addColorStop(.8, '#F00000');
ctx.rect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = grad;
ctx.fill();
ctx.fillStyle = "black";
ctx.font = "55px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
}
+0
謝謝!這也看起來類似我所希望的:) – grevin123
相關問題
- 1. 用CSS掩碼
- 2. 用css掩蓋div
- 3. jquery的文本掩碼
- 4. 在IE10中的css掩碼
- 5. 文本框日期掩碼
- 6. C#掩碼文本框
- 7. 用CSS中的圖像掩蓋div
- 8. CSS類不掩飾內心的div
- 9. CSS掩碼圖像問題
- 10. 如何應用反文本掩碼與CSS
- 11. C#文本框的自定義掩碼
- 12. uitextview/uiwebview中的掩碼文本
- 13. IP地址的掩碼文本框
- 14. 以IE爲中心的CSS文本
- 15. CSS不能爲文本div工作
- 16. CSS掩碼不能在Firefox上工作
- 17. 是否可以爲MaskedEditExtender設置日期格式爲MMM-yyyy的掩碼,該掩碼可用於任何文化?
- 18. 文本框掩碼只允許數字
- 19. HTML文本框掩碼或驗證
- 20. 輸入文本框日期掩碼
- 21. 用UILabel文本掩碼顯示UIView
- 22. CakePHP掩碼整數到文本
- 23. Internet Explorer 10中的CSS掩碼
- 24. 文本經過css div
- 25. css:可以通過css在div之間移動文本嗎?
- 26. CSS:文本換行到div中的div需要文本
- 27. java腳本掩碼問題
- 28. AS3 - 使用動態文本作爲掩碼
- 29. 爲div的添加代碼到CSS
- 30. 更改輸入掩碼的掩碼?
http://css-tricks.com/image-under-text/ – j08691
我已經看到了這,有幫助 - 但不是我要找的東西。我需要文本來簡單地揭示它下面的內容。不想給背景圖片。 – grevin123
下面還有其他圖像嗎? – helion3