[英]CSS opt-outs on IDs
A hopefully quick css question for you. 一个希望快速的CSS问题。
Throughout the bulk of my site I have added images in with text and given them a 10px padding along the top to make it look better, like this: 在整个网站的大部分内容中,我都在图像中添加了文字,并在顶部添加了10px的填充,以使其看起来更好,如下所示:
#zzmainContent img {padding-top: 10px;}
Now I want to add the vary occasional image, within the same < DIV>, but I don't want the padding to take effect. 现在,我想在相同的<DIV>中添加偶尔出现的图像,但我不希望填充生效。 I've created a new ID: 我创建了一个新的ID:
#icon {padding-top: -10px; vertical-align: middle;}
But it still wants to add the padding as it is still an < img>. 但是它仍然要添加填充,因为它仍然是<img>。 How can I 'opt-out' my icon id? 如何“退出”我的图标ID?
Thanks, Chris. 谢谢,克里斯。
First, if you have multiple icons within #zzmainContent
you should use a class instead of an id. 首先,如果#zzmainContent
有多个图标,则应使用类而不是ID。
If your #icon
rule comes after the img
rules, add !important
and see if that helps. 如果您的#icon
规则在img
规则之后,请添加!important
,看看是否有帮助。
Id-based rule: 基于ID的规则:
#icon {padding-top: -10px !important; vertical-align: middle !important;}
Class-based rule: 基于类的规则:
.icon {padding-top: -10px !important; vertical-align: middle !important;}
These rules both assume that the id or class is an attribute on the image itself. 这些规则都假定id或class是图像本身的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.