最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

CSS - copy parent class behavior to children - Stack Overflow

programmeradmin2浏览0评论

I have a component which renders this kind of html due to using a 3rd party ui component library:

<custom-component class="button-border">
    <button>Press me</button>
</custom-component>

I have defined styles for a button element with a class "button-border". Is there a way to make it behave as if the "button-border" class was given directly to the button instead of the parent element?

I have a component which renders this kind of html due to using a 3rd party ui component library:

<custom-component class="button-border">
    <button>Press me</button>
</custom-component>

I have defined styles for a button element with a class "button-border". Is there a way to make it behave as if the "button-border" class was given directly to the button instead of the parent element?

Share Improve this question asked Mar 14 at 8:51 weksowekso 852 silver badges13 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Yes, apply rules to button: .button-border > button {} instead of .button-border {}

Answering the CSS question: copy parent class behavior to children - use all: inherit;:

.parent{
  font-style: italic;
  cursor: pointer;
  color: red;
  button{
    all: inherit;
  }
}
<div class="parent">
  <button>Text</button>
</div>

发布评论

评论列表(0)

  1. 暂无评论