大多數標簽都有自己的默認樣式,比如遇到的body默認外邊距,另外本例中ul前的圓點及左側的內邊距,另h1-h6字體大小各不相同,em默認為斜體,strong表示粗體。正因為有這些默認樣式,一個設計合理的頁面,即使沒有加載樣式,也能讓用戶很容易閱讀。但此時這些默認樣式對我們沒用,所以需要清除掉,為了方便,建議用標簽重定義方式,這樣可以很簡單地把全局的樣式給統一起來。另外頁面中的圖片添加鏈接后會默認添加個邊框,ul默認情況下會在列表前添加圓點,這些都是需要去掉的。
-
body, ul, li, h1, h2, h3, h4, h5, h6, p, form, dl, dt, dd {
-
margin: 0px;
-
padding: 0px;
-
font-size: 12px;
-
font-weight: normal; }
-
ul { list-style: none; }
-
img { border-style: none; }
2.css去掉瀏覽器默認樣式
-
/** 清除內外邊距 **/
-
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elements 結構元素 */
-
dl, dt, dd, ul, ol, li, /* list elements 列表元素 */
-
pre, /* text formatting elements 文本格式元素 */
-
form, fieldset, legend, button, input, textarea, /* form elements 表單元素 */
-
th, td /* table elements 表格元素 */ {
-
margin: 0;
-
padding: 0;
-
}
-
/** 設置默認字體 **/
-
body,
-
button, input, select, textarea /* for ie */ {
-
font: 14px/1.5 tahoma, \5b8b\4f53, sans-serif;
-
}
-
h1, h2, h3, h4, h5, h6 { font-size: 100%; font-weight: normal;}
-
address, cite, dfn, em, var { font-style: normal; } /* 將斜體扶正 */
-
code, kbd, pre, samp { font-family: courier new, courier, monospace; } /* 統一等寬字體 */
-
small { font-size: 12px; } /* 小於 12px 的中文很難閱讀, 讓 small 正常化 */
-
/** 重置列表元素 **/
-
ul, ol { list-style: none; }
-
/** 重置文本格式元素 **/
-
a { text-decoration: none; }
-
a:hover { text-decoration: underline; }
-
sup { vertical-align: text-top; } /* 重置, 減少對行高的影響 */
-
sub { vertical-align: text-bottom; }
-
/** 重置表單元素 **/
-
legend { color: #000; } /* for ie6 */
-
fieldset, img { border: 0; } /* img 搭車:讓鏈接里的 img 無邊框 */
-
button, input, select, textarea { font-size: 100%; } /* 使得表單元素在 ie 下能繼承字體大小 */
-
/* 注:optgroup 無法扶正 */
-
/** 重置表格元素 **/
-
table { border-collapse: collapse; border-spacing: 0; }
-
/* 重置 HTML5 元素 */
-
article, aside, details, figcaption, figure, footer,header, hgroup, menu, nav, section,
-
summary, time, mark, audio, video {
-
display: block;
-
margin: 0;
-
padding: 0;
-
}
-
mark { background: #ff0; }
-
/* 設置placeholder的默認樣式 */
-
:-moz-placeholder {
-
color: #ddd;
-
opacity: 1;
-
}
-
::-moz-placeholder {
-
color: #ddd;
-
opacity: 1;
-
}
-
input:-ms-input-placeholder {
-
color: #ddd;
-
opacity: 1;
-
}
-
input::-webkit-input-placeholder {
-
color: #ddd;
-
opacity: 1;
-
}
3.<a>標簽
我們在平時a標簽里面嵌套一些字體圖片,這是很常見的。但是我們並不需要點擊時候a標簽里面的字體變色。這個小知識點,很簡單:css樣式:
-
a{
-
text-decoration:none;
-
color:#333;
-
}
記住這個color一定要寫(可自己設定)
這樣你再點擊的時候字體就會是這個color的顏色。
<a>標簽的四中狀態
-
a:hover, a:visited, a:link, a:active {
-
// 做到只設置一次,就可以使所有a標簽的四種狀態都和本身顏色保持一致,樣式代碼自己寫
-
}
4.<input>標簽
-
input{
-
border: none;
-
appearance:none;
-
-moz-appearance:none;
-
outline:none;//input標簽聚焦不出現默認邊框:
-
-webkit-appearance: none;//用於IOS下移除原生樣式
-
}
-
// or:
-
input:focus{ outline:none; }//input標簽聚焦不出現默認邊框:
-
border: none; appearance:none; -moz-appearance:none; outline:none;//input標簽聚焦不出現默認邊框: -webkit-appearance: none;//用於IOS下移除原生樣式 } //or: input:focus{ outline:none; }//input標簽聚焦不出現默認邊框:
input標簽placeholder樣式重設:
-
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color:#3c8bee ;; opacity:1; font-size: 0.25rem;text-align: center; }
-
::-moz-placeholder { /* Mozilla Firefox 19+ */ color:#3c8bee ;; opacity:1; font-size: 0.25rem;text-align: center; }
-
input:-ms-input-placeholder{ color:#3c8bee ;; opacity:1; font-size: 0.25rem;text-align: center; }
-
input::-webkit-input-placeholder{ color:#3c8bee ;; opacity:1; font-size: 0.25rem;text-align: center; }
5.清除<ul><ol>的默認樣式
-
ul, ol, {
-
margin: 0;
-
padding: 0;
-
list-style: n;
-
}
6.<img>
-
img {
-
vertical-align:top;
-
border:none;
-
}
7.<em><strong>
-
em,strong {
-
font-style:normal;
-
font-weight:normal;
-
}
8.button按鈕
-
.button{
-
border:0;
-
outline: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; list-style: none; overflow-wrap: break-word; height: 22px;">outline:none;
-
-webkit-appearance: none;//用於IOS下移除原生樣式
-
}
9.select 標簽
-
select {
-
border: none;
-
appearance:none;
-
-moz-appearance:none;
-
-webkit-appearance:none;
-
/*在選擇框的最右側中間顯示小箭頭圖片*/
-
background: url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center transparent;
-
padding-right: 14px;
-
}
10.清除ie瀏覽器input自帶的icon
-
::-ms-clear,::-ms-reveal{
-
display: none;
-
}
11.字體小於12px
-
font-size: 12px;
-
-webkit-transform: scale(0.84);
-
-ms-transform: scale(0.84);
-
-moz-transform: scale(0.84);
-
-o-transform: scale(0.84);
-
transform: scale(0.84);
-
-webkit-text-size-adjust: none;