开发者社区> 问答> 正文

#React 举例说明样式化组件?

#React 举例说明样式化组件?

展开
收起
因为相信,所以看见。 2020-05-08 10:06:03 396 0
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    让我们创建

    为每个特定的样式组件。
    import React from 'react'
    import styled from 'styled-components'
    
    // Create a <Title> component that renders an <h1> which is centered, red and sized at 1.5em
    const Title = styled.h1`
      font-size: 1.5em;
      text-align: center;
      color: palevioletred;
    `
    
    // Create a <Wrapper> component that renders a <section> with some padding and a papayawhip background
    const Wrapper = styled.section`
      padding: 4em;
      background: papayawhip;
    `
    

    现在,这两个变量Title和Wrapper是可以像其他任何React组件一样呈现的组件。

    <Wrapper>
      <Title>{'Lets start first styled component!'}</Title>
    </Wrapper>
    
    2020-05-08 10:09:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
利用编译将 Vue 组件转成 React 组件 立即下载
React Native 全量化实践 立即下载
React在大型后台管理项目中的工程实践 立即下载