詳解三種方式解決vue中v-html元素中標簽樣式
更新時間:2018年11月22日 10:25:28 作者:honey緣木魚
這篇文章主要介紹了三種方式解決vue中v-html元素中標簽樣式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
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;
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
圖文詳解Element-UI中自定義修改el-table樣式
elementUI提供的組件間距、樣式都比較大,如果直接套用,在頁面顯示可能就會顯得很大,就比如表格,表頭、行寬如果不修改的話,遇到列較多的時候,會顯得整個頁面就不好看,下面這篇文章主要給大家介紹了關于Element-UI中自定義修改el-table樣式的相關資料,需要的朋友可以參考下2022-08-08

