English 中文(简体)
“空间”与空间学会选择者的空间有何区别?
原标题:What is the difference between > and a space in CSS selectors?

使用这一辛加税点是什么

div.card > div.name

这两者之间有何区别

div.card div.name
最佳回答

A > B将只选B类直接儿童进入A类(即没有其他内容在外)。

<代码>A B将选择A内的任何B,即使其中还有其他内容。

问题回答

> vs. Space

审议两个假设情景:div >%20} vs. div%20{>

此处,<代码> (space) 选择了所有<span>、>、div>、内的内容,即使放在一个以上要素内。 <代码>> 选择了所有子女:<div> 要素,但如果不在另一要素范围之内的话。


探讨两个例子:

> (Greater than):

div > span {
  color: #FFBA00 ;
}
<body>
  <div>
    <div>
      <span>Hello...</span>
      <p><span>Hello!</span></p>
    </div>

    <span>World!</span>
  </div>
</body>

这只是选择了<代码><span>Hello...</span> (because it s Immediate after the nested div tag, and <span>World!</span>, and 它赢得对, 因为其并非在<>divcode/>上。

Space

div span {
  color: #0A0 ;
}
<body>
  <div>
    <div>
      <span>Hello...</span>
      <p><span>Hello!</span></p>
    </div>

    <span>World!</span>
  </div>
</body>

即便是在其他标签内封顶的,也选择了所有各界。

div.card > div.name matches <div class= card >....<div class= name >xxx</div>...</div> but it doesn t match <div class= card >....<div class= foo > ... <div class= name >xxx</div>..</div>....</div>

<代码>div.card div. 姓名对两者都有对应关系。

That is, the > selector makes sure that the selected element on the right side of the > is an immidiate child of the element on its left side.

The syntax without the >对以下条目加以匹配:<div category= name >的后代(而不仅仅是儿童)<div category=index >

A > B 选择B,如果是A的直接孩子,而AB选择B, 不管它是否是B的直接孩子。

<p> USING SPACE </p>

<style>
  .a .b {
    background-color: red;
  }
</style>

<span class="a">
  a
  <br>
  <span class="b"> a b</span>
  <br>

  <span class="c">
    <span class="b"> a b c</span>
  </span>
</span>

<br><br>
<p> USING GREATER THAN SIGN</p>

<style>
  .x > .y {
    background-color: red;
  }
</style>

<span class="x">
  x
  <br>
  <span class="y"> x y</span>
  <br>

  <span class="z">
    <span class="y"> x y z</span>
  </span>
</span>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签