How do I do the layout for this?

So i have this design and I'm trying to implement it in vanilla CSS. i realised in mobile view i would make it a
flex-direction:column
flex-direction:column
but on the main screen i realise that the image is on the right and the text is on the left . How would it be done? I've attached an image of the design. I'd prefer pseudocode so i try coding it myself.
No description
73 Replies
DeCodX
DeCodX6mo ago
If you do mobile approach first then do this
Default layout
flex-direction:column;

When hitting the 750px viewport above
@media (min-width: 750px) {
flex-direction: row
}
Default layout
flex-direction:column;

When hitting the 750px viewport above
@media (min-width: 750px) {
flex-direction: row
}
cubiq
cubiq6mo ago
i mean, that's obvious but were talking about this
No description
cubiq
cubiq6mo ago
im not sure if grid layout with named regions would do the job.
DeCodX
DeCodX6mo ago
justify-content: center; to center your element since you switch the main axis into y axis
Hungry🐻
Hungry🐻6mo ago
But if i do this my image would be in-between my text. but all my text are to be on the left.
DeCodX
DeCodX6mo ago
so the justify-content will be the y axis now when you have the flex-direction: column;
cubiq
cubiq6mo ago
they know that, they're asking about the positioning of the image
DeCodX
DeCodX6mo ago
ah
ghostmonkey
ghostmonkey6mo ago
google flex order
cubiq
cubiq6mo ago
possibly..
DeCodX
DeCodX6mo ago
yeah order
ghostmonkey
ghostmonkey6mo ago
definitely lol
cubiq
cubiq6mo ago
grid would be better approach for this as with this, you'd have to fit it between the children..
No description
ghostmonkey
ghostmonkey6mo ago
he listed flex in his initial comment, so I gave him a flex solution
Hungry🐻
Hungry🐻6mo ago
but that would assume all the text is one div but doing mobile first its different divs
cubiq
cubiq6mo ago
oh, right, however i don't think that's possible
Hungry🐻
Hungry🐻6mo ago
i dont mind any
cubiq
cubiq6mo ago
i see it as grid row-span tbh
No description
cubiq
cubiq6mo ago
then you'd be able to change the placement based on the grid template.
ghostmonkey
ghostmonkey6mo ago
I would just flex-order everything as 1 and the image as 2 assuming you are starting from mobile first
cubiq
cubiq6mo ago
yes but then how? how would you make it so that the left text aligns still as row?
DeCodX
DeCodX6mo ago
if u use flex then be consistent
ghostmonkey
ghostmonkey6mo ago
Flexbox Froggy
A game for learning CSS flexbox
ghostmonkey
ghostmonkey6mo ago
have you guys seen this, it might help you figure out the different ways you can use flex
cubiq
cubiq6mo ago
these are super easy tbh
No description
ghostmonkey
ghostmonkey6mo ago
Grid Garden
A game for learning CSS grid layout
ghostmonkey
ghostmonkey6mo ago
and this one is for you cubiq, since I think you strongly prefer grid 🙂
cubiq
cubiq6mo ago
i mean in that case i have no idea how id do this layout with flex. https://codepen.io/thecubiq/pen/WNPqzpV there's a simple demo with my grid approach.
cubiq
cubiq6mo ago
clevermissfox
clevermissfox6mo ago
This is a job for grid
cubiq
cubiq6mo ago
@Hungry🐻 mind checking this out? is this how you wanted it to be?
Hashir Akbar
Hashir Akbar6mo ago
+
Hungry🐻
Hungry🐻6mo ago
the media query isnt working
cubiq
cubiq6mo ago
really?
cubiq
cubiq6mo ago
works on all my browsers, chrome, firefox, edge. what's your browser?
No description
cubiq
cubiq6mo ago
No description
Hungry🐻
Hungry🐻6mo ago
meaning my flex direction would be a row then safari 😦
cubiq
cubiq6mo ago
webkit ahhhhhhhhhh gotta check the grid support on safari later, have to switch to my hackintosh.
Hungry🐻
Hungry🐻6mo ago
Just tried it in on firefox though
No description
cubiq
cubiq6mo ago
show me on safari
Hungry🐻
Hungry🐻6mo ago
No description
cubiq
cubiq6mo ago
and now resize it
Hungry🐻
Hungry🐻6mo ago
just realised. i thin the ems you set is why i wasnt seeing it but yes thats what i want
cubiq
cubiq6mo ago
i mean, like a bit smaller still, maybe just the 30rem is not enough
cubiq
cubiq6mo ago
cubiq
cubiq6mo ago
maybe try this
Hungry🐻
Hungry🐻6mo ago
Mind going over the pseudocode approach you used ?
cubiq
cubiq6mo ago
it shouldn't be that hard, i really tried to make it as simple as i could if you don't understand how it works make sure to watch the grid series from kevin
Hungry🐻
Hungry🐻6mo ago
Im yet to go through the code. Just wanted a pseudo explanaiton. Then i try it beforei compare what i did to yours. I really want to be hands on
cubiq
cubiq6mo ago
so well.. this part is just my goto template, it's just css reset and also makes it so that everything on body is centered and reactive.
No description
cubiq
cubiq6mo ago
then we have the main grid, the grid template columns set to 2 columns that are both taking the same fraction of space. i added simple padding and also placing all items to center.
No description
cubiq
cubiq6mo ago
and then the image. i don't go with mobile first design so by default ive set the image to span through 2 rows. also added border radius that makes the image rounded.
No description
cubiq
cubiq6mo ago
and then if the height is smaller than 30rem, i set the template columns to just one column. simple as that
No description
cubiq
cubiq6mo ago
in the structure also notify that i didn't have to even change the image order. it's always gonna be the second item
cubiq
cubiq6mo ago
No description
Hungry🐻
Hungry🐻6mo ago
how did the text elemets fit all on the left? you didnt specify anything. was it the grid? Was it the image filling two rows?
cubiq
cubiq6mo ago
that's default p css behavior.
Hungry🐻
Hungry🐻6mo ago
I see. im just trying to understand the behavior of the elements. you specified two columns meaning all elements are going to ocupy the two columns row by row?
cubiq
cubiq6mo ago
Kevin Powell
YouTube
Learn CSS Grid the easy way
It can be easy to get bogged down in how grid works, with a lot of new properties, values, and even units! So let's try and simplify things as much as possible, because to get started, you don't need to know everything about how Grid works. 🔗 Links ✅ The GitHub repo: https://github.com/kevin-powell/learn-grid-the-easy-way ✅ More videos on gr...
cubiq
cubiq6mo ago
please take your time and lear this
cubiq
cubiq6mo ago
also im terrible at explaining so..
Hungry🐻
Hungry🐻6mo ago
Thank you everyone for helping me out. I currently have a challenge where my menu is not on top of my page for some reason even after using z-index. Trying to have a go before i post it asking for help.
clevermissfox
clevermissfox6mo ago
It would be more helpful to post a codepen then screenshots of bits of your code. It all works together so the people helping could be missing an important piece , especially in this case with stacking context. Did you give the item with z-index a position: relative ?
Hungry🐻
Hungry🐻6mo ago
Just tried and pasted . the whole code. my css styling isn't even working for some odd reason. only the nav styling is showing. https://codepen.io/oti-adjei/pen/YzBmjRv
No description
clevermissfox
clevermissfox6mo ago
Your class is named Hero and you’re selecting .hero
Hungry🐻
Hungry🐻6mo ago
Just realised i copied the wrong css :). Its working now. Kindly check the pen now
clevermissfox
clevermissfox6mo ago
Your nav links are there when pressing the hamburger menu, you can select them , you just can’t see them because the white color on the cream bg
Hungry🐻
Hungry🐻6mo ago
the navlinks is suppose to have a z-index so it shouldn't even be showing whats beneath it like this page
clevermissfox
clevermissfox6mo ago
That’s the behaviour I’m getting, they are on top of the content on mobile. You just can’t read the text because it’s white but it’s there
Hungry🐻
Hungry🐻6mo ago
Hmmm so how come im getting something else
clevermissfox
clevermissfox6mo ago
Could be the browser or device. The “responsive mode” on dev tools aren’t gonna translate to how it actually works on a phone device; it just demonstrates how it will work on the machine you’re working on, if the screen was that small. What browser are you using ? Is it Firefox or safari? Look up stacking context css + your browser See if it differ
Hungry🐻
Hungry🐻6mo ago
firefox but using responsive mode
clevermissfox
clevermissfox6mo ago
In Firefox use the stacking context inspector to try and debug. It’s an extension available Another issue you have is your not making the navLinks display none or visibility hidden or setting your body’s overflow property so it’s creating side scrolling