--- title: 後裔選擇器 slug: Web/CSS/Descendant_combinator tags: - CSS - CSS參考 - Selectors - 初學者 - 選擇器 translation_of: Web/CSS/Descendant_combinator ---

{{CSSRef("Selectors")}}

簡介

組合符號 (代表空白, 或更精準地說,代表一或多個空白字元) 結合了兩種選擇器,選擇了只有當第二個選擇器的目標為第一個選擇器目標的後裔時的元素,後裔選擇器跟子選擇器相似,但是不要求披對的元素要是嚴格是父子關係。

語法

selector1 selector2 { style properties }

範例

span { background-color: white; }
div span { background-color: DodgerBlue; }
<div>
  <span>Span 1.
    <span>Span 2.</span>
  </span>
</div>
<span>Span 3.</span>

{{ EmbedLiveSample('Example', 200, 50) }}

Specifications

Specification Status Comment
{{ SpecName('CSS4 Selectors', '#descendant-combinators', 'descendant combinator') }} {{ Spec2('CSS4 Selectors') }}  
{{ SpecName('CSS3 Selectors', '#descendant-combinators', 'descendant combinator') }} {{ Spec2('CSS3 Selectors') }}  
{{ SpecName('CSS2.1', 'selector.html#descendant-selectors', 'descendant selectors') }} {{ Spec2('CSS2.1') }}  
{{ SpecName('CSS1', '#contextual-selectors', 'contextual selectors') }} {{ Spec2('CSS1') }} Initial definition

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}