HTML DOM----改变HTML样式
语法:
Object.style.property = new style;
注意: Object是获取元素的对象,如通过document.getElementById(“id”)获取的元素。
基本属性表(property):
属性 | 描述 |
---|---|
backgroundColor | 设置元素的背景颜色 |
height | 设置元素的高度 |
width | 设置元素的宽度 |
color | 设置文本的颜色 |
font | 在一行设置所有的字体属性 |
fontFamily | 设置元素的字体系列 |
fontSize | 设置元素的字体大小 |
… | … |
– | – |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
window.onload = function(){
var icon =document.getElementById("icon")
icon.style.color = "red";//文本颜色
icon.style.height ="50px";
icon.style.lineHeight = "50px";
icon.style.textAlign ="center";
icon.style.background ="paleturquoise"
}
</script>
</head>
<body>
<div id="icon">
改变HTML样式
</div>
</body>
</html>