绑定class样式
class样式
1. 写法:class=“xxx”,xxx可以是字符串、对象、数组
2. 字符串写法适用于:类名不确定,需要动态获取
3. 对象写法适用于:需要绑定多个样式,个数和名字不确定
4. 数组写法适用于:需要绑定多个样式,个数和名字确定,但不确定用不用
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>绑定样式</title>
<script type="text/javascript" src="../js/vue.js"></script>
<style>
.basic {
width: 300px;
height: 80px;
border: 1px solid black;
text-align: center;
line-height: 80px;
}
.happy {
background-color: orange;
}
.sad {
background-color: dimgray;
}
.normal {
background-color: bisque;
}
.show1 {
background-color: cyan;
}
.show2 {
font-size: 30px;
font-weight: bold;
}
.show3 {
border-radius: 30px;
}
</style>
</head>
<body>
<div id="root">
<h1>绑定class样式</h1>
<!-- 绑定class样式-字符串写法,适用于:样式类名不确定,需要动态指令 -->
<h3>点击div时修改样式为 happy</h1>