• scss


    @import引入规则

    1. @import "foo.scss";
    2. @import "foo";
    3. // 上两种都会引入 foo.scss文件
    4. @import "foo.css";
    5. @import "foo" screen;
    6. @import "";
    7. @import url(foo);
    8. // 编译为
    9. @import "foo.css";
    10. @import "foo" screen;
    11. @import "";
    12. @import url(foo);
    13. // 可以引人多个文件
    14. @import "rounded-corners", "text-shadow";
    15. // 有scss或sass文件需要引入,但不希望被编译为css文件,可以在文件名前加一个下划线,就能避免被编译
    16. // eg. _colors.scss 这样子就不会生成_colors.css文件了.
    17. @import "colors"; // 不用加下划线
    18. // 该引入的文件为 _colors.scss;
    19. // 注意:在同一个目录下不能同时存在带下划线和不带下划线的同名文件. eg. _colors.scss不能与colors.scss并存.
    20. // 嵌套引入
    21. // example.scss文件中包含
    22. .example{
    23. color:red;
    24. }
    25. #main{
    26. @import "example";
    27. }
    28. //编译后
    29. #main .example{
    30. color:red;
    31. }

    @media

    1. // 使用@media 可以冒泡到外面
    2. .sidebar {
    3. width: 300px;
    4. @media screen and (orientation: landscape) {
    5. width: 500px;
    6. }
    7. }
    8. // 编译后
    9. .sidebar {
    10. width: 300px;
    11. }
    12. @media screen and (orientation: landscape) {
    13. .sidebar {
    14. width: 500px;
    15. }
    16. }
    17. // @media的嵌套
    18. @media screen {
    19. .sidebar {
    20. @media (orientation: landscape) {
    21. width: 500px;
    22. }
    23. }
    24. }
    25. // 编译后
    26. @media screen and (orientation: landscape) {
    27. .sidebar {
    28. width: 500px;
    29. }
    30. }
    31. // 在@media中可以使用插件#{}
    32. $media: screen;
    33. $feature: -webkit-min-device-pixel-ratio;
    34. $value: 1.5;
    35. @media #{$media} and ($feature: $value) {
    36. .sidebar {
    37. width: 500px;
    38. }
    39. }
    40. // 编译后
    41. @media screen and (-webkit-min-device-pixel-ratio: 1.5) {
    42. .sidebar {
    43. width: 500px;
    44. }
    45. }

    @extend

    1. // @extend 用来扩展选择器或占位符
    2. .error {
    3. border: 1px #f00;
    4. background-color: #fdd;
    5. }
    6. .error.intrusion {
    7. background-image: url("/image/hacked.png");
    8. }
    9. .seriousError {
    10. @extend .error;
    11. border-width: 3px;
    12. }
    13. // 编译后
    14. .error, .seriousError {
    15. border: 1px #f00;
    16. background-color: #fdd;
    17. }
    18. .error.intrusion, .seriousError.intrusion {
    19. background-image: url("/image/hacked.png");
    20. }
    21. .seriousError {
    22. border-width: 3px;
    23. }
    24. // @extend可以扩展任意选择器
    25. .hoverlink {
    26. @extend a:hover;
    27. }
    28. a:hover {
    29. text-decoration: underline;
    30. }
    31. //编译后
    32. a:hover, .hoverlink {
    33. text-decoration: underline;
    34. }
    35. // 多个扩展
    36. .error {
    37. border: 1px #f00;
    38. background-color: #fdd;
    39. }
    40. .attention {
    41. font-size: 3em;
    42. background-color: #ff0;
    43. }
    44. .seriousError {
    45. @extend .error;
    46. @extend .attention;
    47. border-width: 3px;
    48. }
    49. //编译后
    50. .error, .seriousError {
    51. border: 1px #f00;
    52. background-color: #fdd;
    53. }
    54. .attention, .seriousError {
    55. font-size: 3em;
    56. background-color: #ff0;
    57. }
    58. .seriousError {
    59. border-width: 3px;
    60. }
    61. //扩展单一选择器
    62. #context a%extreme {
    63. color: blue;
    64. font-weight: bold;
    65. font-size: 2em;
    66. }
    67. .notice {
    68. @extend %extreme;
    69. }
    70. //编译后
    71. #context a.notice {
    72. color: blue;
    73. font-weight: bold;
    74. font-size: 2em;
    75. }

    @at-root

    1. //@at-root 跳出根元素
    2. .a {
    3. color: red;
    4. .b {
    5. color: orange;
    6. .c {
    7. color: yellow;
    8. @at-root .d {
    9. color: green;
    10. }
    11. }
    12. }
    13. }
    14. //编译后
    15. .a {
    16. color: red;
    17. }
    18. .a .b {
    19. color: orange;
    20. }
    21. .a .b .c {
    22. color: yellow;
    23. }
    24. .d {
    25. color: green;
    26. }

    @debug

    1. //@debug 在 Sass 中是用来调试的,当你的在 Sass 的源码中使用了
    2. //@debug 指令之后,Sass 代码在编译出错时,在命令终端会输出你设置的提示 Bug:
    3. @debug 10em+12em;
    4. //会输出
    5. //Line 1 DEBUG: 22em;

    @warn

    1. @mixin adjust-location($x, $y) {
    2. @if unitless($x) {//unitless是内置函数,判断数值是否有“单位”
    3. @warn "Assuming #{$x} to be in pixels";
    4. $x: 1px * $x;
    5. }
    6. @if unitless($y) {
    7. @warn "Assuming #{$y} to be in pixels";
    8. $y: 1px * $y;
    9. }
    10. position: relative; left: $x; top: $y;
    11. }
    12. .botton{
    13. @include adjust-location(20px, 30);
    14. }

    @error

    1. @mixin error($x){
    2. @if $x < 10 {
    3. width: $x * 10px;
    4. } @else if $x == 10 {
    5. width: $x;
    6. } @else {
    7. @error "你需要将#{$x}值设置在10以内的数";
    8. }
    9. }
    10. .test {
    11. @include error(15);
    12. }
  • 相关阅读:
    win11+vs2022配置ceres库
    多目标追踪——【Transformer】MOTR: End-to-End Multiple-Object Tracking with TRansformer
    荧光标记肽,FITC-胰高血糖素样肽-1,FITC-glucagon-like peptide-1,GLP-1
    Java Stream API详解:高效处理集合数据的利器
    选择商品属性弹框从底部弹出动画效果
    layer弹出框详细说明
    LeetCode 1879. 两个数组最小的异或值之和【记忆化搜索,状压DP,位运算】2145
    【解决方案】危化品厂区安防系统EasyCVR+AI智能监控
    Android不带电池设备文件系统配置
    《Python 计算机视觉编程》学习笔记(三)
  • 原文地址:https://blog.csdn.net/SeriousLose/article/details/128067466