<head>
<style type="text/css">
a.top:link {font-family: 宋体} /*链接字体*/
a.top:link {font-weight: normal} /*设置链接文字中的字符粗细*/
a.top:link {font-size: 12} /*设置链接文字的大小*/
a.top:link {text-decoration: none} /*设置链接文字没有下划线*/
a.top:hover {text-decoration: underline} /*鼠标放在链接上时有下划线*/
a.top:link {color: #000000} /*设置链接文字的颜色*/
a.top:visited {color: #000000} /*访问过的链接*/
a.top:hover {color: #B50000} /*鼠标放在链接上字体的颜色*/
a.tj:link {font-family: 宋体}
a.tj:link {font-weight: normal}
a.tj:link {font-size: 12}
a.tj:link {text-decoration: none}
a.tj:hover {text-decoration: none}
a.tj:link {color: #000000}
a.tj:visited {color: #0000ff}
a.tj:hover {background: #FFFFCC}
h1 {font-size:12px}
h1 {font-family: "宋体"}
h1 {font-weight: normal}
h1 {color: #000000}
h2 {font-size:14px}
h2 {font-family: "宋体"}
h2 {font-weight: normal}
h2 {color: #000000}
h3 {font-size:24px}
h3 {font-weight: 1}
h3 {color: #000000}
body {
margin-top: 1px /*上边距*/
margin-bottom: 1px /*下边距*/
}
</style>
<meta http-equiv="Content-Type" content="text/html charset=gb2312"></head>
<body>
<p>Mouse over the links to see them change layout.</p>
<p><b><a href="default.asp" target="_blank" class="top">电脑对怀孕其实没啥影响</a></b></p>
<p><b><a href="default.asp" target="_blank" class="tj">电脑对怀孕其实没啥影响</a></b></p>
<h1>电脑对怀孕其实没啥影响</h1>
<h2>电脑对怀孕其实没啥影响</h2>
<h3>电脑对怀孕其实没啥影响</h3>
</body>
</html>
我一般是这样写/*reset style*/
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td { margin:0padding:0}
body { width:100%height:100%background:#FFFcolor:#333font:12px/1.5em Arial, Helvetica, sans-serifposition:relativeleft:0top:0}
h1, h2, h3, h4, h5, h6 { font-size:1em}
*{ word-wrap: break-word}
a, a:hover { color:#333text-decoration:none}
a:hover { color:#c00}
fieldset, img { border:none}
img{ border:0vertical-align:middle}
legend { display:none}
ol, ul, li { list-style:none}
em, strong, cite, th { font-style:normalfont-weight:400}
input, textarea, select, button { font:12px Verdana, Helvetica, Arial, sans-serif}
table { border-collapse:collapse}
html { overflow:-moz-scrollbars-vertical}
/* common style */
.clearfix:after { content:"."display:blockheight:0clear:bothvisibility:hidden}
.clearfix { display:inline-block}
/*\*/ .clearfix { display:block} /**/
.cl{ clear:both}
把它写在一个css文件里 存起来 然后直接调用 我每次写都是这样用的
如果.name1跟.name2是同级元素,那么.name1下定义的样式,是不会影响.name2下的元素的。回答你失效的那个问题:
问题1:第一种中的写法相当于#name1 div 和span元素同时具有相同样式;
#name1 div,span{}这种写法是并列关系,等同于:
#name1 div{}
span{}
所有span标签都具有和#name1 div一样的样式,所以对你div中的span元素有影响,而第二种是在#name1下的span标签的样式,所以对#name2中的span标签没有影响。
问题2:如果你不想让样式冲突的话,可以用以下方法解决:
》每个代码块中的样式定义都要在当前层的范围下,使每个代码块中的元素的样式只对当前模块有效,不会影响到其他模块:
.div1 span{}
.div1 a{}
.div2 span{}
.div2 a{}
<div class="div1">
<span></span>
<a></a>
</div>
<div class="div2‘>
<span></span>
<a></a>
</div>
如上,所有div1中的元素的样式都定义在.div1后面,所有div2中的元素的样式都定义在.div2后面,