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

Sas*_*sha 5 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>
Run Code Online (Sandbox Code Playgroud)

Tim*_*ery 14

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

虽然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>
Run Code Online (Sandbox Code Playgroud)

  • +1非常好的例子.我努力让它变得更好. (2认同)

ale*_*lex 9

它的意思是

选择任何img元素
作为div元素的后代元素img.

img门课没有特别的意义.在这个例子中,它看起来有点令人困惑.