0

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:

enter image description here

But on smaller screen, this doesn't look right:

enter image description here

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

  • Is flexbox used for only the layouts?
  • Can flexbox help in aligning the text, images, icons inside layout/columns?
  • Is it recommended to use 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.

1
  • Whether you use media queries or not is up to your implementation and design. There is no absolute right/wrong way or answer. Flex and media queries are 2 things that can work together if you need them to. If you want specific feedback, post your code, and what specifically doesn't look right with the mobile layout. Commented Apr 17, 2017 at 22:50

1 Answer 1

1

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.

  • Can flexbox help in aligning the text, images, icons inside layout/columns?

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/

  • Is it recommended to use 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.

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.