CSS常用技巧

【1】制作三角形

<style>
  .box {
    width: 0;
    height: 0;
    margin: 0 auto;
    /* 等腰直角三角: 各边框宽度一致,将上边框保留,其他边框设置为透明色 */
    border: 100px solid transparent;
    border-top: 100px solid red;
  }
</style>    

<div class="box"></div>

【2】文字超过范围显示省略号

<style>
 .box {
    width: 200px;
    height: 200px;
    /* 一下三句就是做省略的关键 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>

<div class="box"></div>

【3】超出宽度在div内左右滑动

<style>
.box {
  height: auto;
  /* 设置不换行 */
  white-space: nowrap;
  /* x轴超出可滚动 */
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid #ccc;
}
</style>

<div class="box">
  <img src="../image/logo.png" alt="">
  ...
</div>

【4】清除浮动

<style>
.box:before,
.box:after {
  content: "";
  display: block;
  clear: both;
}
</style>

<div class="box">
  <div class="left"></div>
  <div class="right"></div>
</div>

【5】背景颜色多变

<style>
.box {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 100px auto;
  background-color: #ccc;
}

.box::before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 5px;
  background: -webkit-repeating-linear-gradient(45deg, #ff6c6c 0, #ff6c6c 20%, transparent 0, 		transparent 25%, #1989fa 0, #1989fa 45%, transparent 0, transparent 50%);
  background: repeating-linear-gradient(-45deg, #ff6c6c 0, #ff6c6c 20%, transparent 0, transparent 25%, #1989fa 0, #1989fa 45%, transparent 0, transparent 50%);
  background-size: 80px;
}
</style>

<div class="box"></div>

【6】上下居中

<style>
.box {
  height: 200px;
}

.middle {
  margin-top: 100px;
  transform: translateY(-50%);
}
</style>

<div class="box">
  <div class="middle"></div>
</div>

【7】不显示滚动条但可滚动

<style>
.box {
	overflow: scroll;
}

.box::-webkit-scrollbar {
	display: none;
	width: 0 !important;
}
</style>

<div class="box"></div>

【8】更改滚动条样式

<style>
/*滚动条整体样式*/
.box::-webkit-scrollbar { 
	width: 5px; /*高宽分别对应横竖滚动条的尺寸*/
	height: 5px;
}

/*滚动条里面小方块*/
.box::-webkit-scrollbar-thumb { 
	border-radius: 5px;
	box-shadow: inset 0 0 5px #fafafa;
	-webkit-box-shadow: inset 0 0 5px #fafafa;
	background: rgba(0,0,0,.075);
}

/*滚动条里面轨道*/
.box::-webkit-scrollbar-track {
	box-shadow: inset 0 0 5px #fafafa;
	-webkit-box-shadow: inset 0 0 5px #fafafa;
	border-radius: 0;
	background: #ececec;
}
</style>

<div class="box"></div

https://www.cnblogs.com/ranyonsue/p/9487599.html

【9】去掉input、select自带样式

<style>
input {
 	width: 100%;
  outline-color: invert;
	outline-style: none;
	outline-width: 0px;
	border: none;
	border-style: none;
	text-shadow: none;
	-webkit-appearance: none;
	-webkit-user-select: text;
	outline-color: transparent;
	box-shadow: none;
}

select {
	border: 0;
  display: block;
  width: 100%;
  white-space: nowrap;
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}
</style>

【10】动画animation

<style>
.box {	
	animation: move 2.5s linear 2.5s;
}

@keyframes move {
  0% {
   ...
  }
  100% {
   ...
  }
}
</style>

<div class="box"></div>  

【11】过渡效果

<style>
.box {
  width: 200px;
  height: 20px;
  margin: 0 auto;
  border: 1px solid red;
  border-radius: 10px;
  box-sizing: border-box;
}

.son {
  width: 50%;
  height: 100%;
  border-radius: 10px;
  background-color: red;
  /* 过渡效果 */
  transition: all 1s ease-in-out 0.3s;
}

.box:hover .son {
  width: 100%;
  background-color: green;
}
</style>

<div class="box">
	<div class="son"></div>
</div>

相关推荐

  1. CSS技巧

    2024-02-20 13:24:01       31 阅读
  2. vim技巧

    2024-02-20 13:24:01       8 阅读
  3. npm命令技巧

    2024-02-20 13:24:01       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-20 13:24:01       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-20 13:24:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-20 13:24:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-20 13:24:01       18 阅读

热门阅读

  1. C++BST(二叉搜索树)应用场景

    2024-02-20 13:24:01       26 阅读
  2. Codeforces Round 928 (Div. 4) (A-E)

    2024-02-20 13:24:01       29 阅读
  3. com.google.android.material.tabs.TabLayout

    2024-02-20 13:24:01       25 阅读
  4. AI人工智能,VR虚拟现实与《黑客帝国》

    2024-02-20 13:24:01       30 阅读
  5. SpringBoot 打成jar包后如何获取jar包Resouces下的文件

    2024-02-20 13:24:01       22 阅读
  6. 使用Hutool的ExcelUtil工具导出Excel时遇到的异常

    2024-02-20 13:24:01       28 阅读
  7. nodename nor servname provided, or not known

    2024-02-20 13:24:01       26 阅读
  8. Python实用代码片段(二)

    2024-02-20 13:24:01       31 阅读
  9. 机器人能否返回原点

    2024-02-20 13:24:01       32 阅读