//css样式的书写
//元素ID
#tb1{width:100%;height:80px;background-color:#FFD700;padding:4px;font-family:verdana,tahoma;font-weight:bold;}
#tb2{width:100%;padding:4px;font-family:verdana,tahoma;margin:12px 0px 0px 0px;background-color:#EEEEEE;font-weight:bold;}
//类
.test{cursor:hand;
    border-right: white thin inset; 
    border-top: black thin inset; 
    border-left: black thin inset; 
    border-bottom: white thin inset;   
    }
.post1
{
 cursor:move; background:red; color:Navy; border-right: black thin inset;
}
//元素
body
{
 background-color:Gray:
}
//css样式的运用
<html>
<head runat="server">
    <title>无标题页</title>
    //引入css样式文件
    <link type ="text/css" rel = "stylesheet"  href = StyleSheet.css />
</head>
//样式元素的应用,元素名字相同自动套用
<body>
    <form id="form1" runat="server">
    <div>
        //样式元素ID的应用
        <table id = "tb1" border = 1; type = "font-size;13pt; align;center;">
            <tr>
                //自己使用css样式style=样式
                <td style="width: 134px; height: 19px">dsfdf</td>
            </tr>
        </table>
    </div>
        <table id = "tb2" style="width: 168px">
            <tr>
                //样式类的应用
                <td class = "post1">啊啊啊啊啊啊啊啊</td>
            </tr>      
        </table>
    </form>
</body>
</html>
ID 是 以 #定义的CSS样式
也可以用JS获取来控制 getElementById(这里是ID) 来获取
name 很多了,就是给当前标签或元素指定名称,也可以用JS来控制值,form提交后获取的时候就需要获取name名称。 
 id与class区别,我在前面的文章中已经讲过了。但还是有新手对此非常迷茫,不知道什么时候该用id,什么时候该用class。这两个选择器让新手左右为难。
  一、在web标准中是不容许重复ID的,例如 div id="a" 不容许重复2次;而class所定义的是类,理论上可以无限重复。以根据需要多次引用。
  二、属性的优先级问题:ID 的优先级要高于class,我们在下面的代码中有示例说明。
  三、方便JS等客户端脚本的引用,假如在页面中要对某个对象进行脚本操作,那么可以给他定义一个ID,否则只能利用遍历页面元素加上指定特定属性来找到它,这是相对浪费时间资源,远远不如一个ID来得简单与快捷。
id与class优先级的试验
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fengfly.com</title>
<style type="text/css">
#YourHomePage {
 color:red
 }
.YourHomePage {
 color:blue
 }
</style>
</head>
<body>
<div id="YourHomePage" class="YourHomePage">
fengfly.com - Div CSS XHTML XML 教程大全 <br />
fengfly.com - Div CSS XHTML XML 教程大全
</div>
</body>
</html>
解析:根据一般的CSS优先级的原则。接近的应该是优先的。class="YourHomePage"更接近于定义样式的元素。但此例中,对元素应用的样式是id所定义的样式。说明id的优先级要高于class!
 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号