【问题标题】:Child elements of link not overriding text-decoration when link is display flex当链接显示 flex 时,链接的子元素不会覆盖文本装饰
【发布时间】:2018-10-16 09:07:24
【问题描述】:

当链接 css 显示属性为 flex 时我遇到了一些麻烦:链接的子元素没有覆盖 text-decoration 属性。

示例:http://jsfiddle.net/wu627vn3/

.test{
    text-decoration:none;
    display:inline-block;
    color: red;
}

<a href="#" style="display: flex;">
    <div class="test">
        This isn't.
    </div>
    <div class="test">
        This isn't.
    </div>
</a>

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    您必须将text-decoration 添加到锚点

    .test {
      display: inline-block;
      color: red;
    }
    
    a {
      text-decoration: none
    }
    <a href="#" style="display: flex;">
      <div class="test">
        This isn't.
      </div>
      <div class="test">
        This isn't.
      </div>
    </a>

    【讨论】:

    • 是的。这是解决方案,但我想知道一个共振。为什么?它看起来像错误。
    • @JonSnowKnowsNothing 这不是错误。默认情况下,当您在其中嵌套了 inline-block 元素时,锚是内联的。因此,在这种情况下,下划线不可见。当你设置 display: flex 时,下划线变得可见。
    • @JonSnowKnowsNothing 您看到的下划线是锚元素的下划线,而不是“div”; text-decoration 不是可继承的属性。
    • @KK 好的!我明白了!谢谢!
    • @Daniel 好的!我明白了!谢谢!
    猜你喜欢
    • 2017-03-18
    • 2019-10-19
    • 1970-01-01
    • 2012-01-30
    • 2014-05-26
    • 1970-01-01
    • 2011-05-27
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多