平常我们编码过程中总会遇到好多听起来很简单,但是实现的时候有点挠头的需求。今天来总结一些实用的CSS属性。
1.为了不让用户复制内容,使用下面的属性禁止选择
<div unselectable="on" onselectstart="return false;">
</div>
<input id = "box" x-webkit-speech>
::-webkit-input-placeholder {
color: #999;
}
:-moz-placeholder {
color: #999;
}
::-moz-placeholder {
color: #999;
}
:-ms-input-placeholder {
color: #999;
}
4.超出长度显示省略号
.box{
display:bolck;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
#box{
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
5.强制换行和不换行
.box{
word-wrap: break-word;
word-break: normal;
}
.box{
word-break:break-all;
}
.box{
white-space:nowrap;
}
6.两端对齐
.box{
text-align:justify;
text-justify:distribute-all-lines;
text-align-last:justify;
-moz-text-align-last:justify;
-webkit-text-align-last:justify;
}
7.textarea禁止拖动
.box{resize: none;}
8.模糊遮罩效率,模糊滤镜效果
.box{
filter: blur(3px);
}
9.背景图裁剪
.box{
background-clip:border-box
}
.box1{
background-clip:padding-box
}
.box{
background-clip:content-box
}
10.优化用户滑动流畅度
.box{
-webkit-overflow-scrolling:touch;
}
11.文字排版方式
#box{
writing-mode : horizontal-tb
}
.box{
writing-mode : vertical-rl
}
.box{
writing-mode : vertical-lr
}
.box{
writing-mode : sideways-lr
}
.box{
writing-mode : sideways-rl
}
12.点击穿透
.box{
pointer-events: none;
}
13.文字模糊效果
.box{
color: transparent;
text-shadow: #111 0 0 5px;
}
14.文字空隙和单词空隙
.box{
letter-spacing:10px
}
.box{
word-spacing:10px
}
15.解决图片失真呈现的锯齿状
.box{
-ms-interpolation-mode:bicubic;
image-rendering:optimizeQuality
}