单行与多行CSS格式化 [英] Single-line vs multi-line CSS formatting

查看:137
本文介绍了单行与多行CSS格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然有争议,但我听说大多数CSS开发人员喜欢多行,因为在CSS文件中可以轻松找到一个属性。但是这不会使CSS文件更大,更少的可读性整体?我想单行让你扫描CSS文件更快。任何想法?

Though it's debatable, I've heard the majority of CSS developers prefer multi-line because of the ease of which a property can be found within the CSS file. But doesn't this make the CSS file bigger and less readable on the whole? I think single-line lets you scan the CSS file much faster. Any thoughts?

推荐答案

这是一个基于你的团队决定的偏好。但是,这里是我为什么使用单行格式:

It's all a matter of preference based on what your team decides on. However, here's my take on why I use single-line formatting:

当我需要维护CSS,我最经常寻找修改现有的选择器。如果每一行的开始是一个新的选择器,而不只是更多的样式声明,它使我更容易扫描文档的选择器,我想找到。这也意味着滚动更少,找到我需要的。

When I need to maintain CSS, I'm most often looking to modify an existing selector. If the start of every line is a new selector, and not just more style declarations, it makes it easier to scan the document for the selector I want to find. It also means less scrolling to find what I need.

一旦找到我需要编辑的选择器,良好的语法高亮功能便于读取特定选择器的规则,因此我不会失去任何可读性通过将所有的样式声明放在一行上。

Once I've found the selector I need to edit, good syntax highlighting makes it easy to read the rules for a specific selector, so I don't lose any readability by having all of my style declarations on a single line.

这就是说,我不会说它有助于文件大小任何。我依靠YUI Compressor自动压缩我的CSS,而不是试图手动维护一个有效地声明的样式文档。

That being said, I wouldn't say it helps with file size any. I rely on YUI Compressor to compress my CSS for me automatically, rather than trying to manually maintain an efficiently declared style document.

这篇关于单行与多行CSS格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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