美文网首页
styled-components使用

styled-components使用

作者: SmileMylife | 来源:发表于2019-06-08 12:19 被阅读0次

    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标签所具有的属性。

    相关文章

      网友评论

          本文标题:styled-components使用

          本文链接:https://www.haomeiwen.com/subject/wehixctx.html