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

h1元素的文本比元素的实际高度短。我可以删除空白吗?

  •  0
  • Onyx  · 技术社区  · 4 年前

    我有一个 <h1> 具有以下类的元素:

    .product-name {
      font-size: 36px;
      font-weight: 600;
      border-bottom: 1px solid #dee2e6;
      padding-bottom: 20px;
      margin-bottom: 20px;
    }
    <h1 class="product-name">My awesome product </h1>

    文本呈现如下:

    current output

    如您所见,文本上方和下方有一些空白。我正在努力实现这一点:

    desired output

    这可以实现吗?

    0 回复  |  直到 4 年前
        1
  •  0
  •   Kevin Shuguli    4 年前

    我想你是这个意思。 我补充道 line-height: 1;

    .product-name {
        font-size: 36px;
        font-weight: 600;
        border-bottom: 1px solid #dee2e6;
        line-height: 1;
        margin-bottom: 20px;
        display: inline-block;
    }
    <h1 class="product-name">Aadaadf</h1>
        2
  •  0
  •   casraf    4 年前

    .product-name {
      font-size: 36px;
      font-weight: 600;
      border-bottom: 1px solid #dee2e6;
      padding-bottom: 20px;
      margin-bottom: 20px;
      line-height: 30px; /* here */
    }
    <h1 class="product-name">My awesome product </h1>