如何使padding:auto在CSS中工作? [英] How to make padding:auto work in CSS?

查看:501
本文介绍了如何使padding:auto在CSS中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个旧项目,该项目的CSS重置已将*{ margin:0; padding:0 }应用于所有项目.现在,我的新代码不需要它,因为它依赖于Normalize.css.这并不是什么大问题,但是在某些地方,我需要同时使用两种样式.

I am working on a legacy project that has CSS Reset with *{ margin:0; padding:0 } applied to everything. Now, my new code doesn't need that as it relies on Normalize.css. This hasn't been much of a problem but at some places I need to use both styles.

如何取消重置CSS?我已经能够做*{margin:auto},它工作正常.填充也不一样.是否有等效的方法来重置填充.您如何解决这个问题?

How do I unreset my CSS? I have been able to do *{margin:auto} which works fine. The same isn't true about padding. Is there an equivalent way to reset the padding. How do you go about solving this?

推荐答案

auto不是padding属性的有效值,唯一可以做的就是从*声明中删除padding: 0;,否则只需将padding分配给相应的属性块.

auto is not a valid value for padding property, the only thing you can do is take out padding: 0; from the * declaration, else simply assign padding to respective property block.

如果从* {}中删除padding: 0;,则浏览器将对元素应用默认样式,这将为您带来意想不到的跨浏览器跨位置偏移几像素,因此最好使用**来分配padding: 0;如果您想覆盖填充,只需使用另一条规则

If you remove padding: 0; from * {} than browser will apply default styles to your elements which will give you unexpected cross browser positioning offsets by few pixels, so it is better to assign padding: 0; using * and than if you want to override the padding, simply use another rule like

.container p {
   padding: 5px;
}

这篇关于如何使padding:auto在CSS中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆