Github: github.com/aototo/blog 博客长期更新,喜欢的朋友star一下css
outline
移除当选中input元素的时候会出现状态线An outline is a line that is drawn around elements (outside the borders) to make the element "stand out".
包裹elements 的一个线,通常设置成none 。
div {
outline: none; //通常状况下移除它
// outline: 5px dotted red; 也能够设置样式
}
复制代码
contenteditable
设置element是否可编辑<p contenteditable="true">可编辑</p>
复制代码
能够经过input, blur事件来监听element的输入和输入完后鼠标离开。html
webkit-playsinline
手机video 均可以在页面中播放,而不是全屏播放了。ios
<video src="test.mp4" webkit-playsinline="true"></video>
复制代码
设置left:0, right:0 margin: 0 auto; 就能够。缘由是2边都是0不存在边距,element就能够得出距离,并居中。
div {
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
}
复制代码
.clearfix {
zoom: 1;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
复制代码
div {
user-select: none; /* Standard syntax */
}
复制代码
* {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
复制代码
能够修改浏览器的滚动条样式。IE火狐可能不支持。
复制代码
- To apply platform specific styling to an element that doesn't have it by default
- To remove platform specific styling to an element that does have it by default
移除浏览器默认的样式,好比chrome的input默认样式,而后就能够定义须要的样式。css3
input, button, textarea, select {
*font-size: 100%;
-webkit-appearance:none;
}
复制代码
www.cnblogs.com/rubylouvre/…git
-webkit-transform: translateZ(0);
复制代码
-webkit-backface-visibility: hidden;
复制代码
-webkit-touch-callout: none;
复制代码
div {
transform: rotateY(60deg);
transform-style: preserve-3d;
}
复制代码
这个属性的存在决定你看到的元素是2d仍是3d。通常设置在包裹元素的父类上。github
.div-box {
perspective: 400px;
}
复制代码
//不换行
white-space:nowrap;
//自动换行
word-wrap: break-word;
word-break: normal;
//强制换行
word-break:break-all;
复制代码
{
box-sizing: border-box;
}
复制代码
www.w3schools.com/cssref/func…web
div {
width: calc(100% - 100px);
}
复制代码
上面的例子就是让宽度为100%减去100px的值,项目中很适用,IE9以上面试
默认开始在top, 也能够自定义方向。chrome
div {
linear-gradient(red, yellow)
}
background: linear-gradient(direction, color-stop1, color-stop2, ...);
复制代码
选择父类下第一个子节点,p元素api
p:nth-child(1) {
...
}
复制代码
使用该属性能让页面上的字体变得清晰,可是也会形成font-weight: bold 加粗变得异常。不信你试试...
div {
-webkit-font-smoothing: antialiased;
}
复制代码
img {
filter: grayscale(100%); //灰度
filter: blur(5px); //模糊
filter:brightness(200%); //高亮
filter:saturate(8); //饱和
filter:sepia(100%); //怀旧
...
}
复制代码
移动端可使用,IE兼容很差。更多请看 www.w3schools.com/cssref/css3…
这个不少面试题好像问到,但实际中我也确实使用了。
div {
border-bottom: 10px solid white;
border-right: 10px solid transparent;
border-left: 10px solid transparent;
height: 0px;
width: 0px;
}
复制代码
transparent 透明
img {
position: absolute;
clip: rect(0px,60px,200px,0px);
}
复制代码
你有兴趣能够看 tympanus.net/codrops/201…
h1 {
letter-spacing: *px; //也能够是负数
}
复制代码
关于display: box 和 display: flex,前者是2009实施,后者2012年,若是你的安卓比较老请使用display: box,可是2者的表现可能有点不一样。下面是兼容方法。
display: -webkit-box; /* Chrome 4+, Safari 3.1, iOS Safari 3.2+ */
display: -moz-box; /* Firefox 17- */
display: -webkit-flex; /* Chrome 21+, Safari 6.1+, iOS Safari 7+, Opera 15/16 */
display: -moz-flex; /* Firefox 18+ */
display: -ms-flexbox; /* IE 10 */
display: flex; /* Chrome 29+, Firefox 22+, IE 11+, Opera 12.1/17/18, Android 4.4+ */
复制代码
在animation过程当中,图片会出现模糊的状况,能够设置以下在图片上面。
transform: translate3d(0, 0, 0);
复制代码
div {
width: 100px;
position: absolute;
right: 0;
}
// 使用margin-left: auto 自动算出作左边宽度,实现内容贴右边
div {
width: 100px;
margin-left: auto;
}
复制代码
-webkit-overflow-scrolling: touch;
复制代码
后续追加...有错误的地方请指正,谢谢。
下面是一些CSS的网站,项目中也常常使用的。
Css3动画手册 Css参考手册 Anicollection 动画库 Animate 动画库 csshake 抖动很逗 字体图标 w3schools