简体   繁体   English

带边框的透明文本 html/css

[英]Transparent text with a border html/css

So I have been searching, and maybe I am not searching correctly or the answers aren't making sense to me.所以我一直在搜索,也许我没有正确搜索或者答案对我来说没有意义。 I want to have completely transparent text with a visible border around it.我想要完全透明的文本,周围有可见的边框。

So far, this is what I have:到目前为止,这就是我所拥有的:

{
    font-family: Arial Black,Arial Bold,Gadget,sans-serif;
    color: white;
    opacity: 0.4;
    font-size: 80px;
    margin-left: 25px;
    text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}

The problem with this is lowering the opacity to allow the background through is also drastically reducing the border making the text harder to read.这样做的问题是降低不透明度以允许背景通过也大大减少了边框,使文本更难阅读。 I know that doing this will make it difficult anyway, but the fading border is not helping.我知道这样做无论如何都会让它变得困难,但逐渐消失的边界并没有帮助。 Any help on this is greatly appreciated!非常感谢您对此的任何帮助!

Use rgba() value for the color property.使用rgba()值作为color属性。

 div { font-family: Arial Black, Arial Bold, Gadget, sans-serif; color: rgba(255, 255, 255, 0.4); font-size: 80px; margin-left: 25px; text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; }
 <div>Some text</div>


Or you could use a :pseudo-element.或者您可以使用 :pseudo-element。

 div { position: relative; font-family: Arial Black, Arial Bold, Gadget, sans-serif; font-size: 80px; margin-left: 25px; text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; } div:after { position: absolute; top: 0; left:0; content: 'Some text'; width: 100%; height: 100%; font-family: Arial Black, Arial Bold, Gadget, sans-serif; color: white; opacity: 0.4; font-size: 80px; z-index: 1; pointer-events: none; }
 <div>Some text</div>

Or you could use svg .或者你可以使用svg

 body, html { height: 100%; margin: 0; background: url(http://lorempixel.com/500/200/) no-repeat; }
 <svg width="400" height="100"> <text fill="white" fill-opacity="0.4" font-size="80" x="200" y="70" text-anchor="middle" stroke="black">Some Text</text> </svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM