html默认css样式的标签及去除(全局)

1.标签的默认样式和清除默认样式(统一全局样式)的代码

大多数标签都有自己的默认样式,比如第二天课程中遇到的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; }

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标签聚焦不出现默认边框:
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;
    background-color:none
    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;
}


如有不足请谅解!希望给您带来帮助。

猜你喜欢

转载自blog.csdn.net/muzidigbig/article/details/80371464