ElementUI修改默认样式的⼏种办法(⼩结)ElementUI 是⼀套ui组件库,⽬前最新版本 react 和 vue 等主流框架都有⽀持。该库默认主题⾊是天蓝⾊,若⽤于项⽬开发,难免遇到要需求修改其默认样式的情况,本⽂就基于 react 和 vue 框架介绍⼏种修改 ElementUI 默认样式的办法。
Vue
安装:
npm i element-ui -S
使⽤:
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
Vue.use(ElementUI);
new Vue({
el: '#app',
render: h => h(App)
});
(⼀)内嵌法修改样式
通过:style修改,⽤于局部组件块:
<el-button :>默认按钮</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;
vue与react面试题
}
.self-button:hover {
color: black;
background-Color: whitesmoke;
}
React
安装:
npm install element-react -S
npm install element-theme-default -S
使⽤:
import React from 'react';
import ReactDOM from 'react-dom';
import { Button } from 'element-react';
import 'element-theme-default';
(⼀)内嵌法修改样式
import { Button } from 'element-react';
function app(){
render() {
const style = {
color: "white",
marginTop: "10px",
width: "100px",
backgroundColor: "cadetblue"
}
return(
<div>
<Button style={style}>Hello</Button>
</div>
);
}
}
(⼆)提升优先级修改样式
导⼊样式⽂件,通过className引⽤样式,样式⽂件中需要使⽤!import提⾼优先级,否则⽆效。import '../style/button.css'
import { Button } from 'element-react';
function App(){
render() {
return(
<div>
<Button>和下⾯的Button效果⼀样</Button>
<Button className="self-button">Hello</Button>
</div>
);
}
}
/* button.css */
.el-button {
color: white!important;
margin-top: 10px!important;
width: 100px!important;
background-Color: cadetblue!important;
}
.self-button {
color: white!important;
margin-top: 10px!important;
width: 100px!important;
background-Color: cadetblue!important;
}
.self-button:hover {
color: black!important;
background-Color: whitesmoke!important;
}
到此这篇关于ElementUI 修改默认样式的⼏种办法(⼩结)的⽂章就介绍到这了,更多相关ElementUI 修改默认样式内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!