styled-components使用

2019-06-08  本文已影响0人  SmileMylife

1.首先引入styled变量

import styled from "styled-components";

2.根据需要编写样式代码:

export const NavItem = styled.div`
    line-height: 56px;
    font-size: 17px;
    padding: 0 15px;
    color: #333;
    &.left {
        float: left;
    }
    &.right {
        float: right;
        color: #969696;
    }
    &.active {
        color: #ea6f5a;
    }
`;

以上样式代码中&表示class为left或right的div样式。

export const Logo = styled.a.attrs({
    href: "/"
})`
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100px;
    height: 56px;
    background: url(${logoPic});
    background-size: contain;
`;

以上代码中.attrs表示a标签所具有的属性。

上一篇下一篇

猜你喜欢

热点阅读