Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于Id选择器问题的CSS问题?_Css_Css Selectors - Fatal编程技术网

关于Id选择器问题的CSS问题?

关于Id选择器问题的CSS问题?,css,css-selectors,Css,Css Selectors,在下面的代码中将ba选择器用作id选择器而不是类选择器时,如何使其工作 这不适用于将ba作为id属性的情况 #abc textarea#ba { height: 400px; width: 660px; } #abc textarea.ba { height: 400px; width: 660px; } 这将使用ba作为类属性 #abc textarea#ba { height: 400px; width: 660px; } #abc texta

在下面的代码中将ba选择器用作id选择器而不是类选择器时,如何使其工作

这不适用于将ba作为id属性的情况

#abc textarea#ba {
   height: 400px; 
   width: 660px;
}
#abc textarea.ba {
   height: 400px; 
   width: 660px;
}
这将使用ba作为类属性

#abc textarea#ba {
   height: 400px; 
   width: 660px;
}
#abc textarea.ba {
   height: 400px; 
   width: 660px;
}

我不明白你的例子为什么行不通

您是否100%确定在ID为abc的元素中有ID为ba的textarea?记住,名称属性不算数。也许在其中一个元素中有一个重复的id?另外,请记住,您可以分配多个类,但不能分配id='abc def'等多个id

编辑:这对我来说很好:

<style type="text/css">
#abc textarea#ba {
   height: 400px; 
   width: 660px;
   background-color: lightyellow;
}

</style>

<div id="abc">
  <textarea id="ba">
    I'm 400  wide, 660 tall and light yellow!
  </textarea>
</div>

id的全部意义在于它们是唯一的标识符,因此您不需要以这种方式进行选择,只需使用

#ba {
   height: 400px; 
   width: 660px;
}
如果你有多个学士学位,那么你做得不对

'id=此属性指定的名称[CS] 元素的名称。这个名字必须是 在文档中必须是唯一的。”


来源:

你也需要显示你的html。但这不一定。如果我只想影响abc中的ba,如果可能不想,这是合法的使用。@DN啊,公平点。我是从另一个角度看的。