Html 嵌套在 div 中的命名 span 类的 CSS 语法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4611727/
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 05:59:32  来源:igfitidea点击:

What is the CSS syntax for a named span class nested in a div?

htmlcss

提问by alpheus

In the following, how do I reference the "name" class?

在下面,我如何引用“名称”类?

<div class="resultDetails">
<span class="name">Name</span>
<span class="address">Address</span>
</div>

回答by Harish

div span.name { ... }

div.. tells the element type

div.. 告诉元素类型

a space then span.. tells to look at span elements in sub levels

一个空间然后span.. 告诉查看子级别中的跨度元素

.name.. tells to look at those elements with css class named name

.name.. 告诉查看那些名为 css 类的元素 name

回答by Brad Christie

div.resultDetails > span.name { ... }

Should work.

应该管用。

回答by Patrick Evans

simply

简单地

<style>
.name
{

}
</style>

All you need is the name of the class itself, unless other factors otherwise you can use several types of selectors

您只需要类本身的名称,除非有其他因素,否则您可以使用多种类型的选择器

div span.name // selects all spans with class "name" in any div
div > span.name // this one selects only the spans that are direct children of a div
div.resultDetails span.name //select only spans with class "name" in only divs with class="result Details
.resultDetails .name // selects any element with class "name" in any element with class "resultDetails" 

There are more ways of selecting but you get the point.

有更多的选择方式,但你明白了。

回答by jacobangel

div.resultDetails > span.name works in most browsers.

div.resultDetails > span.name 适用于大多数浏览器。

However, it doesn't work in IE6. If that's an issue, just using: div.resultDetails span.name {} should target the span correctly (provided you dont have any nested span.name elements inside the div that you don't intend to target).

但是,它在 IE6 中不起作用。如果这是一个问题,只需使用: div.resultDetails span.name {} 应该正确定位范围(前提是您不打算定位的 div 内没有任何嵌套的 span.name 元素)。