I am writing a section of a webpage, and want to flex contents inside the same div horizontally, with equal width. Somehow my CSS code is not working.
const Reasons = ()=>{
return (
<div className="reasons" id='reasons'>
<div className="left-r">
<img src={image1} alt="" />
<img src={image2} alt="" />
<img src={image3} alt="" />
<img src={image4} alt="" />
</div>
<div className="right-r">
Right Side
</div>
</div>
)
}
The CSS code:
.Reasons{
padding: 0 2rem;
display: flex;
}
.left-r{
flex: 1 1;
flex-direction: column;
}
.right-r{
flex: 1 1;
flex-direction: column;
background-color: var(--orange);
}
I expect it to be flexing horrizontally. But somehow it displays vertically.
2
Answers
Try this in the CSS file because I think the problem lies within the classname’s syntax being wrong. You do not need to add any flex styles to the two divs inside the main div:
I corrected the className (
.reasons
instead of.Reasons
), set a width for the images so that they remain in the horizontal direction, and also added some codes to crop the height if your images have different aspect ratio.