Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
8704a872
Commit
8704a872
authored
Nov 02, 2016
by
qingwei.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: add custom theme
parent
6f41d5c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
README.md
README.md
+1
-0
custom-theme.md
custom-theme.md
+85
-0
No files found.
README.md
View file @
8704a872
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
-
[
Home Page
](
http://element.eleme.io/
)
-
[
Home Page
](
http://element.eleme.io/
)
-
[
Docs
](
http://element.eleme.io/#/component
)
-
[
Docs
](
http://element.eleme.io/#/component
)
-
[
FAQ 中文
](
./FAQ.md
)
-
[
FAQ 中文
](
./FAQ.md
)
-
[
自定义主题
](
./custom-theme.md
)
-
[
i18n
](
./i18n.md
)
-
[
i18n
](
./i18n.md
)
-
Starter Kit
-
Starter Kit
-
[
element-starter
](
https://github.com/ElementUI/element-starter
)
-
[
element-starter
](
https://github.com/ElementUI/element-starter
)
...
...
custom-theme.md
0 → 100644
View file @
8704a872
# 自定义主题
Element 默认提供一套主题,CSS 命名采用 BEM 的风格方便使用者覆盖样式。如果你想完全替换主题色或者部分样式,可以使用下面方法。
## 安装工具
首先安装「主题生成工具」,可以全局安装或者安装在当前项目下,推荐安装在项目里,方便别人 clone 项目时能直接安装依赖并启动。
```
shell
npm i element-theme
-D
```
安装默认主题,可以从 npm 安装或者从 GitHub 拉取最新代码。
```
shell
npm i element-theme-default@next
-D
# 从 GitHub
npm i https://github.com/ElementUI/theme-default
-D
```
## 初始化变量文件
主题生成工具安装成功后,如果全局安装可以在命令行里通过
`et`
调用工具,如果安装在当前目录下,需要通过
`node_modules/.bin/et`
访问到命令。执行
`-i`
初始化变量文件。默认输出到
`element-variables.css`
,当然你可以传参数指定文件输出目录。
```
shell
node_modules/.bin/et
-i
[
可以自定义变量文件目录]
>
✔ Generator variables file
```
如果使用默认配置,执行后当前目录会有一个
`element-variables.css`
文件。内部包含了主题所用到了所有变量,它们使用 CSS4 的风格定义。大致结构如下:
```
css
:root
{
/* Colors
-------------------------- */
--color-primary
:
#20a0ff
;
--color-success
:
#13ce66
;
--color-warning
:
#f7ba2a
;
--color-danger
:
#ff4949
;
--color-info
:
#50BFFF
;
--color-blue
:
#2e90fe
;
--color-blue-light
:
#5da9ff
;
--color-blue-lighter
:
rgba
(
var
(
--color-blue
),
0.12
);
--color-white
:
#fff
;
--color-black
:
#000
;
--color-grey
:
#C0CCDA
;
```
## 修改变量
直接编辑
`element-variables.css`
文件,例如修改主题色为红色。
```
CSS
--color-primary: red;
```
## 编译主题
保存文件后,到命令行里执行
`et`
编译主题,如果你想启用
`watch`
模式,实时编译主题,增加
`-w`
参数。
```
shell
node_modules/.bin/et
>
✔ build theme font
>
✔ build element theme
```
## 引入自定义主题
默认情况下编译的主题目录是放在
`./theme`
下,你可以通过
`-o`
参数指定打包目录。像引入默认主题一样,在代码里直接引用
`theme/index.css`
文件即可。
```
javascript
import
'
./theme/index.css
'
import
ElementUI
from
'
element-ui
'
import
Vue
from
'
vue
'
Vue
.
use
(
ElementUI
)
```
## 搭配插件按需引入组件主题
如果是搭配
`babel-plugin-component`
一起使用,只需要修改
`.babelrc`
的配置,指定
`styleLibraryName`
路径为自定义主题相对于
`.babelrc`
的路径,注意要加
`~`
。
```
json
{
"plugins"
:
[[
"component"
,
[
{
"libraryName"
:
"element-ui"
,
"styleLibraryName"
:
"~theme"
}
]]]
}
```
如果不清楚
`babel-plugin-component`
是什么,请阅读
[
快速上手
](
./examples/docs/zh-cn/quickstart.md
)
一节。更多
`element-theme`
用法请参考
[
项目仓库
](
https://github.com/ElementUI/element-theme
)
。
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment