首页 > 其他分享 >CSS常用总结

CSS常用总结

时间:2023-10-09 11:01:38浏览次数:31  
标签:总结 常用 50% transform height width webkit position CSS

重置样式

html, body, ul, li, a, p, div {
  padding: 0;
  margin: 0;
  // 设置盒模型
  box-sizing: border-box;
  // 移除移动端特有的点击高亮效果
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica", "Helvetica Neue", "Tahoma", "Arial", "sans-serif";
  font-size: 14px;
}

a, a:hover {
  color: #222;
  text-decoration: none;
  transition-duration: .3s;
}

ul {
  list-style: none;
}

input {
  outline: none;
}
// 清除浮动
.clearfix:after, .clearfix:before {
  content: '';
  display: block;
  height: 0;
  line-height: 0;
  clear: both;
  visibility: hidden;
}

多余的文字显示...(默认一行)

@mixin ellipsisTxt($line:1) {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: $line;
}

遮罩层

@mixin coverMask {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  position: fixed;
  top: 0;
  left: 0;
}

关闭按钮,默认是16px

@mixin commonCloseStyle($width:16px) {
  position: absolute;
  width: $width;
  height: $width;
  right: calc(#{$width}/2);
  top: calc(#{$width}/2);
  background: transparent;
  cursor: pointer;

  &:after,
  &:before {
    content: "\a0";
    position: absolute;
    transition: .3s;
    background: #bbb;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
  }
  &:before {
    left: 0;
    top: calc(#{$width}/2);
    width: $width;
    height: 1px;
  }

  &:after {
    top: 0;
    left: calc(#{$width}/2);
    width: 1px;
    height: $width;
  }
  &:hover:after,
  &:hover:before {
    transition: .3s;
    -webkit-transform: rotate(225deg);
    transform: rotate(225deg);
  }
}

滚动条

@mixin scrollStyle($height:400px) {
  height: $height;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  // 滚动条宽
  &::-webkit-scrollbar {
    width: 4px;
    border-radius: 10px;
  }
  // 滚动条 背景槽
  &::-webkit-scrollbar-track {
    border-radius: 10px;
    background-color: #C1CAD2;
  }
  // 滚动条 拖动条
  &::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: #889098;
  }
}

垂直居中显示

@mixin centerBlock {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

设置对象 变大变小

.btnKaihu {
  width: 405px;
  height: 112px;
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-animation: bouncedelay 1.2s infinite;
  animation: bouncedelay 1.2s infinite;
}
    
@keyframes bouncedelay {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    -webkit-transform: scale(0.8);
  }
  40% {
    transform: scale(1.0);
    -webkit-transform: scale(1.0);
  }
}

遮罩层 内容垂直水平居中 显示

1. html设置
<div class="dialog_module">
  <div class="contArea">
    <div class="content">内容显示</div>
    <img src="/template/web/skin/default/images/close.png" class="btnClose">
  </div>
</div>

2. scss样式设置
.dialog_module {
  width: 100%;
  height: 100%;
  background: #00000060;
  position: fixed;
  z-index: 10;

  .contArea {
    width: 300px;
    height: 300px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    border-radius: 6px;

    .content {
      font-size: 30px;
    }

    .btnClose {
      width: 40px;
      height: 40px;
      cursor: pointer;
      position: absolute;
      right: -60px;
      top: 0;
    }
  }
}

image

图片onerror设置

<img src="" one rror="this.src='/template/web/skin/default/images/errorImg.png'">

css样式修改背景图

&:hover {
    img {
        content: url("/skin/default/images/default.svg");
    }
}

标签:总结,常用,50%,transform,height,width,webkit,position,CSS
From: https://www.cnblogs.com/songxia/p/17750981.html

相关文章

  • CSS单位
    CSS常用长度单位px:相对长度单位相对于显示器屏幕分辨率rem:相对长度单位对于根元素(即html元素)font-size计算值的倍数html{font-size:14px;那么14px=1rem28px=2rem即:npx=n/14rem}h3{font-size=2rem;//转换为px即是2*12=24px}vw和vh移动端......
  • Vue学习笔记(七):绑定css样式
      1绑定class样式¶vue为HTML绑定css中的class样式是通过v-bind实现的。  1.1绑定单个class¶把需要绑定的样式class名赋值给一遍变量,然后通过变量v-bind绑定class属性,绑定后的class并不会覆盖原来的class属性,而是与原来的class进行叠加。如下所示,d......
  • 使用postcss-px-to-viewport实现兼容
    为提高页面的兼容性,可使用postcss-px-to-viewport。1.安装依赖"postcss-px-to-viewport":"^1.1.1"2.在vite.config.js导入importpostcssPxToViewportfrom'postcss-px-to-viewport';3.增加css配置,示例如下returndefineConfig({plugins:[vue(),buildTi......
  • docker常用命令
    docker网络相关设置常见的网络模式有:bridge:默认网络模式,容器和主机在同一个子网中,可以通过IP地址相互访问。host:容器和主机共享一个网络命名空间,容器直接使用主机的网络接口。none:容器没有网络接口,无法进行网络通信。container:容器和另一个容器共享同一个网络命名......
  • git常用命令
    要配置Git的用户名和密码,您可以使用以下命令:设置用户名:gitconfig--globaluser.name"YourName"设置用户邮箱:gitconfig--globaluser.email"[email protected]"设置用户密码缓存:gitconfig--globalcredential.helpercache这将在10分钟内缓存您的密码......
  • Docker 安装 Redis 单机&集群总结
    前言Redis是一个开源的使用ANSIC语言编写、遵守BSD协议、支持网络、可基于内存、分布式、可选持久性的键值对(Key-Value)存储数据库redis版本:redis:6.2.13作者:易墨安装单机版安装源:DockerHub默认配置文件:配置文件示例6.2运行时指定配置文件docke......
  • PHP的错误机制总结
    PHP的错误机制总结PHP的错误机制也是非常复杂的,做了几年php,也没有仔细总结过,现在就补上这一课。特别说明:文章的PHP版本使用5.5.32PHP的错误级别https://www.clw9335.com/rj/首先需要了解php有哪些错误。截至到php5.5,一共有16个错误级别注意:尝试下面的代码的时候请确保打开er......
  • css - 脱离文档流
    CSSposition定位&z-index层级1.定位position:(1).相对定位relative:元素相对定位:a.相对于元素在文档流中原本的位置定位的b.不脱离文档流c.如果不设置偏移量,元素不会发生任何变化不改变元素性质(块级/内联元素)(2).绝对定位absolute:绝对定位的元素:a.相对于最近开启......
  • OSPF常用配置和常用的查看命令
    转载请注明出处:1.启动OSPF进程,进入OSPF视图。[Huawei]ospf[process-id|RouterIDRouterID]路由器支持OSPF多进程,进程号是本地概念,两台使用不同OSPF进程号设备之间也能够建立邻接关系。2.创建并进入OSPF区域视图[Huawei-ospf-1]areaarea-id在OpenShor......
  • 2023-2024-1 20231407陈原《计算机基础与程序设计》第2周学习总结
    作业信息这个作业属于哪个课程<2023-2024-1-计算机基础与程序设计>这个作业要求在哪里<2023-2024-1计算机基础与程序设计第二周作业>这个作业的目标<熟练掌握《计算机科学概论》第一章,熟悉《C语言程序设计》第一章>作业正文https://www.cnblogs.com/CCCY12345/p/......