css - 从 <u> 中的某些元素中删除下划线

标签 css css-selectors

<分区>

我正在使用 Chrome 插件将自定义样式表调整应用于其他人的网站(即我无法更改 HTML)。

我想停止在下划线 ( <i> ) 元素内给斜体 ( <u> ) 文本加下划线,同时保留 <u> 内其他部分的正常下划线.

例如,这些是我所追求的:

<u>Foo</u>                --> Foo (underlined)
<u><i>Bar</i></u>         --> Bar (not underlined)
<u>Foo <i>Bar</i></u>     --> Foo (underlined) Bar (not underlined)

我试过:

u i {
  text-decoration: none !important;
}

但是发现改变<i>的text-decoration|没有区别。外层<u>似乎是决定文本装饰的那个。

有办法吗?

我知道这可能是 Is there a CSS parent selector? 的副本 但希望有人能够为这个特定案例想出一个聪明的解决方法。

最佳答案

是的。

display:inline-block 应用到不带下划线的 child 。

u {
font-size:3rem
}

u i {
  text-decoration: none !important;
  display: inline-block;
}
<u>Foo <i>Bar</i></u>  

关于css - 从 <u> 中的某些元素中删除下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53759520/

上一篇:javascript - 推特喜欢使用CSS的按钮动画

下一篇:javascript - 如何使任何悬停的颜色比原始颜色更深/更浅

相关文章:

html - 在不使用 !important 或内联样式表的情况下覆盖 CSS 样式行为

css - 水印文本CSS

css - 将按钮的可见属性分配给静态方法结果

javascript - 如何从 jQuery 包装集中删除后代元素?

javascript - 根据 Material-UI 组件的 props 动态创建第 n 个子选择器

CSS 应用第 n 个类型

html - 向第一列添加元素会将第二列向下推

html - 如何让背景图片覆盖整个屏幕?

html - @media 标签在 HTML 类中不起作用

css - 如何使用 grunt-recess 编译 2 个独立的 LESS 文件