Vue为v-html中标签添加CSS样式
<template>
<div class="hello">
<section>
<h3 class="title">{{news.title}}</h3>
<p class="news-time">{{news.datetime}}</p>
<div class="con" v-html="news.dec">
</div>
<button class="back" @click="goBack()">返回列表</button>
</section>
</div>
</template>
当我们使用v-html渲染页面,使用下面这种方式去修改样式并没有效果,
<style scoped lang="less">
.con{
p {
font-size: 14px;
line-height: 28px;
text-align: left;
color: rgb(238, 238, 238);
color: #585858;
text-indent: 2em;
}
}
</style>
解决方案:
当我们引入第三方组件或加载html元素时,想修改下样式,就可以用以下三种方式:
一.去掉<style scoped>中的scoped
这个方法不建议使用,会改变布局
二.定义两个style标签,一个含有scoped属性,一个不含有scoped属性
使用方法为
<style scoped>
.introduction{
width: 100%;
margin-bottom: 3rem;
}
</style>
<style>
.introduction img{
width: 100%;
object-fit: fill;
}
</style>
三.通过 >>> 可以使得在使用scoped属性的情况下,穿透scoped,修改其他组件的值
使用模板为:
.introduction>>> img{
width: 100%;
object-fit: fill;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。