• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Web前端工程师必须知道的八个CSS代码

前端 开心洋葱 1971次浏览 0个评论

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代码
喜欢 (0)

您必须 登录 才能发表评论!

加载中……