【问题标题】:Removing underline from flex child从 flex child 中删除下划线
【发布时间】:2018-08-24 19:06:24
【问题描述】:

仅从子元素中删除文本装饰的传统方法是将其设为inline-block(小提琴中的示例 1)

但是,这种方法在 flexbox 中不起作用。

我怎样才能从示例 2 中的图标中删除下划线?

.div1 {
    text-decoration: underline;
    .icon {
        display: inline-block;
        text-decoration: none;
    }

}
.div2 {
    display: flex;
    align-items: center;
    text-decoration: underline;
    .icon {
        display: inline-block;
        text-decoration: none;
    }
}

小提琴:https://jsfiddle.net/mz4y3jgL/8/

【问题讨论】:

    标签: html css flexbox underline


    【解决方案1】:

    将内容包装在 span 元素中,就像您为图标所做的那样。

    无法使用 CSS (related post) 定位匿名弹性项目,例如展开的文本。

    .div2 {
      display: flex;
      align-items: baseline;
    }
    
    .div2 > :not(.icon) {
      text-decoration: underline;
    }
    <div class="div2">
      <span>Example 2</span>
      <span class="icon">?</span>
    </div>

    【讨论】:

    • 谢谢!这是一个很好的解决方案。
    猜你喜欢
    • 2019-11-25
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多