Categories: Sass教程

Sass:媒体指令

描述

@media指令将样式规则设置为不同的媒体类型。可以将@media指令嵌套在选择器SASS中,但它会冒泡到样式表的顶层。

以下示例演示了SCSS文件中@media的使用:

media.htm

<!doctype html>
   <head>
      <title>Media directive Example</title>
      <link rel = "stylesheet" href = "media.css" type = "text/css" />
   </head>

   <body class = "container">
      <h2>Example using media directive</h2>
      <img src = "/sass/images/birds.jpg" class = "style">
   </body>
</html>

接下来,创建文件media.scss

media.scss

h2 {
   color: #77C1EF;
}

.style {
   width: 900px;

   @media screen and (orientation: portrait) {
      width:500px;
      margin-left: 120px;
   }
}

您可以使用以下命令,让SASS监视文件并在SASS文件更改时更新CSS:

sass --watch C:\ruby\lib\sass\media.scss:media.css

接下来,执行以上命令;它将使用以下代码自动创建media.css文件:

media.css

h2 {
   color: #77C1EF;
 }

.style {
   width: 900px;
}
@media screen and (orientation: portrait) {
   .style {
      width: 500px;
      margin-left: 120px;
   }
}
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

4 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

2 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago