我想通过 id 'reg' 引用我容器中的一个图像而不更改其他图像的属性,我该怎么做?
<div class="two_third lastcolumn">
<div class="container clients">
<div class="one_sixth"><a href="userProfile.php"><img src="../../images/reg.png" alt="" id="reg"/></a></div>
<div class="one_sixth"><a href="../../community/feedback.php"><img src="../../images/feedback.png" alt=""/></a></div>
<div class="one_sixth"><a href="../../resources/donation.php"><img src="../../images/donate.png" alt=""/></a></div>
<div class="one_sixth"><a href="userProfile.php"><img src="../../images/oneyear.png" alt=""/></a></div>
</div>
</div>
我猜是这样的
.clients img #reg {
...
}
最佳答案
您实际上不需要使用所有这些选择器。
index.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div>
<div class="clients">
<div><a href="#"><img src="a.png.png" id="small" alt=""/></a></div>
<div><a href="#"><img src="b.png.png" alt=""/></a></div>
</div>
</div>
</body>
</html>
样式.css
img {
width: 200;
height: 200;
}
#small {
width: 150;
height: 150;
}
如果您需要进一步指定,不要将类“clients”分配给 div,而是像这样将其应用于每个 img,不要有空格。 引用:How to combine class and ID in CSS selector?
index.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div>
<div><a href="#"><img src="a.png.png" alt=""/></a></div>
<div class="clients">
<div><a href="#"><img src="a.png.png" class="clients" id="small" alt=""/></a></div>
<div><a href="#"><img src="b.png.png" class="clients" alt=""/></a></div>
</div>
</div>
</body>
</html>
样式.css
img {
width: 100;
height: 100;
}
img.clients {
width: 200;
height: 200;
}
img.clients#small {
width: 150;
height: 150;
}
关于CSS 引用容器内的 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34169800/