css - 标签 "div.img img"是什么意思?

标签 css css-selectors

我理解创建类标签的一般概念,例如 .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>

最佳答案

到目前为止给出的所有答案都是正确的,但也许也解释一下它不是什么会有所帮助。

同时 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>

关于css - 标签 "div.img img"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6405889/

相关文章:

html - 在 HTML 或 body 上实现背景图片的最佳方式

html - 在容器内垂直居中 div

html - 在 CSS 中选择每隔一个级别

java - 如何在 Java 中使用 Selenium 从 Tooltip 获取文本?

html - ID类CSS文件

html - 文本节点后的第一个 block 的边距(垂直空间)?

css - 求ME IE 7+纯CSS下拉多级菜单

javascript - 如何使用 javascript 创建导航菜单?单击菜单选项后如何平滑滚动到部分?

javascript - 在 casperjs 上提交一个没有名字的表单

css - 是否有 "previous sibling"选择器?