有没有替代 CSS 的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/925653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:38:57  来源:igfitidea点击:

Is there an alternative to CSS?

css

提问by JustADude

Is there a style sheet formatting language alternative to CSS? Or is CSS the current single language for doing Style Sheet formatting type things?

是否有替代 CSS 的样式表格式语言?或者 CSS 是当前用于处理样式表格式化类型的单一语言吗?

I looked at the write up of CSS on Wikipedia (http://en.wikipedia.org/wiki/Cascading_Style_Sheets) and a few other comments about CSS and became discouraged about the lack of full support for CSS in the different Layout engines, so I am just curious if there is an alternative or I must learn to also use CSS filters.

我查看了 Wikipedia ( http://en.wikipedia.org/wiki/Cascading_Style_Sheets) 上关于 CSS 的文章以及其他一些关于 CSS 的评论,并对不同布局引擎中缺乏对 CSS 的全面支持感到沮丧,所以我只是好奇是否有替代方案,或者我必须学会也使用 CSS 过滤器。

Thanks for any insights.

感谢您提供任何见解。

采纳答案by Dan Herbert

CSS is the only real option.

CSS 是唯一真正的选择。

Browser support for CSS should not be a major concern (in most cases) once you learn the ins & outs of CSS. The key to understand about CSS is that its purpose is to define the style of an HTML document and it should be separate from the content.

一旦您了解了 CSS 的来龙去脉,浏览器对 CSS 的支持就不应该成为主要问题(在大多数情况下)。理解 CSS 的关键在于它的目的是定义 HTML 文档的样式,并且它应该与内容分开。

You'll need practice in learning how to make things degrade gracefully in browsers that don't support features. The basic idea here is that you should make the lowest common denominator (Internet Explorer usually) work "good enough" that it doesn't take away from the user experience, and provide the niceties for users with better browsers. Also, don'tdevelop for Internet Explorer first. Leave it until last, then fix its bugs. Doing things the other way around (IE first) is much harder.

您需要练习学习如何在不支持功能的浏览器中优雅地降级。这里的基本思想是,您应该使最低公分母(通常为 Internet Explorer)工作“足够好”,不会影响用户体验,并为使用更好浏览器的用户提供细节。另外,不要先为 Internet Explorer 开发。把它留到最后,然后修复它的错误。反过来(IE优先)做事要困难得多。

You also have the option of using JavaScript to set styles, but that is not recommended because you should avoid applying styles within JavaScript since JavaScript is meant for logic, not styles.

您还可以选择使用 JavaScript 来设置样式,但不建议这样做,因为您应该避免在 JavaScript 中应用样式,因为 JavaScript 用于逻辑,而不是样式。

There are 3 (depending how you look at it) components to a web page:

一个网页有 3 个(取决于你如何看待它)组件:

  • HTML- for content
  • CSS- for styling your content
  • JavaScript- for applying additional or dynamic logic to your content
  • HTML- 用于内容
  • CSS- 用于样式化您的内容
  • JavaScript- 用于将附加或动态逻辑应用于您的内容

回答by Rolf

You guys are all trying to answer the question from a programmer's perspective. I think the original poster was looking for an alternative which is more graphic-friendly - one that would offer a different concept.

你们都试图从程序员的角度来回答这个问题。我认为最初的海报正在寻找一种对图形更友好的替代方案 - 一种可以提供不同概念的替代方案。

Even if CSS3 gets adopted cross browser, I believe that the CSS way of laying out stuff (inline box, floats, margins, etc) is awful. I am a programmer, but my father is a graphic designer, and I am pretty sure that the layout software they were using 20 years was in some aspects easier and more advanced than CSS.

即使 CSS3 被跨浏览器采用,我相信 CSS 布局东西(内联框、浮动、边距等)的方式很糟糕。我是一名程序员,但我父亲是一名平面设计师,我很确定他们使用了 20 年的布局软件在某些方面比 CSS 更容易和更先进。

回答by Camilo Martin

Yesthere is, it's called LESSand it really adresses most CSS's code readability problems.

的,它被称为LESS,它确实解决了大多数 CSS 代码可读性问题。

You can both compile it on the server or on-the-fly client-side with less.js.

你既可以在服务器上编译它,也可以在客户端使用less.js编译它。

For production, I recommend setting up a build script that compiles it (in NodeJSthis is piece of cake with Gruntand grunt-contrib-less).

对于生产,我建议设置一个编译它的构建脚本(在NodeJS 中,这是使用Gruntgrunt-contrib-less的小菜一碟)。



Edit:There are also other options worth mentioning, even if I'm using and recommending LESS.

编辑:还有其他值得一提的选项,即使我正在使用和推荐 LESS。

SASS: Ruby folks love this one. It is not a super-set of CSS like LESS, but instead uses its own syntax. To cope up for this, they developed SCSS, which isa CSS super-set and is similar to LESS.

SASS:Ruby 的人喜欢这个。它不是像 LESS 那样的超集 CSS,而是使用自己的语法。为了解决这个问题,他们开发了 SCSS,它一个 CSS 超集,类似于 LESS。

Stylus: like LESS, it is coded in javascript, but this is commonly used from Node.js. I can't vouch for it, since I didn't try it out yet, but it is very mature so if it has a feature you want, definitely go for it.

Stylus:和 LESS 一样,它是用 javascript 编码的,但这通常是从 Node.js 使用的。我不能保证它,因为我还没有尝试过,但它非常成熟,所以如果它有你想要的功能,一定要去做。

Turbine: This one was coded in PHP. Not much traction.

涡轮机:这个是用 PHP 编码的。没有太大的牵引力。

Switch CSS: Maybe Python hackers will want to look into this. Even less traction.

切换 CSS:也许 Python 黑客会想要研究这个。甚至更少的牵引力。

If you're feeling even more alternative, there's also CSS Cacheer, CSScaffold, DtCSS, CSSPPand even somethingby porneL.

如果你觉得还有更多选择,还有CSS CacheerCSScaffoldDtCSSCSSPP,甚至还有一些来自porneL 的东西



Other stuff you might want to check out:

您可能想查看的其他内容:

Compass: A full-on CSS authoring framework for the Ruby guys.

Compass:一个完整​​的 CSS 创作框架,供 Ruby 爱好者使用。

WinLESS: A drag&drop LESS compiler for Windows, it's super cool and you really should check it out.

WinLESS:适用于 Windows 的拖放式 LESS 编译器,它非常酷,您真的应该检查一下。

LESS Elements, Preboot, LESSHatand even.less: Libraries of mixins and constants for LESS.

LESS ElementsPrebootLESSHateven.less:LESS 的 mixin 和常量库。

Bootstrap: A framework developed by Twitter. Also related: HTML5 Boilerplate.

Bootstrap:由 Twitter 开发的框架。还相关:HTML5 Boilerplate

Normalize.css: an alternative to CSS resets. There are many resets, however, as the developer of one, I have to say: most are crap. If you're not going to make your own, then just use this one.

Normalize.css:替代CSS 重置。有很多重置,但是,作为其中一个的开发者,我不得不说:大多数都是废话。如果你不打算自己做,那就用这个吧。



Update: Since 1.4, LESS has @extendtoo. Be sure to use 1.4+ if possible! This completes the reasons to choose LESS over SASS I think.

更新从 1.4 开始,LESS 也有@extend。如果可能,请务必使用 1.4+!这完成了我认为选择 LESS 而不是 SASS 的原因。

回答by Patrick McElhaney

Yes.

是的。

As everyone else said, CSS is your only real option, but there is another language for "style sheet formatting type things"on the web, called eXtensible Stylesheet Language (XSL), particularly the subset of the spec that became known as XSL-FO (formatting objects).

正如其他人所说,CSS 是您唯一真正的选择,但在 Web 上还有另一种用于“样式表格式化类型”的语言,称为可扩展样式表语言 (XSL),尤其是后来被称为XSL-FO的规范子集(格式化对象)

At one point, depending on who you asked, it was intended to compete or collaborate with CSS.

在某一时刻,取决于你问的是谁,它旨在与 CSS 竞争或合作

回答by Scoregraphic

Wide-spread CSS does not get full support in all browsers...how should an (unknown) alternative reach this goal?

广泛使用的 CSS 并未在所有浏览器中获得完全支持……(未知的)替代方案应该如何实现这一目标?

回答by EFraim

Well, CSS 2.1 is pretty well supported by nearly every browser. (except IE6) It's easy to write gracefully-degraded CSS once you know the safe subset. (So that even unsupporting browsers won't totally mess the page up)

好吧,几乎所有浏览器都非常支持 CSS 2.1。(IE6 除外)一旦您知道安全子集,就很容易编写优雅降级的 CSS。(这样即使是不支持的浏览器也不会完全弄乱页面)

See http://www.quirksmode.orgfor CSS browser compatibility hints.

有关CSS 浏览器兼容性提示,请参阅http://www.quirksmode.org

回答by Sam Adamsh

Grid stylesheets (GSS) : GSS

网格样式表 (GSS) : GSS

way better

更好的方式

回答by hasen

became discouraged about the lack of full support for CSS in the different Layout engines

对不同布局引擎中缺乏对 CSS 的全面支持感到气馁

I think jQuery has some ways to make css more compatible across-browsers, i.e. if you specify some attributes using jQuery then it will try to make sure to use a work-around for browsers that don't support certain features.

我认为 jQuery 有一些方法可以使 css 跨浏览器更兼容,即如果您使用 jQuery 指定某些属性,那么它将尝试确保对不支持某些功能的浏览器使用变通方法。

There's also a project called CleverCSS, you might want to check it out. It's not an alternative to it though, just a slightly different way to define it.

还有一个名为CleverCSS的项目,您可能想查看一下。不过,它不是它的替代品,只是定义它的方式略有不同。

回答by Marcus Downing

I looked at the write up of CSS on Wikipedia (http://en.wikipedia.org/wiki/Cascading_Style_Sheets) and a few other comments about CSS and became discouraged about the lack of full support for CSS in the different Layout engines, so I am just curious if there is an alternative or I must learn to also use CSS filters.

我查看了 Wikipedia ( http://en.wikipedia.org/wiki/Cascading_Style_Sheets) 上关于 CSS 的文章以及其他一些关于 CSS 的评论,并对不同布局引擎中缺乏对 CSS 的全面支持感到沮丧,所以我只是好奇是否有替代方案,或者我必须学会也使用 CSS 过滤器。

CSS is thestandard. There is no alternative.

CSS是标准。没有替代。

All browsers support the basic CSS features. Each new version of each of the (four?) main browser lines comes with increased support for the standard, but websites that use these features will be broken to any users in an earlier version. There are two answers to this:

所有浏览器都支持基本的 CSS 功能。每个(四个?)主要浏览器系列的每个新版本都增加了对标准的支持,但是使用这些功能的网站将被早期版本的任何用户破坏。对此有两个答案:

  1. "Graceful degredation" (or its twin, "Progressive enhancement" - google it), in which the page takes advantage of advanced features if they're available, while still continuing to work if they're not.

  2. Who are your audience? If you're lucky enough to know that 99.8% of visitors to your website will be using at least IE7, then you don't need to worry about the CSS features that are broken in IE6. This will depend on your own business though, so check the facts first.

  1. “优雅降级”(或它的双胞胎,“渐进增强” - 谷歌它),其中页面利用可用的高级功能,而如果它们不可用,则仍然继续工作。

  2. 你的听众是谁?如果您有幸知道 99.8% 的网站访问者将至少使用 IE7,那么您就不必担心 IE6 中损坏的 CSS 功能。不过,这将取决于您自己的业务,因此请先检查事实。

The worst thing you can do is code to the quirks of a single specific browser, because that leads to a page that's broken not only on other browsers, but even on later versions of the same browser.

您可以做的最糟糕的事情是针对单个特定浏览器的怪癖进行编码,因为这会导致页面不仅在其他浏览器上损坏,甚至在同一浏览器的更高版本上也损坏。