【问题标题】:Transparent text with a border html/css带边框的透明文本 html/css
【发布时间】:2015-01-24 21:11:36
【问题描述】:

所以我一直在搜索,也许我没有正确搜索或者答案对我来说没有意义。我想要完全透明的文本,周围有可见的边框。

到目前为止,这就是我所拥有的:

{
    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;
}

这样做的问题是降低不透明度以允许背景通过也大大减少了边框,使文本更难阅读。我知道这样做无论如何都会变得困难,但逐渐消失的边界无济于事。非常感谢您对此的任何帮助!

【问题讨论】:

    标签: html css textcolor text-formatting


    【解决方案1】:

    color 属性使用rgba() 值。

    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>

    或者你可以使用 :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>

    或者你可以使用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>

    【讨论】:

    • 第三个选项更接近我想要完成的,第一个和第二个最终都变得更暗并且完全隐藏了背景。就像你的第三个一样,我想通过字母看到背景,但我试图让它完全清晰,而不是看起来像磨砂玻璃。不幸的是,svg 给了我很多我已经拥有的东西。
    • @ChrisStorz - 只需将 fill-opacity 更改为 0
    • @ChrisStorz - 顺便说一句,您还可以使用 stroke-width 属性更改边框的 width
    • 太棒了!谢谢芯片!稍作调整,我就会得到我想要的东西!
    • @ChrisStorz - 不客气。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    相关资源
    最近更新 更多