1.reset.css:
html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:”}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;*font-size:100%}legend{color:#000}#yui3-css-stamp.cssreset{display:none}
2.clearfix:
常用的清除浮动方法:
方案一
.clearfix:before,.clearfix:after {content: “.”;display: block; height: 0;overflow: hidden;}
.clearfix:after {clear: both;}
.clearfix {zoom: 1;}
方案二
.clearfix:before, .clearfix:after {content:”.”;;display:table;}
.clearfix:after{clear:both;overflow:hidden;}
.clearfix{zoom:1;}
3.placeholder
Chrome浏览器(webkit)
::-webkit-input-placeholder {color: #999;}
注:webkit下在文本框获取焦点后不显示placeholder,以便使其与其他浏览器表现一致
:focus::-webkit-input-placeholder {color: transparent !important;}
Firefox浏览器
/* Mozilla Firefox 4 to 18 */
:-moz-placeholder {color: #999;}
/* Mozilla Firefox 19+ */
::-moz-placeholder {color: #999;}
IE浏览器
/* Internet Explorer 10+ */
:-ms-input-placeholder {color: #999;}
4.文本省略号:
文本超出省略号
display:block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
多行文本超出省略号
display: -webkit-box;
-webkit-box-orient: vertical;
text-overflow: ellipsis;
overflow: hidden;
-webkit-line-clamp: 2;
5.重置默认行为:
禁用鼠标
pointer-events: none;
禁止文本选中
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
自定义文本选择
::selection { background: #e2eae2; }
::-moz-selection { background: #e2eae2; }
::-webkit-selection { background: #e2eae2; }
禁用输入法
ime-mode:disabled;
隐藏IE10默认在input框输入内容后显示“X”按钮
pointer-events: none;
6.重置按键样式:
去除表单自动填充颜色(Chrome浏览器)
input:-webkit-autofill {
background-color: #FAFFBD;
background-image: none;
color: #000;
}
去除按键圆角(iPhone)
-webkit-appearance:none;
去除搜索按键(Chrome浏览器)
input[type=(search(]::-webkit-search-cancel-button,input[type=(search(]::-webkit-search-decoration{-webkit-appearance: none;}
去除数字输入框增减按键(Chrome浏览器)
input[type=(number(]::-webkit-outer-spin-button,input[type=(number(]::-webkit-inner-spin-button{-webkit-appearance: none;}
去除date类型文本框多了个叉叉清除内容的效果(Chrome浏览器)
::-webkit-clear-button {-webkit-appearance: none;}
去除按键虚线框(Firefox浏览器)
button::-moz-focus-inner,input::-moz-focus-inner{}
改变password类型input框的默认样式(IE浏览器)
::-ms-reveal{display: none; }
::-ms-reveal{background-color:#f0f3f9; }
设置默认线框距离
input {outline-offset: 4px ;}
input字体垂直居中
font-family: Tahoma,Arial, Helvetica,(Microsoft YaHei(;
7.横竖屏判断:
设备竖屏时调用该段css代码:
@media all and (orientation : portrait){
}
设备横屏时调用该段css代码:
@media all and (orientation : landscape){
}
8.全站变灰:
html{
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: url(“data:image/svg+xml;utf8,#grayscale”);
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
filter: gray;
-webkit-filter: grayscale(1);
}
未经允许不得转载:爱前端网 » web前端要知道的八款CSS代码