CSS:令人惊讶地删除了没有处理子显示:内联块div

Dea*_*ool 5 html javascript css jquery

如果我应用文本修饰,我有一个代码:line-through; 在外部div上,所有内部div元素也必须是"strikethroughed".这通常100%正常; 但是,如果我将子元素设置为' display:inline-block ',现在应用于父div的删除线不会影响对孩子的攻击.我必须把孩子作为显示器:内联块,我需要在添加文本装饰时划掉孩子:直通; 父div.

div{padding:10px;}
#outer{background:yellow;text-decoration: line-through;}
#inner{background:pink;display:inline-block;}
Run Code Online (Sandbox Code Playgroud)
<div id=outer> 
  <div id=inner>
    This is the text 
  </div> 
</div>
Run Code Online (Sandbox Code Playgroud)

这是一个办公室项目,非常感谢您的帮助!

Mr *_*ter 7

使用text-decoration:inherit.

div{padding:10px;}
#outer{background:yellow;text-decoration: line-through;}
#inner{background:pink;display:inline-block; text-decoration:inherit}
Run Code Online (Sandbox Code Playgroud)
<div id=outer> 
  <div id=inner>
    This is the text 
  </div> 
</div>
Run Code Online (Sandbox Code Playgroud)

通常,text-decoration不是继承属性,因此内部div具有隐式text-decoration:none默认值.通过使用inherit,您告诉元素它应该与其父元素具有相同的文本修饰.

  • @AaronDigulla许多样式都是继承的,但绝不是全部.[here](http://www.w3.org/TR/CSS/#properties)是一个列表. (3认同)
  • `请注意,文本修饰不会传播到浮动和绝对定位的后代,也不会传播到原子内联级后代(如内联块和内联表)的内容.解释就在那里:[W3C](http://www.w3.org/TR/CSS2/text.html#propdef-text-decoration).这意味着除非正确指定,否则子元素将不会继承该属性. (2认同)

Ben*_*Ben 6

text-decorationis 的默认值none,因此如果您希望它不同,则需要指定一个值.使用inherit使用母公司的价值:

#outer > div { text-decoration: inherit; }
Run Code Online (Sandbox Code Playgroud)

或适应css #inner包括text-decoration: inherit;:

#inner { background: pink; display: inline-block; text-decoration: inherit; }
Run Code Online (Sandbox Code Playgroud)

div{padding:10px;}
#outer{background:yellow;text-decoration: line-through;}
#inner{background:pink;display:inline-block; text-decoration: inherit; }
Run Code Online (Sandbox Code Playgroud)
<div id=outer> 
  <div id=inner>
    This is the text 
  </div> 
</div>
Run Code Online (Sandbox Code Playgroud)

  • `text-decoration`自动赋值为'none`,因此如果你希望它不同,你需要指定一个值 (2认同)