react环境

03.添加css依赖

2017-11-01  本文已影响14人  大月山

添加css样式

新建/style/app.css
html, body, #root, .app {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

div {
    box-sizing: border-box;
}

.header {
    position: fixed;
    top: 0;
    left: 150px;
    right: 0;
    padding: 0 30px;
    height: 61px;
    background: #ebebeb;

}

.title {
    width: 90%;
    margin: 0 5%;
    height: 80px;
    line-height: 80px;
    color: #fff;
    font-size: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 150px;
    background: #3d3c4a;

}

.header-con {
    position: relative;
    width: 100%;
    height: 60px;
}

.user {
    position: absolute;
    right: 0;
    top: 15px;
    height: 30px;
    line-height: 30px;
    color: gray;
}

.text {
    float: left;
    height: 30px;
}

.avatar {
    float: right;
    width: 30px;
    height: 30px;

}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: 90%;
}

.content {
    position: fixed;
    top: 60px;
    left: 150px;
    right: 0;
    bottom: 0;
    padding: 30px;
    color: gray;
}



修改/app/component/Header.js
import React from 'react';

class Header extends React.Component {
    render() {
        return (
            <div className="header">
               <div className="header-con">
                   <div className="user">
                       欢迎您!
                   </div>
               </div>
            </div>
        )
    }
}
export default Header;
修改/app/component/Sidebar.js
import React from 'react';

class Sidebar extends React.Component {
    render() {
        return (
            <div className="sidebar">
                <div className="title">
                    easterCat
                </div>
            </div>
        )
    }
}
export default Sidebar;
修改/app/component/App.js
...
import '../style/app.css';
添加css依赖/webpack.config.js
module: {
    loaders: [
        {
            test: /\.css$/,
            loader: 'style-loader!css-loader'
        },
    ]
},
打包运行
webpack

此时的css打包是自动添加到index的style标签里面

上一篇 下一篇

猜你喜欢

热点阅读