使用特定 ID 设置 div 样式
#contentpage div
这是否意味着选择具有 id #contentpage
的 div?
我遇到了一些糟糕的布局。我正在尝试选择 id 为 #contentpage
的 div。
有人可以告诉我以下 css 的含义吗:
#myid div a
.myid a h
div #myid a
#contentpage div
Does this mean select the div that has id #contentpage
?
I am getting some bad layout. I am trying to select the div with the id #contentpage
.
Could somebody also please tell me what the following css mean:
#myid div a
.myid a h
div #myid a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想将一个 div 与 id #myid 进行匹配,那么要么忽略它是一个 div(无论如何 id 都是唯一的)这一事实,要么按如下方式进行匹配:
If you would like to match a div with id #myid, then either ignore the fact that it's a div (ids are unique anyway) or match it as follows:
这将匹配 ID 为
myid
的元素内div
内的a
。当我说“内部”时,我的意思是任何嵌套级别内的任何地方。其他都相同,但元素不同,顺序不同。如果您想要 id 为
contentpage
的元素,只需使用#contentpage
即可。如果出于某种原因您想指定它是一个 div,那么它将是div#contentpage
。This will match an
a
within adiv
within an element with the id ofmyid
. When I say "within" I mean anywhere within at any nesting level. The others are all the same but with different elements in different orders.If you want an element with the id of
contentpage
you simply use#contentpage
. If for some reason you wanted to specify that it was a div it would bediv#contentpage
.如果您想使用 contentpage 的 id 修改 div 的样式,那么您将执行以下操作
,或者
看起来您也试图获取 div 下的元素,这些元素可以通过多种方式访问,但这通常是我愿意
if you want to modify the styling of the div with the id of contentpage then you would do the following
OR
it also looks like you are trying to get at elements under the div these can be accessed in a number of ways but this is usually what I do
#contentpage {color:red}
将选择 id 为contentPage
的元素#myid div a
将选择内的 code> 元素位于 id
myid
.myid a h
的元素内,据我所知,没有
元素?如果没有h
,它将选择任何具有myid
类的元素内的所有链接(在这种情况下,myid 是一个可疑的名称,因为它本身不是一个 id)div #myid a
将选择 ID 为myid
的元素内部的链接,但前提是该元素位于内。例如,如果元素
myid
是的直接子元素,则它将不起作用
#contentpage {color:red}
will select whichever element with idcontentPage
#myid div a
will select<a>
elements that are inside<div>
that are inside an element with idmyid
.myid a h
as far as I know there is no<h>
element ? Without theh
, it would select all links within any elements with the classmyid
(in this case myid is a dubious name, then, since its not an id per se)div #myid a
will select links inside of an element with idmyid
, but only if this element is within a<div>
. It won't work if the elementmyid
is a direct children of<body>
for example