【问题标题】:float left or display inline-block is not working in styled components reactjs向左浮动或显示内联块在样式组件reactjs中不起作用
【发布时间】:2017-10-24 05:51:38
【问题描述】:

我想在同一个 div 中获取图像和文本,我尝试过使用 float left 并显示 inline-block 但没有用,我无法理解我正在做的错误。

我得到的输出如下

我在 reactjs 中使用了样式化组件。 这些是我用过的样式化组件

export const BannerContainer = styled.div`
    width: 1280px
    height: 448px
    margin: auto
    `

export const BannerImageContainer = styled.div height:448px width:640px float: left export const BannerImage = styled.img padding:96px 96px 96px 96px margin-left:128px

export const BannerTextContainer = styled.div height:448px width:512px margin-right:128px float: left

export const BannerHeaderText = styled.h1 width: 352px height: 64px padding-top:40px font-family: Nunito font-size: 28px font-weight: 600 line-height: 1.14 text-align: center

export const BannerParagraphContainer = styled.p width: 389px height: 72px opacity: 0.38 font-family: Nunito font-size: 16px line-height: 1.5 text-align: center color: #000000

export const SeeAllProductsButton = styled.button width: 160px height: 32px background-color: #7C6ECC color: #FFFFFF border: 0px margin: 32px 112px

这是渲染它的代码 <BannerContainer> <BannerImageContainer> <BannerImage src={bannerImage} /> </BannerImageContainer> <BannerTextContainer> <BannerHeaderText> Solving the most common problems in marketing </BannerHeaderText> <BannerParagraphContainer> Exquisite codially mr happiness of neglected distrusts. Boisterous impossible unaffected he me everything. </BannerParagraphContainer> <SeeAllProductsButton>See All Products</SeeAllProductsButton> </BannerTextContainer> </BannerContainer>

【问题讨论】:

    标签: css reactjs styled-components


    【解决方案1】:

    尝试使用 FlexBox!

    非常简单的实现让你开始:

    <div style={{display: 'flex'}}>
       <div style={{flex: '1'}}>
          <BannerImageContainer>
              <BannerImage src={bannerImage} />
          </BannerImageContainer>
       </div>
       <div style={{flex: '1'}}>
          <BannerTextContainer>
              <BannerHeaderText>
                  Solving the most common problems in marketing
              </BannerHeaderText>
              <BannerParagraphContainer>
                 Exquisite codially mr happiness of neglected distrusts.
                 Boisterous impossible unaffected he me everything.
              </BannerParagraphContainer>
              <SeeAllProductsButton>See All Products</SeeAllProductsButton>
          </BannerTextContainer>
       </div>
    </div>
    

    只是补充一点信息,这是一个非常流行的 css 组件(不是特定于 React),用于正确对齐事物。只需在谷歌上搜索“flexbox”即可获得大量信息,但一些特定链接是 herehere

    【讨论】:

    • 您能详细说明一下吗?它什么都不做吗?
    • 它正在做,但是在开发者工具的元素中检查它时对齐不正确......容器完全放在一边......我认为它不应该是那样的。开发者工具中的对齐也应该是完美的......对吧?
    • 在这种情况下,我不知道如何提供帮助了。希望有其他了解更多的人来。
    猜你喜欢
    • 2013-03-09
    • 2019-09-11
    • 2020-05-22
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2012-08-02
    相关资源
    最近更新 更多