Not CSS selectors

后端 未结 8 1977
礼貌的吻别
礼貌的吻别 2020-11-28 11:05

Is there some kind of \"not\" CSS selector?

For example when I write the following line in my CSS, all input fields inside an tag with class classname will

8条回答
  •  离开以前
    2020-11-28 11:25

    Inputs are a bit annoying because, unlike most other html elements, there isn't necessarily a way of resetting all the css properties back to their default value.

    If the styling is non-critical (ie a nice to have but doesn't affect functionality) I would use jQuery to get an array of all the inputs, check their parents, and then only carry out the styling on those outside that div. Something like:

    $('input').each(function() {
         if($(this).closest('.classname') == false)
         {
               // apply css styles
         }
    });
    

    (By the way, I'm no jQuery expert, so there might be some errors in the above, but in principle something like this should work)

提交回复
热议问题