这两个css选择器之间的区别是什么? [英] whats the difference between these two css selectors?

查看:107
本文介绍了这两个css选择器之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个选择器之间的区别,我认为他们会有相同的效果,但他们不?

Whats the difference between these two selectors, I thought they would have the same effect, but they don't? can someone explain please?

    #parent-div #child-div

    #parent-div#child-div


推荐答案

CSS选择器中的后代选择器。

The (space) in CSS selectors is the "descendant selector."


  1. 选择ID为 child-div 的元素具有 parent-div 的父项

  2. 选择一个具有 parent-div child-div (这是不可能的)

  1. Selects an element with ID child-div that has an ancestor of parent-div
  2. Selects an element that has an id of both parent-div and child-div (which is impossible)

parent-div#child-div 是一个有效的ID,但是作为CSS语法的一部分, code>#在规则集中:

Just for fun: parent-div#child-div is a valid ID, but as part of the CSS syntax you have to escape the # in the ruleset:

http://jsfiddle.net/ExplosionPIlls/xdWNV/1/

这篇关于这两个css选择器之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆