Flexbox or Grid challenge // which would you use to solve these?

Flexbox or Grid challenge // which would you use to solve these?

Kevin Powell

7 месяцев назад

54,723 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@anzalaarfaq939
@anzalaarfaq939 - 03.01.2024 10:41

can you make a video on how to add smooth transition on gradients

Ответить
@carolmckay5152
@carolmckay5152 - 03.01.2024 10:12

For challenge 5 I did:
.product {
display: grid;
grid-template-columns: repeat(2, 1fr);
align-items: center;
}
.product__content {
display: grid;
gap: 1em;
padding: 2rem;
}

Ответить
@space_ace7710
@space_ace7710 - 03.01.2024 08:46

I love Flex and my friend loves Grid XD

Ответить
@user-ik7rp8qz5g
@user-ik7rp8qz5g - 03.01.2024 06:23

The key point to decide which one to use is to remember that grid is table v2. If a task feels like it has obvious solution with table, it will have obvious solution with grid, but most likely will require some magic to work with flex. Example - rigid layouts.
And opposite scenario, when a task feels like it would be nightmare to do with table, flex most likely would be better for it than grid. Example - inherently fluid things like tags from challenge 2.

Ответить
@QwDragon
@QwDragon - 03.01.2024 03:52

Here are my solutions:
1. display: grid; grid-template-columns: auto 1fr; gap: 1em; // expected flex to require reset of flex-shink for an image
2. display: flex; flex-wrap: wrap; gap: .5em;
3. .featured-products { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; @media (max-width: 800px) { grid-template-columns: 1fr; } }
4. display: grid; gap: 1em; grid-template-columns: repeat(auto-fill, minmax(max(300px, 26%), 1fr)); // Haven't thought about 100%, but thought about limiting 4 columns
5. .product { display: grid; grid-template-columns: 50% 1fr; } .product__content { height: 100%; box-sizing: border-box; padding: 2em; display: grid; gap: 1em; align-content: center; }

Ответить
@nanke1987
@nanke1987 - 03.01.2024 03:16

Maybe it's just my browser, but the link to the explanation of the 999 trick does not link to a different video (it just points to a section of the same video)

Ответить
@astolfoFredor
@astolfoFredor - 03.01.2024 02:34

Wow, I love messing around with CSS, and finding your channel definitely made my CSS evolve to the next level. Thanks for all the videos, I'll keep studying! 👍

Ответить
@bn5055
@bn5055 - 03.01.2024 01:28

Grid for layout, flexbox for components is rarely wrong

Ответить
@smithjohn2367
@smithjohn2367 - 03.01.2024 00:17

Great video as always.
For challenge number 5, I did it like this on my part.

.product {
display: grid;
grid-template-columns: 1fr 1fr;
place-items: center;
....
}

.product__content {
display: grid;
gap: 1rem;
padding: 1rem;
}

Ответить
@JoseDiasNeto
@JoseDiasNeto - 02.01.2024 23:06

For the last one, I use to replace "align-content: center" by:

grid-element > :first-child {
margin-block-start: auto;
}

grid-element > :last-child {
margin-block-end: auto;
}

It prevents some potential weird content loss on small height screens.

Ответить
@PicSta
@PicSta - 02.01.2024 22:54

In most cases, you want to use CSS Grid instead of flex box. Only if you have something to you want to align 1 dimensional, I think of flex box immediately. Flex box often leads to hacks or extra lines of CSS to get the desired behaviour. There are also people going for the flex box always solution and flex their way through. The quick and dirty solution. CSS grid also gives less hassle dealing with media queries. In a time when we don't design for explicit device widths, grid is just the better solution 90% of the time.

Ответить
@jybedesign
@jybedesign - 02.01.2024 22:00

Thank you a lot for this video!

I guess you already know this trick, but for people who don't, adding this line to your CSS would turn your HTML framework into a "blueprint", that help a lot when working with flex and grid :)

--- --- ---
* { --h:240; opacity: .9; background: hsl(var(--h),100%,90%) !important; border: 5px solid hsl(var(--h),100%,50%) !important; /**/ }
--- --- ---

You can also remove the [opacity] and simply play with these colors and apply the code to different elements (the div, the img, etc.)
--h:0 = Red
--h:120 = Green
--h:240 = Blue
--h:60 = Yellow
--h:180 = Cyan
--h:300 = Magenta

--- --- ---
Adding a [/*] just before the [--h] will fully deactivate the code (that's why we need to keep the [/**/] at the end). Useful to switch the border on/off easily when working with code like this:

img {
--h:240; opacity: .9; background: hsl(var(--h),100%,90%) !important; border: 5px solid hsl(var(--h),100%,50%) !important; /**/
width: 100%;
}
--- --- ---

If you didn't alrady have a video about this trick yet, maybe it would be a good one to consider. I think it can help newcomers a lot :)

Best to you!

Ответить
@groovebird812
@groovebird812 - 02.01.2024 20:23

Could you explain why css frameworks use flexbox instead of grid for their grid component?

Ответить
@robertkaminski1781
@robertkaminski1781 - 02.01.2024 19:51

I always have to use a grid layout when I need a gap, because older iPhones' Safari doesn't support the flex gap, and these devices are usually included in the browser compatibility list."

Ответить
@MrgnUTube
@MrgnUTube - 02.01.2024 19:16

Flex lover here!
Okay, you have to make more elements than grids sometimes, but it is more powerful for responsive UIs.

Ответить
@ELStalky
@ELStalky - 02.01.2024 19:13

For the first one, grid also makes it easy to prevent layout shifts from the image loading in later (if the image size is not fixed elsewhere).
You can use a fixed first column and the text will stay in place while the image loads.

The same can even be true for HTML streaming in over a slow connection, e.g. in the multiple products cases.
If you use flexbox with growing items or a grid with auto-fit and new items load in, existing items can shrink and things can start wrapping etc.

Ответить
@richardz6049
@richardz6049 - 02.01.2024 19:08

Still recovering from float based lay-outs and just happy to have build a simple site using flex-box. Happy to learn grid but not now😂

Ответить
@jhasani79
@jhasani79 - 02.01.2024 19:08

Awesomeness! I loved those challenges.

Ответить
@s0l0r1d4
@s0l0r1d4 - 02.01.2024 18:43

team both here! ✋

Ответить
@hayesmaker64
@hayesmaker64 - 02.01.2024 18:28

hi friend and friends

Ответить
@derBiesel
@derBiesel - 02.01.2024 18:27

I see the advantages in using grid for 2nd exercise. But I prefer the code structure and readability with flexbox solution 😀

Ответить
@Hellow12397
@Hellow12397 - 02.01.2024 18:25

i think you channel logo nedd to be updated

Ответить
@venomus9286
@venomus9286 - 02.01.2024 18:22

For challenge#5 for .product I used display: grid with grid-template-columns: 1fr 1fr; place-items: center;. To stretch the button to take full width I did .product__content { display: grid;} thats it.

Ответить
@Onee007
@Onee007 - 02.01.2024 18:18

For last case I prefere use flex, just add flex: 1 & width: 50% for both and for text just use align-self propety :)

Ответить
@pinnaclewd
@pinnaclewd - 02.01.2024 18:17

Great video Kevin. I personal feel using FB for some of these requires what I would class as hacks. I'm a big user of grid as it gives me absolute control as not too concerned how much code I have to write (media queries).

Ответить
@panzerswineflu
@panzerswineflu - 02.01.2024 18:16

Always grid

Ответить
@quadrumane
@quadrumane - 02.01.2024 18:15

FYI, just noticed Edge bizarrely refuses to support avif files, so folks like myself might find a fair bit of confusion that the images don't show.

Ответить
@khamliantung
@khamliantung - 02.01.2024 18:05

is it OK to use place-items: center for the 5th challenge?

Ответить
@juliusuwuigbe7743
@juliusuwuigbe7743 - 02.01.2024 17:54

I love the background gradient and filter you apply in your videos.

You are applying your CSS skills in real life 😂.

Ответить
@user-lj9vl7vt5f
@user-lj9vl7vt5f - 02.01.2024 17:31

Hey, Kevin. Sorry, but the CSS panel of the codepen of the first challenge (I have not checked the rest of them yet) didn't let me to type in it.

Ответить
@fromagetriste
@fromagetriste - 02.01.2024 17:29

i recommand any beginner to learn flexbox first, and learning Grid next year, if they need. I dont even know grid, dont waste time

Ответить
@ahmeddotgg
@ahmeddotgg - 02.01.2024 17:26

it feels so proud to do all the recommended/simplest approach 😄

Ответить
@nomadshiba
@nomadshiba - 02.01.2024 17:24

flex is a fallback for me
if it cant work with grid, then i fallback to flex

Ответить
@Atractiondj
@Atractiondj - 02.01.2024 17:24

display: none is a must-have for any layout!

Ответить
@ujjwalsahore1797
@ujjwalsahore1797 - 02.01.2024 17:23

So i can learn frontend by picking templates and then creating them by myself without leaving in between? Or there is a shortcut?

Ответить
@ganta2080
@ganta2080 - 02.01.2024 17:23

'Breakdown of method used from my Discord community:' -> Link broken

Ответить
@HamzaNazir277
@HamzaNazir277 - 02.01.2024 17:08

I am beginner learner and I am in a confusion
the matter is that
I learned CSS and I have seen some video that it is necessery to learn any framework after having a little knowledge of CSS
please guide me to go furthur that I learned tailwind CSS or Go with this css
please give your advice

Ответить
@chikeziechinonso4671
@chikeziechinonso4671 - 02.01.2024 17:05

First to like and comment

Ответить