Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【译】我最喜欢的CSS hack #47

Open
reng99 opened this issue Sep 7, 2019 · 0 comments
Open

【译】我最喜欢的CSS hack #47

reng99 opened this issue Sep 7, 2019 · 0 comments
Labels
blog a single blog css 样式

Comments

@reng99
Copy link
Owner

reng99 commented Sep 7, 2019

有一个我已经复制粘贴5年的CSS片段:

* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }

这是我最喜欢的发明之一。

2014年,我首次在Quora上分享了它(What are the most interesting HTML/JS/DOM/CSS hacks that most web developers don't know about?),现在,我每天仍然收到有人支持这个答案的通知。

那么,这个可怕的代码片段做了什么?

它意味着当你使用布局时适用,比如:

time-01

问题是,除非页面上的元素具有纯色背景或者一张图片,否则你看不到它是如何适合布局。例如大多数的文本节点,具有透明度的图片等。

应用上面的CSS,你会看到类似(下面)的东西:

time-02

不同深度的节点使用不同的颜色。允许你查看页面上每个元素的大小,它们的边距和填充。现在,你可以容易地识别出不一致性。

参考和后话

@reng99 reng99 added blog a single blog css 样式 labels Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog a single blog css 样式
Projects
None yet
Development

No branches or pull requests

1 participant