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>

  • 10
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值