zoukankan      html  css  js  c++  java
  • 项目初始化CSS公共样式

    样式初始化

    不再使用​​Reset CSS​ 了, 对于有富文本 markdown解析有差异

    使用​​normalize.css​​

    • 与许多CSS重置不同,保留有用的默认值。
    • 规范各种元素的样式。
    • 更正错误和常见的浏览器不一致问题。
    • 通过细微的修改来提高可用性。
    • 使用详细注释说明代码的作用。

    直接下载:https://necolas.github.io/normalize.css/latest/normalize.css

    npm: ​​npm install --save normalize.css

     

    公共样式

    模拟了​bootstrap​​的一些class​,例如:

    // Flex 布局
    .d-flex {
      display: flex !important;
    }
    
    .d-inline-flex {
      display: inline-flex !important;
    }
    
    .flex-row {
      flex-direction: row !important;
    }
    
    .flex-column {
      flex-direction: column !important;
    }
    
    .flex-row-reverse {
      flex-direction: row-reverse !important;
    }
    
    .flex-column-reverse {
      flex-direction: column-reverse !important;
    }
    
    .flex-wrap {
      flex-wrap: wrap !important;
    }
    
    .flex-nowrap {
      flex-wrap: nowrap !important;
    }
    
    .flex-wrap-reverse {
      flex-wrap: wrap-reverse !important;
    }
    
    .flex-fill {
      flex: 1 1 auto !important;
    }
    
    .flex-grow-0 {
      flex-grow: 0 !important;
    }
    
    .flex-grow-1 {
      flex-grow: 1 !important;
    }
    
    .flex-shrink-0 {
      flex-shrink: 0 !important;
    }
    
    .flex-shrink-1 {
      flex-shrink: 1 !important;
    }
    
    .justify-content-start {
      justify-content: flex-start !important;
    }
    
    .justify-content-end {
      justify-content: flex-end !important;
    }
    
    .justify-content-center {
      justify-content: center !important;
    }
    
    .justify-content-between {
      justify-content: space-between !important;
    }
    
    .justify-content-around {
      justify-content: space-around !important;
    }
    
    .align-items-start {
      align-items: flex-start !important;
    }
    
    .align-items-end {
      align-items: flex-end !important;
    }
    
    .align-items-center {
      align-items: center !important;
    }
    
    .align-items-baseline {
      align-items: baseline !important;
    }
    
    .align-items-stretch {
      align-items: stretch !important;
    }
    
    .align-content-start {
      align-content: flex-start !important;
    }
    
    .align-content-end {
      align-content: flex-end !important;
    }
    
    .align-content-center {
      align-content: center !important;
    }
    
    .align-content-between {
      align-content: space-between !important;
    }
    
    .align-content-around {
      align-content: space-around !important;
    }
    
    .align-content-stretch {
      align-content: stretch !important;
    }
    
    .align-self-auto {
      align-self: auto !important;
    }
    
    .align-self-start {
    align-self: flex-start !important;
    }
    .align-self-end {
    align-self: flex-end !important;
    }
    .align-self-center {
    align-self: center !important;
    }
    .align-self-baseline {
    align-self: baseline !important;
    }
    .align-self-stretch {
    align-self: stretch !important;
    }

    除此之外,我也使用​​Scss​的控制指令和​​ScssScript​批量生成了一些样式, 例如:

    // 定义内外边距,历遍1-40 取其偶数和5的倍数
    @for $i from 0 through 40 {
      @if $i % 2==0 or $i % 5==0 {
        .m-#{$i} {
          margin: $i + px !important;
        }
    
        .p-#{$i} {
          padding: $i + px !important;
        }
    
        @each $short, $long in l left, t top, r right, b bottom, x (left, right),
          y (top, bottom)
        {
          @if $short==x or $short==y {
            .m#{$short}-#{$i} {
              @each $direction in $long {
                margin-#{$direction}: $i + px !important;
              }
            }
    
            .p#{$short}-#{$i} {
              @each $direction in $long {
                padding-#{$direction}: $i + px !important;
              }
            }
          } @else {
            .m#{$short}-#{$i} {
              margin-#{$long}: $i + px !important;
            }
    
            .p#{$short}-#{$i} {
              padding-#{$long}: $i + px !important;
            }
          }
        }
      }
    }

    还有​​mixin, 例如:

    @mixin clearfix {
      &:after {
        content: "";
        display: table;
        clear: both;
      }
    }
    
    @mixin scrollBar {
      &::-webkit-scrollbar-track-piece {
        background: #d3dce6;
      }
    
      &::-webkit-scrollbar {
         6px;
      }
    
      &::-webkit-scrollbar-thumb {
        background: #99a9bf;
        border-radius: 20px;
      }
    }

    差不多就到这里了,最后附上最终代码

    • index.scss
    @import './variables.scss';
    @import './mixin.scss';
    @import './transition.scss';
    @import './global.scss';
    • variables.scss
    // base color
    $blue:#324157;
    $light-blue:#3A71A8;
    $red:#C03639;
    $pink: #E65D6E;
    $green: #30B08F;
    $tiffany: #4AB7BD;
    $yellow:#FEC171;
    $panGreen: #30B08F;
    • transition.scss
    /* fade */
    .fade-enter-active,
    .fade-leave-active {
      transition: opacity 0.28s;
    }
    
    .fade-enter,
    .fade-leave-active {
      opacity: 0;
    }
    
    /* fade-transform */
    .fade-transform-leave-active,
    .fade-transform-enter-active {
      transition: all .5s;
    }
    
    .fade-transform-enter {
      opacity: 0;
      transform: translateX(-30px);
    }
    
    .fade-transform-leave-to {
      opacity: 0;
      transform: translateX(30px);
    }
    • mixin.scss
    @mixin clearfix {
      &:after {
        content: "";
        display: table;
        clear: both;
      }
    }
    
    @mixin scrollBar {
      &::-webkit-scrollbar-track-piece {
        background: #d3dce6;
      }
    
      &::-webkit-scrollbar {
         6px;
      }
    
      &::-webkit-scrollbar-thumb {
        background: #99a9bf;
        border-radius: 20px;
      }
    }
    
    @mixin relative {
      position: relative;
       100%;
      height: 100%;
    }
    
    @mixin pct($pct) {
       #{$pct};
      position: relative;
      margin: 0 auto;
    }
    
    @mixin triangle($width, $height, $color, $direction) {
      $ $width/2;
      $color-border-style: $height solid $color;
      $transparent-border-style: $width solid transparent;
      height: 0;
       0;
    
      @if $direction==up {
        border-bottom: $color-border-style;
        border-left: $transparent-border-style;
        border-right: $transparent-border-style;
      }
    
      @else if $direction==right {
        border-left: $color-border-style;
        border-top: $transparent-border-style;
        border-bottom: $transparent-border-style;
      }
    
      @else if $direction==down {
        border-top: $color-border-style;
        border-left: $transparent-border-style;
        border-right: $transparent-border-style;
      }
    
      @else if $direction==left {
        border-right: $color-border-style;
        border-top: $transparent-border-style;
        border-bottom: $transparent-border-style;
      }
    }
    
    • common.scss
     
    • ​global.scss
     
     
  • 相关阅读:
    用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目
    jvm学习笔记二(减少GC开销的建议)
    jvm学习笔记一(垃圾回收算法)
    【转】 StringUtils中 isNotEmpty 和isNotBlank的区别
    单例模式
    工厂模式
    个人项目作业
    第一次作业-热身!
    第四单元总结
    第三单元总结
  • 原文地址:https://www.cnblogs.com/izhaong/p/12154311.html
Copyright © 2011-2022 走看看