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
DeCodX12mo 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
cubiq12mo ago
i mean, that's obvious but were talking about this
No description
cubiq
cubiq12mo ago
im not sure if grid layout with named regions would do the job.
DeCodX
DeCodX12mo ago
justify-content: center; to center your element since you switch the main axis into y axis
Hungry🐻
Hungry🐻OP12mo 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
DeCodX12mo ago
so the justify-content will be the y axis now when you have the flex-direction: column;
cubiq
cubiq12mo ago
they know that, they're asking about the positioning of the image
DeCodX
DeCodX12mo ago
ah
ghostmonkey
ghostmonkey12mo ago
google flex order
cubiq
cubiq12mo ago
possibly..
DeCodX
DeCodX12mo ago
yeah order
ghostmonkey
ghostmonkey12mo ago
definitely lol
cubiq
cubiq12mo ago
grid would be better approach for this as with this, you'd have to fit it between the children..
No description
ghostmonkey
ghostmonkey12mo ago
he listed flex in his initial comment, so I gave him a flex solution
Hungry🐻
Hungry🐻OP12mo ago
but that would assume all the text is one div but doing mobile first its different divs
cubiq
cubiq12mo ago
oh, right, however i don't think that's possible
Hungry🐻
Hungry🐻OP12mo ago
i dont mind any
cubiq
cubiq12mo ago
i see it as grid row-span tbh
No description
cubiq
cubiq12mo ago
then you'd be able to change the placement based on the grid template.
ghostmonkey
ghostmonkey12mo ago
I would just flex-order everything as 1 and the image as 2 assuming you are starting from mobile first
cubiq
cubiq12mo ago
yes but then how? how would you make it so that the left text aligns still as row?
DeCodX
DeCodX12mo ago
if u use flex then be consistent
ghostmonkey
ghostmonkey12mo ago
Flexbox Froggy
A game for learning CSS flexbox
ghostmonkey
ghostmonkey12mo ago
have you guys seen this, it might help you figure out the different ways you can use flex
cubiq
cubiq12mo ago
these are super easy tbh
No description
ghostmonkey
ghostmonkey12mo ago
Grid Garden
A game for learning CSS grid layout
ghostmonkey
ghostmonkey12mo ago
and this one is for you cubiq, since I think you strongly prefer grid 🙂
cubiq
cubiq12mo 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
cubiq12mo ago
clevermissfox
clevermissfox12mo ago
This is a job for grid
cubiq
cubiq12mo ago
@Hungry🐻 mind checking this out? is this how you wanted it to be?
Hashir Akbar
Hashir Akbar12mo ago
+
Hungry🐻
Hungry🐻OP12mo ago
the media query isnt working
cubiq
cubiq12mo ago
really?
cubiq
cubiq12mo ago
works on all my browsers, chrome, firefox, edge. what's your browser?
No description
cubiq
cubiq12mo ago
No description
Hungry🐻
Hungry🐻OP12mo ago
meaning my flex direction would be a row then safari 😦
cubiq
cubiq12mo ago
webkit ahhhhhhhhhh gotta check the grid support on safari later, have to switch to my hackintosh.
Hungry🐻
Hungry🐻OP12mo ago
Just tried it in on firefox though
No description
cubiq
cubiq12mo ago
show me on safari
Hungry🐻
Hungry🐻OP12mo ago
No description
cubiq
cubiq12mo ago
and now resize it
Hungry🐻
Hungry🐻OP12mo ago
just realised. i thin the ems you set is why i wasnt seeing it but yes thats what i want
cubiq
cubiq12mo ago
i mean, like a bit smaller still, maybe just the 30rem is not enough
cubiq
cubiq12mo ago
cubiq
cubiq12mo ago
maybe try this
Hungry🐻
Hungry🐻OP12mo ago
Mind going over the pseudocode approach you used ?
cubiq
cubiq12mo 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🐻OP12mo 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
cubiq12mo 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
cubiq12mo 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
cubiq12mo 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
cubiq12mo 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
cubiq12mo 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
cubiq12mo ago
No description
Hungry🐻
Hungry🐻OP12mo 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
cubiq12mo ago
that's default p css behavior.
Hungry🐻
Hungry🐻OP12mo 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
cubiq12mo 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
cubiq12mo ago
please take your time and lear this
cubiq
cubiq12mo ago
also im terrible at explaining so..
Hungry🐻
Hungry🐻OP12mo 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
clevermissfox12mo 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🐻OP12mo 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
clevermissfox12mo ago
Your class is named Hero and you’re selecting .hero
Hungry🐻
Hungry🐻OP12mo ago
Just realised i copied the wrong css :). Its working now. Kindly check the pen now
clevermissfox
clevermissfox12mo 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🐻OP12mo ago
the navlinks is suppose to have a z-index so it shouldn't even be showing whats beneath it like this page
clevermissfox
clevermissfox12mo 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🐻OP12mo ago
Hmmm so how come im getting something else
clevermissfox
clevermissfox12mo 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🐻OP12mo ago
firefox but using responsive mode
clevermissfox
clevermissfox12mo 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
Want results from more Discord servers?
Add your server