笔记

215 阅读2分钟

常用居中css

//定位上下左右居中
center {
	position: absolute;
	top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

//定位上下居中
ct {
	position: absolute;
	top: 50%;
    transform: translateY(-50%);
}

//定位左右居中
cl {
	position: absolute;
	left: 50%;
    transform: translateX(-50%);
}

//flex 居中
.flex-x-center{
  display: flex;
  justify-content: center;
}

.flex-y-center{
  display: flex;
  align-items: center;
}

限制文字一行或两行

.twoLine {
    display: -webkit-box;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    white-space: normal;
}
.oneLine {
    display: -webkit-box;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    white-space: normal;
}

webstrom 配置less

Tools ---> file watchers

url 编码解码

item=encodeURIComponent(String)
item=decodeURIComponent(String)

移动端meta标签设置

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telphone=no, email=no"/>
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<meta name="wap-font-scale" content="no">

@media screen and (max-width:375px) and (min-width:320px) {
  
}
@media screen and (max-width: 320px) {
 
}

border 1 px

.borderTop(@size, @color) {
  &::before {
    content: "";
    box-sizing: border-box;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    border-top: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }
}

.border1px(@size, @color) {
  &::before {
    content: "";
    box-sizing: border-box;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    border: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }
}

.borderBottom(@size, @color) {
  &::after {
    content: "";
    box-sizing: border-box;
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    border-top: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }
}

.borderRight(@size, @color) {
  &::after {
    content: "";
    box-sizing: border-box;
    position: absolute;
    height: 100%;
    left: 0;
    right: 0;
    border-right: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }
}

.verticalBorder(@size, @color) {
  &::before {
    content: "";
    box-sizing: border-box;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    border-top: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }

  &::after {
    content: "";
    box-sizing: border-box;
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    border-top: @size solid @color;
    @media screen and (-webkit-min-device-pixel-ratio: 3) {
      transform: scaleY(0.33333);
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2) {
      transform: scaleY(0.5);
    }
  }
}

.setTopLine(@c: #C7C7C7) {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1px solid @c;
  color: @c;
  transform-origin: 0 0;
  transform: scaleY(0.5);
}

.setBottomLine(@c: #C7C7C7) {
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  border-bottom: 1px solid @c;
  color: @c;
  transform-origin: 0 100%;
  transform: scaleY(0.5);
}

.setLeftLine(@c: #C7C7C7) {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  bottom: 0;
  border-left: 1px solid @c;
  color: @c;
  transform-origin: 0 0;
  transform: scaleX(0.5);
}

.setRightLine(@c: #C7C7C7) {
  content: " ";
  position: absolute;
  right: 0;
  top: 0;
  width: 1px;
  bottom: 0;
  border-right: 1px solid @c;
  color: @c;
  transform-origin: 100% 0;
  transform: scaleX(0.5);
}

.setLine(@c: #C7C7C7) {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 200%;
  height: 1px;
  border: 1px solid @c;
  color: @c;
  height: 200%;
  transform-origin: left top;
  transform: scale(0.5);
}