代码之家  ›  专栏  ›  技术社区  ›  Fjott

使图像充当文本下划线

  •  0
  • Fjott  · 技术社区  · 6 年前

    h1 { text-align: center; }
    
    .container { width: 500px; margin: 0 auto;}
    
    .text-underline {
        background: transparent url("https://cockandbullfestival.co.uk/wp-content/themes/cock_bull/img/nav_underline.png") center bottom repeat-x;
    }
    <div class="container">
        <h1 class="text-underline"> Text With Stroke Underline </h1>
    </div>

    如何使此笔划图像作为文本下划线?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Temani Afif    6 年前

    考虑一下 span 要素 (内联元素) 内部 h1 所以你有一个心理医生来适应你的行为。

    h1 {
      text-align: center;
    }
    
    .container {
      width: 500px;
      margin: 0 auto;
    }
    
    .text-underline span {
      background: url("https://cockandbullfestival.co.uk/wp-content/themes/cock_bull/img/nav_underline.png") center bottom repeat-x;
    }
    <div class="container">
      <h1 class="text-underline"> <span>Text With Stroke Underline</span> </h1>
    </div>

    h1{
    文本对齐:居中;
    }
    
    保证金:0自动;
    }
    
    .文本下划线范围{
    }
    <div class="container">
      <h1 class="text-underline"> <span>Text With Stroke Underline Underline Underline Underline Underline Underline</span> </h1>
    </div>