1. 程式人生 > 實用技巧 >CSS重置預設樣式reset.css程式碼模板

CSS重置預設樣式reset.css程式碼模板

由於各大瀏覽器存在相容性問題,同一個css屬性在不同瀏覽器下的表現不一定相同,有經驗的前端設計者都會自定義一個重置瀏覽器樣式的css檔案,在這個檔案中定義一些針對不同的瀏覽器最終表現出一致的程式碼,大家最熟悉的也許就是* {margin:0 0}了,其實這是最簡單的相容性的程式碼,一般情況下,僅有這個是不夠的,因此筆者收集了幾個前端設計網站使用的reset.css程式碼模板,如果需要你可以複製這些程式碼儲存為reset.css檔案,然後引用在所需的html檔案中即可。

注意:您可以根據您自己的實際情況去修改程式碼中選擇器的定義,如果確定用不上程式碼中對某些選擇器的定義,可以刪除掉。

CSS重置瀏覽器樣式程式碼一:

body,ul,li,p,h1,h2,h3,h4,h5,h6,img,br,hr,table,tr,td,dl,dt,dd,form {
	margin: 0;
	padding: 0;
}
body {
	font-family: Arial,"微軟雅黑";
	font-size: 12px;
	color: #434343;
}
.clear {
	clear: both;
	font-size: 0px;
}
ul,li {
	list-style: none;
}
img {
	border: none;
}
/*一般連結*/
a {
	text-decoration: none;
	color: #555;
}
a: hover {
	color: #3366ff;
}

電腦刺繡繡花廠 http://www.szhdn.com 廣州品牌設計公司https://www.houdianzi.com

CSS重置瀏覽器程式碼二:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td { background: transparent; border: 0; margin: 0; padding: 0; vertical-align: baseline; font-size: 100%; font: inherit; -webkit-text-size-adjust: none; }
body { line-height: 1; }
table { border-collapse: collapse; border-spacing: 0; }
object, :focus { outline: none; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section /* HTML 5 */ { display: block; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ‘‘; content: none; }
a img { border: none; }
input,button,textarea,select,optgroup,option{ font-size: 100%; font: inherit; }
.al { text-align: left; }
.ar { text-align: right; }
.ac { text-align: center; }
.lc { margin: 0 auto; }
.fl, .il .fl { float: left; }
.fr, .il .fr { float: right; }
.fc, .il .fc { float: none; clear: both; }
.rel { position: relative; }
.abs { position: absolute; }
.il { list-style: none; }
.il li { float: left; }

CSS重置瀏覽器程式碼三:來自Eric Meyer網站:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-weight: inherit;
	font-style: inherit;
	font-size: 100%;
	font-family: inherit;
	vertical-align: baseline;
}
: focus {
	outline: 0;
}
body {
	line-height: 1;
	color: black;
	background: white;
}
ol, ul {
	list-style: none;
}
table {
	border-collapse: separate;
	border-spacing: 0;
}
caption, th, td {
	text-align: left;
	font-weight: normal;
}
blockquote: before, blockquote: after,
q: before, q: after {
	content: "";
}
blockquote, q {
	quotes: "" "";
}