CSS 标签“div.img img”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6405889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does the tag "div.img img" mean?
提问by Sasha
i understand the general idea of creating a class tag, such as .center or p.center, but what does it mean to do something like "p.center p"? i saw an example like this in creating an image gallery with css. what does the div.img img mean? thanks a bunch!
我理解创建类标记的一般想法,例如 .center 或 p.center,但是执行诸如“p.center p”之类的操作是什么意思?我在用 css 创建图片库时看到了这样的例子。div.img img 是什么意思?谢谢一堆!
<html>
<head>
<style type="text/css">
div.img
{
margin: 2px;
}
div.img img
{
display: inline;
margin: 3px;
border: 1px solid #ffffff;
}
div.img a:hover img {border: 1px solid #0000ff;}
</style>
</head>
<body>
<div class="img">
<a target="_blank" href="klematis4_big.htm"><img src="klematis4_small.jpg" alt="Klematis" width="110" height="90" /></a>
</div>
</body>
</html>
回答by TimFoolery
All of the answers given so far are correct, but perhaps also explaining what it isn't will help.
到目前为止给出的所有答案都是正确的,但也许也解释了它不是什么会有所帮助。
While div.img img { }
will affect img
elements contained in <div class="img">
elements, here are some elements that it will not affect:
虽然div.img img { }
会影响img
元素中包含的<div class="img">
元素,但这里有一些不会影响的元素:
<body>
<img src="klematis4_small.jpg" alt="Klematis"><br>
This image is not contained in a div, therefore it cannot possibly be
contained in a div of the class "img" and is therefore unaffected.
<div>
<img src="klematis4_small.jpg" alt="Klematis"><br>
This img element is in a div, but the div is not of the class "img",
so the img element is unaffected.
</div>
<div id="img">
<img src="klematis4_small.jpg" alt="Klematis"><br>
This img is contained within a div that has an ID of "img", but it is
also not of the class "img" and is therefore unaffected.
</div>
</body>
回答by alex
It means
它的意思是
Select any
img
element
that is a descendant of adiv
element with the classimg
.
选择 属于具有类的元素的后代的任何
img
元素。div
img
The img
class has no special meaning. It just looks a little confusing in this example.
该img
班有没有特殊的含义。在这个例子中它看起来有点混乱。
回答by Jake Petroules
The div.img img
selector will style img tags inside divs with the class "img". For example:
该div.img img
内部与类“IMG” div的选择意愿风格img标签。例如:
<div class="img">
<img src="foo.jpg" alt="" />
</div>
In short, only img tags that are contained within div tags having the class img will be styled by that selector.
简而言之,只有包含在具有 img 类的 div 标签中的 img 标签才会被该选择器设置样式。