如果你手上有魔棒,你会发出什么的魔咒,让 CSS 按照你的想法走?另外,还有什么你想搞进来的,而且又会受到大家欢迎的?
If you could wave a magic wand, which bit of current CSS would you banish from the world, and what would you magically add and implement everywhere?
首先,我会把浏览器专属特定的代码干掉,像 <!--[if lt IE 7 ]> 诸如此类的。CSS 里面没有这样浏览器特定的代码——尽管不提供,但是也不要用“注释”这样子的风格呈现,而且这样子是“反” Web 标准的。
I’d banish browser-version-specific code like: <!--[if lt IE 7 ]> . While technically not expressed in CSS, these kinds of “comments” should not be necessary and they lower the standards of the web.
你的第二个问题,我觉得是个有意思的问题,啥东西突然叫好又叫座?2006 年,我想是非 Web fonts 莫属。2007 年,我会说 <video> 元素(<video> 元素冒进来 HTML 已经一段时间了)。而时至今日,各家浏览器都支持好这些特性了。
The second part of your question is even more interesting: what parts of CSS should be magically implemented everywhere? In 2006, I would have said web fonts. In 2007, I would have said the element (straying into HTML-land for a while). Both of these are now implemented in all browsers.
2011 年,我看到 app 用户是以 页 的方式,而不是以 滚动 的方式浏览内容的。于是我提倡 Web 内容页面化。什么是页面化?就是把很长的一段内容自动划分到不同的页面,用户通过手势看完一页又翻到下一页,或者按 PageUp/PageDown——这不就是浏览器里的电子书嘛~不过我希望可以更简单些。这就是我想的魔咒啦~哈哈。
In 2011, seeing that many apps used pages (and not scrollbars) to create compelling presentations, I started advocating for web pages to become real pages. The idea is that the style sheet would trigger paged mode so that content is split into pages. Users would navigate from one page to the next with gestures, or perhaps with PageUp and PageDown. I want it to be possible, even easy, to create ebook-readers in browsers. For this to happen, a bit of magic would be helpful. Could you sprinkle some fairy dust on the pillows of all browser vendors, please?
CSS 不仅仅为浏览器而设的。2005 年的时候,我和 Bert 合著了一本关于 CSS 的书。第三版的时候,我们就想,看看能不能在写书的过程中,就用 CSS 来编写(译注:定义格式之类的)。后来,神器 Prince 出现了! Michael Day 和墨尔本的伙伴发明了这种好东西,可以把 PDF 里文档采用 HTML/CSS 来定义,简直是神器!然后发送到打印机打印,毫无问题!于此期间,我发现了 Prince 的若干 bug。为此,我还参与 Prince 的开发。Prince 已经导出了上百本书籍了。我相信,未来仍然有相当的纸质书,不过稍有点不同的是,纸质书被印刷之前,它们采用 HTML/CSS 定义格式。
But CSS is not just for browsers. Bert and I wrote a book on CSS and in 2005, for the third edition, we wanted to use CSS itself for formatting. The browsers were not up to the job, but then Prince came along. Michael Day and his colleagues in Melbourne made a terrific product which was able to create a beautiful PDF document from HTML and CSS which we could send to the printer. In order to them to fix my favorite bugs, I joined the board of directors. Prince has since been used to format hundreds of books. We will still have some paper books in the future, I believe. And they will be made from HTML and CSS.
Why do we still not have a method of laying out pages in CSS that doesn’t require a Doctorate in Rocket Surgery? (I’m looking at you, Flexbox…)
布局是个复杂的话题,而且鉴于多种多样的显示设备,Web 之上的布局更显复杂。针对内容,CSS 有几种不同的布局机制:绝对布局,浮动,多列布局,Table 布局等。它们之间的嵌套更是复杂,但我不认为 doctorate 是需要的。我必须承认
Layout is complex, and layout on the web is even more complex due to pages being displayed on so many different devices. CSS has several mechanisms for laying out content, including absolutely positioned elements, floats, multi-column layout, and CSS tables. The interaction between them can be complex, but I don’t think any doctorate is needed. I must admit to not having used Flexbox much, though.
你对诸如 SASS 和 LESS 这类预处理器的看法是如何?CSS 应该从中汲取些什么优点?What’s your opinion on pre-processors like SASS and LESS? Does CSS have anything to learn from them?
是的,预处理器是好东西。我们应该把预处理器好的东西进行“拿来主义”来改造 CSS 本身。我个人最喜欢内嵌选择器,呃,还有单行注释吧(//……)。卖个关子,到 CSS 50周年的时候我告诉为啥一开始 CSS 没单行注释。Yes, pre-processors make a lot of sense. We should probably take the five or so most popular features from pre-processors and add them to CSS itself. My own favorites would be nested selectors, and single-line comments (starting with //). When CSS turns 50 I’ll tell you why they were not part of CSS from the beginning.