Reputation: 91959
I am new to CSS and front-end development in general.
Yesterday I learnt that using CSS Flex box we can create fluid layouts which work perfectly with screen of different sizes.
I am currently using React
with https://roylee0704.github.io/react-flexbox-grid/. So far I am able to create layout boxes with 3 columns. However, I found that the text in the columns does not align correctly.
So I added some padding to make it look good on browser:
But on smaller screen, this doesn't look right:
My code for this part look like
const MenuItemStyle = {
paddingTop: '3%'
};
const MenuPriceStyle = {
paddingTop: '6%'
};
const SpicyMenuItem = (props) => (
// add price on right side
<Grid fluid>
<Row center="lg">
<Col xs={3} sm={3} lg={2}><Avatar src={props.image}/></Col>
<Col xs={6} sm={6} lg={4}>
<div style={MenuItemStyle}>{props.name}</div>
</Col>
<Col xs={3} sm={3} lg={2}>
<div style={MenuPriceStyle}>{props.price}</div>
</Col>
</Row>
</Grid>
);
Questions
media-queries
and write separate rules to align text, image, icons for different screen sizes? I am confused as to if I still need to write media-queries
in addition to using flexbox
.
Upvotes: 0
Views: 71
Reputation: 116
Questions - Is flexbox used for only the layouts? Not sure what you mean here, but it can be used to create responsive grid layouts if you want. CSS-Grid would be another, possibly more straightforward way to do that though.
Absolutely. There are many guides that go through the awesome flexibility that you have in aligning flexbox content. I won't even try to go through it all here because there is too much and it has been discussed a lot already.
Check out these links:
https://css-tricks.com/almanac/properties/a/align-content/
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/
You will not need media queries nearly as much - they will only be necessary when you want to change the behavior on mobile to something other than the default behavior of flexbox. Start with no media queries, and then see if you like the look on mobile, all you should need are some small tweaks.
Upvotes: 1