html - 选择表格内和 div 内的图像

标签 html css

如何在不选择上方图片的情况下选择下方图片 (@div class="this"),以便使用 CSS 设置样式?

<table>
    <tr>
        <td><a href="../index.html"><img src="../home.png"></a></td> <!-- GO BACK TO HOMEPAGE -->
        <td><a href="########"><img src="../artist.png"></a></td> <!-- GO TO ARTIST -->
        <td><img src="../portfolio.png"></td>
        <td><img src="../contact.png"></td>
    </tr>
    <tr>
        <td colspan="8"><img src="../logo.png"></td>
    </tr>
    <tr>
        <td colspan="8"><img src="../greenmoralesgraphic.png"></td>
    </tr>
    <tr><div class="this">
        <td><img src="nostalgia.jpg" width="400px" height="400px"></td>
        <td><img src="pwersa.jpg" width="400px" height="400px"></td>
        <td><img src="tag_along.jpg" width="400px" height="400px"></td>
        <td><img src="tweet.jpg" width="400px" height="400px"></td>
        </div>
    </tr>
</table>

最佳答案

使用

.this img{
  border:1px solid #ddd;
}

这将选择 .this 类中的图像。这样应用的样式将仅应用于 .this 类中的图像。该空间称为后代组合器。 Read about descendant combinator here

.this img{
  border:1px solid #f00;
}
<table>
    <tr>
        <td><a href="../index.html"><img src="../home.png"></a></td> <!-- GO BACK TO HOMEPAGE -->
        <td><a href="########"><img src="../artist.png"></a></td> <!-- GO TO ARTIST -->
        <td><img src="../portfolio.png"></td>
        <td><img src="../contact.png"></td>
    </tr>
    <tr>
        <td colspan="8"><img src="../logo.png"></td>
    </tr>
    <tr>
        <td colspan="8"><img src="../greenmoralesgraphic.png"></td>
    </tr>
    <tr>
        <td>
          <div class="this"><img src="nostalgia.jpg" width="400px" height="400px">
          <img src="pwersa.jpg" width="400px" height="400px">
          <img src="tag_along.jpg" width="400px" height="400px">
          <img src="tweet.jpg" width="400px" height="400px">
         </div>
       </td>
       <td> </td>
        <td></td>
        <td></td>
        
    </tr>
</table>

并更改 tr 内的 div 标签

  .this img{
      border:1px solid #f00;
    }
 
 

    <table>
        <tr>
            <td><a href="../index.html"><img src="../home.png"></a></td> <!-- GO BACK TO HOMEPAGE -->
            <td><a href="########"><img src="../artist.png"></a></td> <!-- GO TO ARTIST -->
            <td><img src="../portfolio.png"></td>
            <td><img src="../contact.png"></td>
        </tr>
        <tr>
            <td colspan="8"><img src="../logo.png"></td>
        </tr>
        <tr>
            <td colspan="8"><img src="../greenmoralesgraphic.png"></td>
        </tr>
        <tr>
            <td>
              <div class="this">
                <img src="nostalgia.jpg" width="400px" height="400px"> 
             </div>
           </td>
           <td> 
             <div class="this">
                <img src="pwersa.jpg" width="400px" height="400px">
             </div>    
             
           </td>
            <td>
             <div class="this">
               <img src="tag_along.jpg" width="400px" height="400px">
             </div>
            </td>
            <td>
              <div class="this">
                   <img src="tweet.jpg" width="400px" height="400px">
              </div>
            </td>
            
        </tr>
    </table>

关于html - 选择表格内和 div 内的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44395635/

相关文章:

javascript - Jquery Flot "plothover"事件不工作

css - 为什么css中的选择器 '+'不适用于图片?

html - &lt;input type ="search"> 不是样式

jquery - 我应该如何在单击下一个或上一个按钮并同时更改幻灯片时添加导航点的更改?

javascript - 使用 javascript 创建一个新元素

javascript - JS 和 JQuery 脚本冲突

html - firefox 菜单的不同行为

javascript - 如何使用 socket.io 包含外部 javascript 客户端?

css - 如何让动画流畅?

html - 将 iframe 对齐到标题下方