简体   繁体   English

CSS 对除图像以外的所有内容使用填充

[英]CSS use padding for all except images

I'm using flexbox to build my page and I'm using the following to apply the same rules to all elements inside an article:我正在使用 flexbox 来构建我的页面,我正在使用以下内容将相同的规则应用于文章中的所有元素:

#article-wrapper > * 
{
    flex:1 100%;
    padding:0px 20px 0px 20px;
    box-sizing: border-box;  
}

I then use media queries to change the layout but that's not the point of my problem.然后我使用媒体查询来更改布局,但这不是我的问题的重点。

Inside #article-wrapper, I have a couple of DIV elements containing text and images.在#article-wrapper 中,我有几个包含文本和图像的 DIV 元素。 With the CSS code above, everything gets a left & right padding of 20 px.使用上面的 CSS 代码,所有内容都获得了 20 px 的左右填充。 It's fine but I'd like image to have a padding of 0 px.很好,但我希望图像的填充为 0 像素。

Negative padding is not possible and applying the padding locally on each element would force me to wrap all text in负填充是不可能的,并且在每个元素上局部应用填充会迫使我将所有文本包裹在

or或者

I thought of doing this:我想这样做:

#article-wrapper > * 
{
    flex:1 100%;
    box-sizing: border-box;  
}

#article-wrapper:not(img) > * 
{
    padding:0px 20px 0px 20px;
}

But with this, images remain unaffected.但是这样,图像不受影响。

Do you see any way of creating an exception for one type of element ?您是否看到任何为一种类型的元素创建异常的方法? (images in this case) (在这种情况下的图像)

Here is an example: https://wp.laurentwillen.be/circuits/circuit-ecosse/chateau-culzean-et-drumlanring-dumfries-galloway这是一个例子: https : //wp.laurentwillen.be/circuits/circuit-ecose/chateau-culzean-et-drumlanring-dumfries-galloway

Thanks谢谢

Like so像这样

#article-wrapper > *:not(img) {
    padding:0px 20px 0px 20px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM