详解三种方式解决vue中v-html元素中标签样式
2019/6/26 23:21:00
本文主要是介绍详解三种方式解决vue中v-html元素中标签样式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Vue为v-html中标签添加CSS样式
<template> <div class="hello"> <section> <h2 class="title">{{news.title}}</h2> <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; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
这篇关于详解三种方式解决vue中v-html元素中标签样式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-04package.json 文件位置在哪?-icode9专业技术文章分享
- 2024-10-01Craco.js学习:从入门到实践指南
- 2024-10-01Create-React-App学习:入门与实践指南
- 2024-10-01CSS-in-JS学习:从入门到实践指南
- 2024-09-30JSX语法学习:从入门到初步掌握
- 2024-09-30Mock.js学习:入门教程与实战演练
- 2024-09-30React Hooks学习:从入门到实践
- 2024-09-30受控组件学习:React中的基础入门教程
- 2024-09-29JS定时器教程:初学者必看指南
- 2024-09-29JS对象教程:初学者的全面指南