经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » SAS » 查看文章
CSS棰勫鐞嗗櫒scss/sass璇硶鍙婁娇鐢ㄦ暀绋媉CSS鏁欑▼_CSS
来源:jb51  时间:2023/1/11 8:39:19  对本文有异议

scss

scss鍦╟ss鍩虹璇硶涓婇潰澧炲姞浜嗗彉閲?(variables)銆佸祵濂?(nested rules)銆佹贩鍚?(mixins)銆佸鍏?(inline imports) 绛夐珮绾у姛鑳斤紝浣跨敤scss鍙互寰堟柟渚跨殑鎻愰珮寮€鍙戞晥鐜?br /> scss璇硶浠?code>.scss鏂囦欢鍚庣紑缁撳熬锛屽叾涓娉曟牸寮忔湁涓ょsass,scss,涓ょ璇硶鍦ㄤ功鍐欓鏍兼湁宸紓锛屽涓嬩唬鐮佹墍绀?/p>

scss

  1. .container {
  2. width: 100px;
  3. height: 100%;
  4. .nav {
  5. width: 100px;
  6. }
  7. }

sass

  1. .container
  2. width: 100px;
  3. height: 100%;
  4. .nav
  5. width: 100px;

璇硶

宓屽瑙勫垯 (甯哥敤)

scss鍏佽灏嗕竴濂梒ss鏍峰紡宓屽叆鍙︿竴濂楁牱寮忎腑锛屽灞傜殑瀹瑰櫒灏嗕綔涓哄唴灞傚鍣ㄧ殑鐖堕€夋嫨鍣紝濡備笅浠g爜

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. header {
  5. width: 100%;
  6. height: 20%;
  7. }
  8. main {
  9. width: 100%;
  10. height: 20%;
  11. }
  12. footer {
  13. width: 100%;
  14. height: 20%;
  15. }
  16. }

缂栬瘧鍚?/code>

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. }
  5. .container header {
  6. width: 100%;
  7. height: 20%;
  8. }
  9. .container main {
  10. width: 100%;
  11. height: 20%;
  12. }
  13. .container footer {
  14. width: 100%;
  15. height: 20%;
  16. }

鐖堕€夋嫨鍣?nbsp;(甯哥敤)

鏈夋椂闇€瑕佸湪鍐呭眰鏍峰紡鍐呴€夋嫨澶栧眰鐨勭埗鍏冪礌锛岄偅涔堝氨鍙互浣跨敤&绗﹀彿锛屽涓嬩唬鐮佹墍绀?/p>

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. &_header {
  5. width: 100%;
  6. height: 20%;
  7. &:hover {
  8. color: red($color: #000000);
  9. }
  10. }
  11. &_main {
  12. width: 100%;
  13. height: 20%;
  14. &:disabled {
  15. color: red;
  16. }
  17. }
  18. &_footer {
  19. width: 100%;
  20. height: 20%;
  21. &::after {
  22. position: absolute;
  23. content: '';
  24. }
  25. }
  26. }

缂栬瘧鍚?/code>

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. }
  5. .container_header {
  6. width: 100%;
  7. height: 20%;
  8. }
  9. .container_header:hover {
  10. color: 0;
  11. }
  12. .container_main {
  13. width: 100%;
  14. height: 20%;
  15. }
  16. .container_main:disabled {
  17. color: red;
  18. }
  19. .container_footer {
  20. width: 100%;
  21. height: 20%;
  22. }
  23. .container_footer::after {
  24. position: absolute;
  25. content: '';
  26. }

灞炴€х畝鍐?nbsp;(涓嶅父鐢?

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. font: {
  5. family: fantasy;
  6. size: 30em;
  7. weight: bold;
  8. }
  9. background: {
  10. image: url('xxx');
  11. size: 100%;
  12. }
  13. }

缂栬瘧鍚?/code>

  1. .container {
  2. width: 500px;
  3. height: 100px;
  4. font-family: fantasy;
  5. font-size: 30em;
  6. font-weight: bold;
  7. background-image: url('xxx');
  8. background-size: 100%;
  9. }

鍙橀噺 (甯哥敤)

scss涓娇鐢?code>$绗﹀彿瀹氫箟鍙橀噺

  • 鍏ㄥ眬鍙橀噺
    鍦╯css鏂囦欢椤堕儴瀹氫箟鐨勫彉閲忥紝涓哄叏灞€鍙橀噺
  1. $font-color: red;
  2. $font-size: 18px;
  3. $font-size-base: $font-size;
  4.  
  5. .text {
  6. color: $font-color;
  7. font-size: $font-size;
  8. }
  9.  
  10. span {
  11. font-size: $font-size-base;
  12. }

缂栬瘧鍚?/p>

  1. .text {
  2. color: red;
  3. font-size: 18px;
  4. }
  5.  
  6. span {
  7. font-size: 18px;
  8. }
  • 灞€閮ㄥ彉閲?br /> 鍦ㄥ睘鎬у唴瀹氫箟鐨勫彉閲忎负鍧楃骇鍙橀噺
  1. .text {
  2. $font-color: red;
  3. $font-size: 18px;
  4. $font-size-base: $font-size;
  5. h1 {
  6. color: $font-color;
  7. font-size: $font-size;
  8. span {
  9. color: $font-color;
  10. font-size: $font-size;
  11. }
  12. }
  13. }

缂栬瘧鍚?/p>

  1. .text h1 {
  2. color: red;
  3. font-size: 18px;
  4. }
  5. .text h1 span {
  6. color: red;
  7. font-size: 18px;
  8. }

杩愮畻 (甯哥敤)

scss涓敮鎸?code>+ - * /杩愮畻

  1. $base-width: 10;
  2. $small-width: 30;
  3. $large-width: $base-width + $small-width;
  4.  
  5. .div {
  6. width: $large-width + px;
  7. }
  8.  
  9. .div1 {
  10. width: $small-width - $base-width + px;
  11. }
  12.  
  13. .div2 {
  14. width: $small-width * $base-width + px;
  15. }
  16.  
  17. .div2 {
  18. width: calc($small-width / $base-width) + px;
  19. }

缂栬瘧鍚?/p>

  1. .div {
  2. width: 40px;
  3. }
  4.  
  5. .div1 {
  6. width: 20px;
  7. }
  8.  
  9. .div2 {
  10. width: 300px;
  11. }
  12.  
  13. .div2 {
  14. width: 3px;
  15. }

@extend

scss鍏佽浣跨敤@extend闆嗘垚鍏朵粬鏍峰紡瑙勫垯

  1. .item {
  2. width: 100%;
  3. height: 20%;
  4. background-color: red;
  5. }
  6.  
  7. .item-1 {
  8. @extend .item;
  9. border: 1px solid blue;
  10. }
  11.  
  12. .item-2 {
  13. @extend .item;
  14. border: 2px solid blue;
  15. }

缂栬瘧鍚?/p>

  1. .item,
  2. .item-2,
  3. .item-1 {
  4. width: 100%;
  5. height: 20%;
  6. background-color: red;
  7. }
  8.  
  9. .item-1 {
  10. border: 1px solid blue;
  11. }
  12.  
  13. .item-2 {
  14. border: 2px solid blue;
  15. }

@if

褰撴潯浠舵弧瓒虫椂锛岃緭鍏ュ搴旂殑鏍峰紡

  1. p {
  2. @if 1 + 1 == 2 {
  3. border: 1px solid;
  4. }
  5. @if 5 < 3 {
  6. border: 2px dotted;
  7. }
  8. @if null {
  9. border: 3px double;
  10. }
  11. }
  12.  
  13. $type: monster;
  14. p {
  15. @if $type == ocean {
  16. color: blue;
  17. } @else if $type == matador {
  18. color: red;
  19. } @else if $type == monster {
  20. color: green;
  21. } @else {
  22. color: black;
  23. }
  24. }

缂栬瘧鍚?/p>

  1. p {
  2. border: 1px solid;
  3. }
  4.  
  5. p {
  6. color: green;
  7. }

@for

  • 璇硶涓€锛?code>@for $var from <start> through <end>浠巗tart寮€濮嬶紝鍖呭惈end
  1. @for $i from 1 through 3 {
  2. .item-#{$i} {
  3. width: 2em * $i;
  4. }
  5. }

缂栬瘧鍚?/p>

  1. .item-1 {
  2. width: 2em;
  3. }
  4.  
  5. .item-2 {
  6. width: 4em;
  7. }
  8.  
  9. .item-3 {
  10. width: 6em;
  11. }
  • 璇硶浜岋細@for $var from <start> to <end>浠巗tart寮€濮嬶紝涓嶅寘鍚玡nd
  1. @for $i from 1 to 3 {
  2. .item-#{$i} {
  3. width: 2em * $i;
  4. }
  5. }

缂栬瘧鍚?/p>

  1. .item-1 {
  2. width: 2em;
  3. }
  4.  
  5. .item-2 {
  6. width: 4em;
  7. }

鍒版杩欑瘒鍏充簬CSS棰勫鐞嗗櫒scss/sass璇硶鍙婁娇鐢ㄦ暀绋嬬殑鏂囩珷灏变粙缁嶅埌杩欎簡,鏇村鐩稿叧css棰勫鐞嗗櫒scss鍐呭璇锋悳绱㈣剼鏈箣瀹朵互鍓嶇殑鏂囩珷鎴栫户缁祻瑙堜笅闈㈢殑鐩稿叧鏂囩珷锛屽笇鏈涘ぇ瀹朵互鍚庡澶氭敮鎸佽剼鏈箣瀹讹紒

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号