Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

html - CLOSED CSS avoid inheritance for input in specific div

I'm working on this for almost 2 days and i can't find rigthful help to answer my problem. I hope you can help me :)

I've one master div with an ID ("myDiv") and a stylesheet who override input with specific properties. But, sometimes i'll like not to get the stylesheet specification.

In this exemple below, input1 need to receive the css specification but i want input2 and input3 to be clear. And if it's possible get there own.

I assume you understand it's a small sample from a bigger stylesheet =)

Exemple:

<div id="myDiv">
   <input id="input1" />
   <div class="Picker">
       <input id="input2" />
       <div>
           <input id="input3" />
       </div> 
   </div>
   ... Other html markup
</div>

StyleSheet:

#myDiv input {
   width: 40%;
   border: 1px solid #c4c4c4;
}

I tried this but it's not working at all (:not documentation from mozilla):

#myDiv div:not(.Picker) input {
   width: 40%;
   border: 1px solid #c4c4c4;
}

I tried something else (direct inheritance) :

#myDiv div:not(.Picker) > input {
   width: 40%;
   border: 1px solid #c4c4c4;
}

Thank all for your attention. Apologize for my bad english :)

Bobuche

question from:https://stackoverflow.com/questions/65937983/closed-css-avoid-inheritance-for-input-in-specific-div

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not so clear if you need to match #input1 or the other inputs

in the first case use

#myDiv input#input1 {
  ...
}

otherwise exclude the first input using :not()

#myDiv input:not(#input1) {
   ...
}

both these selectors have a higher specificity than #myDiv input so you will be able to override the properties defined.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...