CSS中带有或不带有'px'后缀的零像素大小? [英] Size of zero pixels in CSS with or without 'px' suffix?

查看:407
本文介绍了CSS中带有或不带有'px'后缀的零像素大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在CSS中,我已经看到零像素声明为简单的0 '也为'0px'。

  mystyle {width:0; } 

anotherstyle {width:0px; }

'0'的小问题是,如果将其更改为非零值,你可能会忘记添加'px'。当值为'0'时,你可能会忘记删除'px'。我想在我的代码中的纯一致性和这样的小东西驱动我坚果。



这真的来自个人偏好,如何缩进?



他们似乎都工作,但是哪种更好,为什么?



谢谢。






清除编辑





没有px的0是我所指的是。



它让我坚持,有两种不同的方式做同样的事情。 $ b

就个人而言,尽管在适当的情况下忘记添加/删除px的小问题,我将继续使用'0',知道它与其他方式一样可接受。

$ b $



使用 width:0

特别是当你有,例如:



<$> p $ p> padding:0px 0px 9px 8px

vs

  padding:0 0 9px 8px 

查看规格


长度值的格式(表示为
,由< length>在本说明书中)是
a< number> (具有或不具有十进制
点),紧接着是单元
标识符(例如,px,em等)。
长度为零后,单位标识符是可选的。








'0'的小问题是,如果
将其更改为非零值
,则可能会忘记添加'px' 。和
当值为'0'时,你可以
忘记删除'px'


在没有单元标识符的情况下写入 0 的习惯不会发生。


Googling for the answer to this question has proven difficult so I figured somebody here should know.

Within CSS, I've seen zero pixels declared as simply '0' yet also as '0px'.

mystyle { width: 0; }

anotherstyle { width: 0px; }

The minor problem with '0' is that if you change it to some non-zero value, you might forget to add the 'px'. And when making a value '0', you may forget to remove the 'px'. I want pure consistency in my code and little things like this drive me nuts.

Does this really come down to a personal preference like where to indent?

They both seem to work but which way is better and why?

Thank-you.


EDIT for clarity:

I wrote "little things like this drive me nuts".

Not having a "px" for 0 is not what I was referring to.

It drives me nuts that there are two different ways of doing the same simple thing.

Personally, despite the minor issue of forgetting to add/remove 'px' where appropriate, I'll continue using '0' by itself knowing it's just as acceptable as the other way.

解决方案

They are identical.

Use width: 0, because it is shorter and more readable.

Especially when you have, for example:

padding: 0px 0px 9px 8px

vs

padding: 0 0 9px 8px

See the specs:

The format of a length value (denoted by <length> in this specification) is a <number> (with or without a decimal point) immediately followed by a unit identifier (e.g., px, em, etc.). After a zero length, the unit identifier is optional.


The minor problem with '0' is that if you change it to some non-zero value, you might forget to add the 'px'. And when making a value '0', you may forget to remove the 'px'

This does not happen once you get into the habit of writing 0 without the unit identifier.

这篇关于CSS中带有或不带有'px'后缀的零像素大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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