ElementUI如何修改el-cascader的默認樣式
ElementUI如何修改el-cascader的默認樣式
Element UI 中的下拉彈窗是通過在整個body標簽末尾動態(tài)添加div實現(xiàn)的,所以修改樣式時,必須要定義全局樣式才能實現(xiàn)樣式覆蓋,那怎樣才能避免全局的樣式污染呢?
解決辦法:通過給組件添加自定義的 popper-class 屬性來避免全局樣式污染;
<el-cascader
v-model="showOptions"
style="height: 36px;width:260px"
placeholder="顯示選項"
:options="optionsList"
:props="props"
collapse-tags
clearable
popper-class="dropDownPanel"
></el-cascader>
下拉框的樣式設置:
<style>
.dropDownPanel{
background: #123493;
border: 1px solid rgba(57,106,254,1);
}
.dropDownPanel[x-placement^=bottom] .popper__arrow {
display: none;
}
.dropDownPanel .el-cascader-menu {
color: #fff;
border-right: 1px solid rgba(57,106,254,1);
}
.dropDownPanel .el-cascader-node.in-active-path {
color: #38B4C1;
/* background: transparent; */
}
.dropDownPanel .el-cascader-node.is-active {
color: #38B4C1;
}
.dropDownPanel .el-cascader-node:not(.is-disabled):focus,
.dropDownPanel .el-cascader-node:not(.is-disabled):hover {
background-color: #0C0F56!important;
}
</style>
樣式修改
<style scoped>
/deep/ .el-tag.el-tag--info {
background-color: #123493;
border-color: rgba(57,106,254,1);
color: #FFFFFF;
}
/deep/ .el-cascader__tags .el-tag:not(.is-hit) {
border-color: rgba(57,106,254,1);
}
</style>補充:
ElementUI 修改默認樣式的幾種辦法
ElementUI 是一套ui組件庫,目前最新版本 react 和 vue 等主流框架都有支持。該庫默認主題色是天藍色,若用于項目開發(fā),難免遇到要需求修改其默認樣式的情況,本文就基于vue 框架介紹幾種修改 ElementUI 默認樣式的辦法。
面試官會問:怎樣修改ElementUI的默認樣式 ?
如何修改ElementUI樣式?
回答:一共有三種方法:
1、內嵌法修改樣式、通過:style修改,用于局部組件塊
2、:class引用修改樣式,通過:class修改,用于局部組件塊
3、import導入修改樣式
通過import導入樣式文件,若在main.js中導入css 則表示全局引用。既可以用于局部組件塊也可以用于全局組件
deep 穿透
一、內嵌法修改樣式
通過:style修改,用于局部組件塊
<el-button :style="selfstyle">默認按鈕</el-button>
<script>
export default {
data() {
return {
selfstyle: {
color: "white",
marginTop: "10px",
width: "100px",
backgroundColor: "cadetblue"
}
};
}
}
</script>二、:class引用修改樣式
通過:class修改,用于局部組件塊
<el-button :class="[selfbutton]">默認按鈕</el-button>
<script>
export default {
data() {
return {
selfbutton: "self-button"
};
}
}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.self-button {
color: white;
margin-top: 10px;
width: 100px;
background-Color: cadetblue;
}
</style>三、import導入修改樣式
通過import導入樣式文件,若在main.js中導入css 則表示全局引用。既可以用于局部組件塊也可以用于全局組件
<el-button>和下面的el-button效果一樣</el-button>
<el-button :class="[selfbutton]">默認按鈕</el-button>
<script>
import './button.css'
export default {}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped></style>
/* button.css */
.el-button {
color: white;
margin-top: 10px;
width: 100px;
background-Color: cadetblue;
}
.self-button {
color: white;
margin-top: 10px;
width: 100px;
background-Color: cadetblue;
}
.self-button:hover {
color: black;
background-Color: whitesmoke;
}
</style>以上就是我針對vue框架下的ElementUI 修改默認樣式的方法
到此這篇關于ElementUI如何修改el-cascader的默認樣式的文章就介紹到這了,更多相關ElementUI修改el-cascader默認樣式內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue中Router路由兩種模式hash與history詳解
這篇文章主要介紹了Vue中Router路由的兩種模式,分別對hash模式與history模式作了簡要分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-09-09
Vue3+Vue Router實現(xiàn)動態(tài)路由導航的示例代碼
隨著單頁面應用程序(SPA)的日益流行,前端開發(fā)逐漸向復雜且交互性強的方向發(fā)展,在這個過程中,Vue.js及其生態(tài)圈的工具(如Vue Router)為我們提供了強大的支持,本文將介紹如何在Vue 3中使用Vue Router實現(xiàn)動態(tài)路由導航,需要的朋友可以參考下2024-08-08
Electron自動更新失效報錯Error:?Object?has?been?destroyed的問題解決
本文主要講解如何解決?Error:?Object?has?been?destroyed?這個?Electron?中最常見的問題,以及?Electron?自動更新的流程,文中通過代碼示例給大家講解的非常詳細,需要的朋友可以參考下2024-01-01

