仅在特定 id 下的元素的 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/451626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:13:17  来源:igfitidea点击:

CSS for elements ONLY under a specific id

css

提问by Toran Billups

I have a div element that has an id and this div contains a set of inputs and labels. I ONLY want to style the inputs inside this specific div but .. the following styles everything (global) instead of keeping the scope inside #ParentDiv

我有一个带有 id 的 div 元素,这个 div 包含一组输入和标签。我只想在这个特定的 div 中设置输入的样式,但是.. 以下样式设置所有内容(全局)而不是将范围保持在 #ParentDiv

#ParentDiv label,input { display: inline; }

Also, is it possible to do this type of thing with valid css in IE6/7?

另外,是否可以在 IE6/7 中使用有效的 css 来执行此类操作?

回答by cdeszaq

you need this:

你需要这个:

#ParentDiv label, #ParentDiv input { display: inline; }

A comma indicates a new selector statement.

逗号表示新的选择器语句。

Often, so that I remember what each of the selectors is, and to make it easier to see what elements are being selected at a glance, I will alphabetize and break the selectors on two separate lines like so:

通常,为了记住每个选择器是什么,并且为了更容易地一目了然地看到正在选择的元素,我将按字母顺序排列并将选择器分成两行,如下所示:

#ParentDiv input,
#ParentDiv label {
    display: inline;
}

Also, this should work just fine in IE 6/7/8, and is valid according to w3c.

此外,这在 IE 6/7/8 中应该可以正常工作,并且根据 w3c 是有效的。