css实战
actions-box
.actions-box:hover {filter: drop-shadow(0 0 2em #646cffaa);}
角标

.after::before {content: "";box-sizing: content-box;border: 1px solid;position: absolute;left: 0;border: 19px solid transparent;border-top-color: #ffffff;transform: translateX(104%) translateY(180%);display: block;z-index: 2;}.after::after {box-sizing: content-box;content: "";border: 1px solid;position: absolute;left: 0;border: 20px solid transparent;border-top-color: rgba(181, 216, 255, 0.6);transform: translateX(95%) translateY(180%);display: block;z-index: 1;}
卡片模糊
绝对定位圆角backdrop-filter:blur(8px)阴影
style深度作用选择器
项目中我们经常使用UI框架去做敏捷开发,但是关于UI设计的个性化,我们需要去覆盖组件样式,有两个方案
- 全局样式增加样式修改,去除scoped
- 深度样式选择器 = >>>
- less/sass中是 /deep/
.fuck >>> .weui-cells {// ...}
/deep/.ivu-select {width: 100%;}
垂直水平居中
行内元素
方法1
.text-box {text-align:centerline-height: 100px;height:100px;}
方法2
.father {width: 400px;border: 1px solid burlywood;height: 300px;display: table-cell;vertical-align: middle;}
所有元素
flex弹性盒子
使用flex弹性盒子布局实现子元素的垂直居中
.father {display:flex;justify-content: center;align-items: center;}
块级元素
position定位
在脱离文档流后的绝对定位,有两种垂直居中的定位方式
1、利用margin和left
.icon-play {position: absolute;top: 50%;left: 50%;margin-top: -30px; //自身高度的一半margin-left: -30px ; //自身宽度的一半width: 60px;height: 60px;line-height: 60px;text-align: center;background: rgba(0, 0, 0, 1);opacity: 0.6;border-radius: 50%;}
2、利用transform[块级元素]
transform中translate偏移的百分比就是相对于元素自身的尺寸而言的。
当使用:top: 50%;left: 50%;, 是以左上角为原点,故不处于中心位置,
translate(-50%,-50%) 作用是,往上(x轴),左(y轴)移动自身长宽的 50%,以使其居于中心位置。
与负margin-left和margin-top实现居中不同的是,margin-left必须知道自身的宽高(负自身已知宽高的一半),而translate可以在不知道宽高的情况下进行居中,tranlate()函数中的百分比是相对于自身宽高的百分比,所以能进行居中。
.content {padding:10px;background:green;color:#fff;position:absolute;top:50%;left:50%;border-radius: 5px;-webkit-transform: translate(-50%,-50%);-moz-transform: translate(-50%,-50%);transform:translate(-50%,-50%);}
3. 利用relative和transform[块级元素]
注意,在使用相对定位时,无论是否进行移动,元素仍然占据原来的空间。因此,移动元素会导致它覆盖其它框。
.father {width: 100%;height: 300px;border: 1px solid burlywood;}.son {width: 50px;height: 50px;margin: 0 auto;background: #42b983;position: relative;top: 50%;transform: translateY(-50%);border-radius: 50%;}
选中摇动动效
.lark-like-btn-flash {-webkit-animation-name: bounce;animation-name: bounce;-webkit-animation-duration: .4s;animation-duration: .4s;-webkit-animation-iteration-count: 1;animation-iteration-count: 1;}
超出一行显示省略号
white-space: nowrap;overflow: hidden;text-overflow: ellipsis;
获取盒子容器的宽高
dom.offsetWidth/offsetHeight
文本溢出解决方案
单行文字溢出方法
div {white-space: nowrap;/不换行/overflow: hidden;/隐藏后面的文字/text-overflow: ellipsis;/加省略号/width: 200px;}
多行文本溢出方法
简洁版
div {width: 200px;overflow : hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}
优化版
p {position:relative;line-height:1.4em;height:4.2em;overflow:hidden;}p::after {content:"...";font-weight:bold;position:absolute;bottom:0;right:0;padding:0 20px 1px 45px;background:url(/newimg88/2014/09/ellipsis_bg.png) repeat-y;}
