CSS 按条件加载外部 css 样式文件

2019-04-29  本文已影响0人  MrTricker

Mobile 端 和 PC 端,同一套 HTML 构架,加载不同的 css 样式文件。

一、在 HTML 中

<style href="styles_mobile.css" media="screen and (max-width:768px)" />
<style href="styles_pc.css" media="screen and (min-width:769px)" />

二、在 CSS 中

@import url("styles_mobile.css") screen and (max-width:768px);
@import url("styles_pc.css") screen and (min-width:769px);

三、扩展 CSS at-rule

at-rule 是一个条件声明。已 @ at 符号开头, 分号结尾。

1. Media Queries 媒体查询

根据媒体的类型或特征修改样式。例:

2. Media Types 媒体类型

设备的类型。除了在使用 notonly 逻辑运算符的情况下,媒体类型都是可选的。

3. Media Features 媒体特征

每个媒体特征都必须被 () 括号包围。

4. Logical Operators 逻辑运算符

可以通过 , 逗号分隔多个媒体查询到单个规则中。

上一篇 下一篇

猜你喜欢

热点阅读