内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效。
内部样式(internal Style Sheet):是写在HTML的<head></head>里面的,内部样式只对所在的网页有效。
外部样式表(External Style Sheet):如果很多网页需要用到同样的样式(Styles),将样式(Styles)写在一个以.css为后缀的CSS文件里,然后在每个需要用到这些样式(Styles)的网页里引用这个CSS文件。
不多说 上代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Document</title>
<style>
#test{width:200px;}
</style>
<script>
</script>
</head>
<body>
<div id="test">this is test content</div>
<script type="text/javascript">
var oTest = document.getElementById('test');
if(oTest.currentStyle){
alert('ie: ' + oTest.currentStyle['width']);
} else {
alert('ff: ' + window.getComputedStyle(oTest, null)['width']);
}
</script>
</body>
</html>