我想在同一个div中获取图像和文本我尝试使用float left并显示inline-block但没有用我无法在我正在做的地方弄错。
我在reactjs中使用了样式化的组件。 这些是我使用的样式组件
export const BannerContainer = styled.div`
width: 1280px
height: 448px
margin: auto
`
导出const BannerImageContainer = styled.div
height:448px
width:640px
float: left
export const BannerImage = styled.img
padding:96px 96px 96px 96px
margin-left:128px
导出const BannerTextContainer = styled.div
height:448px
width:512px
margin-right:128px
float: left
导出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
导出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>
答案 0 :(得分: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),用于正确对齐事物。只是谷歌搜索&#39; flexbox&#39;会给你很多信息,但是一些特定的链接是here和here