简体   繁体   English

以HTML链接CSS文件

[英]Linking CSS Files in HTML

Is it a good practice to use two to three stylesheets for a web design. 在网页设计中使用两到三个样式表是一个好习惯。 1. framework that we are using, 2. Main stylesheet 3. Responsive stylesheet which would have media queries. 1.我们正在使用的框架,2.主样式表3.带有媒体查询的响应式样式表。 How does it matter if we put media queries into the main stylesheet? 如果将媒体查询放入主样式表有什么关系? Is there a difference in performance? 性能上有区别吗? What are the pros and cons of embedding 2 stylesheets instead of one? 嵌入2个样式表而不是一个样式表的利弊是什么?

Loading multiple stylesheets: 加载多个样式表:

  • Requires more HTML 需要更多HTML
  • Requires more HTTP requests 需要更多HTTP请求

Unless you are frequently changing one of them, you will always get better performance by having them in a single file (this may change with HTTP2). 除非您经常更改其中之一,否则将它们放在单个文件中将始终获得更好的性能(这可能会因HTTP2 改变)。

The only benefits to having them in separate files is for ease of development, but you should combine them at build time. 将它们放在单独的文件中的唯一好处是易于开发,但是您应该在构建时将它们组合在一起。

I'll recommend using CSS preprocessors, such as LESS/SASS. 我建议使用CSS预处理程序,例如LESS / SASS。

Those allow additional leverage over CSS by providing additional syntax that delivers lots of advantages: 通过提供具有许多优点的附加语法,它们可以比CSS更好地利用:

  • List item 项目清单
  • Nested syntax 嵌套语法
  • Ability to define variables 定义变量的能力
  • Ability to define mixins 定义混合的能力
  • Mathematical functions 数学函数
  • Operational functions (such as “lighten” and “darken”) 操作功能(例如“变亮”和“变暗”)
  • Joining of multiple files and compressing final result 连接多个文件并压缩最终结果

You can read more about this here: Advantages of preprocessors 您可以在此处了解更多信息: 预处理器的优势

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM