<div :class="[ isOne?'one':'', 'two']">数组方法 </div>
2.对象方法,元素键名为css名称,用true和false 来控制是否显示
<div :class="{'one':isOne,'two':true}">对象方法</div>
3.直接加入,加入的内容是css名称,可以通过计算来控制显示的css,名称
<div :class="isOne?'one':'two'" >直接加入</div>
1.数组方法,元素是一个个对象,对象则是style的键值对,当然可以用三目运算控制
<div :style="[{color: 'green',fontSize: '30px'} , isOne ?{'font-weight': 'bold'}:{}]" >数组方法</div>
2.对象方法,元素键名为style名称,值为style属性值。当然可以用三目运算控制来控制是否显示对应的style属性值
<div :style="{ color: isOne ?'green':'#f00' , backgroundColor:'#f00'}" >对象方法</div>
3.直接加入,只要保证得出来的字符串是正确的即可,怎么用都可以
<div :style="(isOne ? 'color:green' : '')+ 'backgroundColor:#f00' ">直接加入</div>
1、基本样式 的写法<style type="text/css">
h1{
font-family:黑体
}
</style>
直接些标签名进行定义属性,这个也比较常见。但是它的定义通常放在<style>标签中声明。
2、类class链接样式
定义也通常在<style>标签中声明
<style type="text/css">
.style1{
color:red
font-size:16px
}
</style>
引用时候直接在标签的属性中使用class="style1" 记住是class属性
<h1></h1>
3、id链接样式
<style type="text/css">
#style1{
color:blue
font-size:16px
}
</style>
引用的时候就用标签属性中的id属性 ,要区别于类属性
<h1 id="style1"></h1>
区别:类class链接样式和id链接样式
类连接样式可以适用于多个对象设置同样的属性中,
而id链接样式只能用于一个对象标签中,其他标签则会失效
4、html选择器:
直接用标签进行声明,跟上面的第一个一样
2)派生选择器:
<style type="text/css">
h1 h2{
color:red
font-size:1em
font-family:黑体
}
</style>
h1 h2的写法意思是代表着该css样式只能之<h1><h2> </h2></h1>同时出现,且是嵌套使用的时候才能生效
3)id选择器
id选择器的作用是通过id选择器将css样式作用到页面的对象上。写法:
<style type="text/css">
#text p{
font-size:1em
}
</style>
将该样式绑定到html上,就要这样写
<h1 id=#"text">这个是不要p的写法
要p的写法
表明该对象只能作用在text对象上的所有p标签中
4)class选择器
<style type="text/css">
.fancy{
color:red
background:#666
}
</style>
使用的时候也是
<h1></h1>
也可以像上面的一样用派生选择器
<style type="text/css">
.fancy td{
color:red
background:#666
}
</style>
说明生效只能在td中
5)分组选择器
h1{color:bule}
#text{color:bule}
.play{color:bule}
这种写法太繁琐了
我们可以使用
h1,#text,.paly{
color:bule}
这样来定义
6)伪类和伪类选择器
用关键字:lang来定义
<html>
<head>
<style type="text/css">
q:lang(smile){
quotes:"∞"
}
</style>
</head>
<body>
好吧,展示一下
<p>请看<q>祝你愉快</q></p>
</body>
</html>
vue3点击之后加css样式在Vue3中可以再css标签中使用v-bind(***)来绑定一个属性控制它的样式,注意:【如果你的数据不是使用Vue3的 ref 或者 reactive使其变成响应...