css - 为帖子内容中没有链接的所有图像添加边距
问题描述
我想为帖子内容中没有链接的所有图像添加边距。
.post-content img (here I need to target only the images whith no link) {
margin: 1em;
}
所有带有链接的图像都必须保留自己的边距。
请问您有 CSS 甚至 javascript 解决方案吗?
干杯
解决方案
如果<img>
是您的孩子,<div class="post-content">
则可以使用此代码。
.post-content > img {
margin: 1em;
}
因为img是在children的第一级。
但是,如果您有其他包装器,则可以使用此代码为没有链接的图像添加边距,然后重置带链接的图像的边距。
.post-content img {
margin: 1em;
}
.post-content a > img {
margin: 0; /* Or the original margin */
}
推荐阅读
- certificate - 自签名证书 bigbluebutton
- vscode-extensions - 如何在 VSCode 扩展 Webview 中显示格式化的 JSON
- elasticsearch - 检查所有索引分片已从 Elastic Search 中删除
- javascript - 如何在 JSX 中动态更新样式
- javascript - 单击时调整 div 的大小
- javascript - 如何将事件监听器分配给 React.useRef
- django - Django rest框架外键指向不同的表
- microservices - 用于 eureka 客户端的 Fargate 服务发现
- c++ - boost::filesystem::exists() 在指定文件的相对路径时失败
- windows - 为什么即使在我输入文件名后 gitignore 也不起作用?