<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width: 200px;
height: 200px;
background-color:pink;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
// 1.获取元素
const box = document.querySelector('.box')
// 2.修改样式 [对象.style.样式属性 = '值'] 记得加单位
box.style.width = '250px'
//多组单词的采取小驼峰命名法,解决减号问题
box.style.backgroundColor = 'red'
box.style.border = '2px solid blue'
box.style.borderTop = 'red'
</script>
</body>
</html>
08-通过style属性修改样式
最新推荐文章于 2023-08-11 14:00:23 发布