Тёмный

5 ways to vertically center with CSS 

Kevin Powell
Подписаться 943 тыс.
Просмотров 227 тыс.
50% 1

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 336   
@obscure_films
@obscure_films 6 лет назад
This was awesome I hope this becomes a regular thing.
@KevinPowell
@KevinPowell 6 лет назад
The plan is for one every Friday, hopefully I can keep it up :)
@designertree
@designertree 5 лет назад
Kyle Foster h Awesome 👏
@T25de
@T25de 2 года назад
Did it do ?
@WebDevSimplified
@WebDevSimplified 6 лет назад
Nice video. I never realized that margin: auto actually aligned items vertically as well in grid and flex containers. I have always used the justify and align properties. Thanks for sharing!
@KevinPowell
@KevinPowell 6 лет назад
I was so happy when I found out that margin: auto worked like that for flexbox and grid. The fact that margin top and bottom: auto were different in behaviour from left and right is crazy to start with, this makes a lot more sense. It also lets you pull off some cool things if you have multiple things stacked inside of a flex or grid parent.
@facundocorradini
@facundocorradini 6 лет назад
I'm pretty sure most of us discovered that by accident! :p Another great (upcoming) feature is that according to the CSS Box Alignment Module level 3 specification, align-content should work on the block axis of block containers and multicol containers just like it does in grid and flex, so that will make for ease alignment in the most "traditional" layouts.
@KevinPowell
@KevinPowell 6 лет назад
Oh, I didn't know that Facundo! Really looking forward to that, as well as the gap property coming to flexbox.
@JackWutang
@JackWutang 4 года назад
Within the first 2 minutes of this video, I figured out something I was trying to do all day. Thanks!
@shardulnalegave4636
@shardulnalegave4636 5 лет назад
Great! You have solved the biggest problem in the world.
@joestevenson5568
@joestevenson5568 5 лет назад
anchored footers disagree
@Daniel_WR_Hart
@Daniel_WR_Hart 4 года назад
No one will ever starve again :)
@sulemanmughal5397
@sulemanmughal5397 2 года назад
😂😂
@jnoah7537
@jnoah7537 6 лет назад
I'm sure glad this came along. Sometimes I prefer to watch a short how to video on a specific subject, like this one, when I want a quick refresher. Or when I'm busy on a project and don't have time to watch a long video. Docs first and a videos after.
@markhackney3305
@markhackney3305 Год назад
2 weeks into a 6 month Web boot-camp. Your channel has become invaluable to me. Thank you, subscribed.
@surafelfikadu4331
@surafelfikadu4331 9 месяцев назад
Very short and to the point Thankyou ... 💚💛❤🙏
@kevinrichter9397
@kevinrichter9397 6 лет назад
Great introduction of a new segment! I still remember how painful it used to be to vertically center stuff and now the only struggle might be to decide which method you want to pick ;-) 5 minute videos are a great idea btw.
@josephlivengood4508
@josephlivengood4508 4 года назад
the old school way is to put align="center" inside the div tag and another way is with css, width: 90%; and margin: auto; but I like your style much better. I'm trying to catch up with the modern ways of doing this without relying on bootstrap.
@kiwicrafter
@kiwicrafter 3 года назад
I use that as well, the align center but it does not allow you to use classes or id's at the same time.
@feeham
@feeham 6 лет назад
These videos will be really good and i will codepen all of them as a quick reference. Keep up the good work Kevin , you doing really good.
@shahadathossain1209
@shahadathossain1209 4 года назад
Thank you. Easy to understand.
@ab-yp2gn
@ab-yp2gn 3 года назад
Thanks sooo much!! this really helped, I was struggling for hrs
@j.almadhaji
@j.almadhaji 5 лет назад
the last way with margin auto and grid&flex is the best I think.. absolute way is good for before and after stuff as I used to do thank you
@maxmaxmaxmaxmaxmaxmaxmaxmax1
@maxmaxmaxmaxmaxmaxmaxmaxmax1 3 года назад
Keep these coming!
@A_Lesser_Man
@A_Lesser_Man 3 года назад
TY KEVIN!! Vertical centering is the bane of my existence. i never know WHERE to apply this styling! do i apply it to the container in which i want the content centered? or, do i apply it to the inner stuff? I get so confused. so, i snitched your "grid" thingy, and slapped it into my css, and voila - it works. many thanks. wish to heck i knew what i was doin wrong tho! i'd love to show you my stuff, but, most of my css is embedded in perl code.
@kavalisuresh8670
@kavalisuresh8670 3 года назад
You are really CSS king sir
@AhmedM-M-c5p
@AhmedM-M-c5p Год назад
thanks for every thing you helped me so much
@johnswanson217
@johnswanson217 4 года назад
very helpful big thanks from korea
@anytabelkis4055
@anytabelkis4055 5 лет назад
Thank you! I love this video, I learned something new and I appreciate it a lot! I took notes for my future projects. Love your videos. Thanks again :)
@ieveva
@ieveva 3 года назад
Thank you, very useful video!
@ttahernvoice6154
@ttahernvoice6154 5 лет назад
Thanks,Thanks,Thanks,Thanks,Thanks,Thanks,Thanks,Thanks,Thanks,Thanks and unlimited gratefulness. It was very helpful. It was mind-blowing. Please keep uploading this kinds of smartest and highly useful videos And you are also mind-blowing.
@KevinPowell
@KevinPowell 5 лет назад
Thank you for the kind words, very happy that you enjoyed the video!
@ttahernvoice6154
@ttahernvoice6154 5 лет назад
@@KevinPowell You are most welcome. I have become your fan
@patriayvida4209
@patriayvida4209 3 года назад
Awesome! Thanks for sharing! You've got a new subscriber!
@aCitizenJOSerased
@aCitizenJOSerased 4 года назад
That's cool! I didn't know that margins, top and bottom, work like that on flex and grid!
@khalidkhan5308
@khalidkhan5308 6 лет назад
Don't know how to thank you. Good job !
@longtran12345678
@longtran12345678 6 лет назад
awesome, with this tiny timebox, this video makes me feel great, thanks a lot
@DennisHorn1981
@DennisHorn1981 2 года назад
Once again, you did an awesome job here! Very clear and high dense content! Thank you! 😀👍
@vladimirbugarin
@vladimirbugarin 5 лет назад
Thanks, this hepled a LOT!!!
@monkeynippleking3615
@monkeynippleking3615 3 года назад
I have tried to solve this as a beginner half a day , if there can be more short videos like this people like me save a lot of time going through long videos and getting the intel they need real quick. thanks for the video.
@AudioJunkie79
@AudioJunkie79 3 года назад
Very useful and too the point. Thank you so much for this.
@heatvisuals
@heatvisuals 5 лет назад
Awesome video brother. I love being able to view these videos on my phone, and still see the code large enough without my glasses. It’s poifect!!
@KevinPowell
@KevinPowell 5 лет назад
It's hard for me to work with the font-size so big, but I know the pain of trying to watch coding videos on a small screen, so I'll continue suffering through it :P
@markiddon4346
@markiddon4346 4 года назад
This is a great demo Kevin, thanks!
@Crickera
@Crickera 4 года назад
this video was phenomenal!!!!
@ghostandgoblins
@ghostandgoblins 4 года назад
Loved this! Like any good performance, the audience is always happy when the performer goes over time ^.*
@hopelavender3967
@hopelavender3967 4 года назад
SOOO HELPFUL!!
@digigoliath
@digigoliath 5 лет назад
Useful tips for a newbie like me. TQ.
@cartooncutis
@cartooncutis 3 года назад
Super sir perfect explain
@kiransahu157
@kiransahu157 5 лет назад
Yes, need more.... Please
@tsdineshjai8565
@tsdineshjai8565 3 года назад
great Kevin ! Nice video
@shashankshukla5438
@shashankshukla5438 5 лет назад
Damn, the margin thing is new to me. Thanks man.
@nikhiltyagi1080
@nikhiltyagi1080 6 лет назад
Thanks a lot! Had no idea about the last one, neither have I read about it anywhere else
@KevinPowell
@KevinPowell 6 лет назад
I was so happy when I discovered that one :)
@gunterfx
@gunterfx 3 года назад
Thank you so so so so much!!!!
@joyvideos1802
@joyvideos1802 3 года назад
very worthy... Thanks
@ChazAllenUK
@ChazAllenUK 4 года назад
Good job!
@dhanashekaranm4725
@dhanashekaranm4725 4 года назад
Wow, Super Cool !
@msmediascreenentertainment1951
very good class
@danielEpifanov
@danielEpifanov 4 года назад
Awesome, thanks a lot
@peoplearecool8766
@peoplearecool8766 3 года назад
In the example of absolute positioning centering is not quite right because you used text-align: center in body element and that was the only reason why text in .absolute p was aligned center - horizontal :D I was very confused why text was centered even so you did not centered it, I figured it out that your other selectors was the reason of it but took me quite some time to find it was in body tag , although it was very good tutorial learned few useful things.
@facundocorradini
@facundocorradini 6 лет назад
Nice to see you kept it bellow the target 5 mins. Funny enough I've got an article with 12 ways to vertically center with CSS coming out next week :)
@KevinPowell
@KevinPowell 6 лет назад
12?! Hah, putting me to shame (though I wouldn't be able to do that in 5-minutes :P). Send me the link when it's up and I'll add it to the description of the video!
@facundocorradini
@facundocorradini 6 лет назад
Kevin Powell awesome. Yup, some really old stuff there (like the ghost element method) and variations on the flex and grid techniques. Still most will always just use the good old top 50% translate -50%.. that's a classic that will never go away.
@DJizz82
@DJizz82 4 года назад
Thank you !!!
@thevloglife105
@thevloglife105 5 лет назад
This video is really awesome work. I really appreciate it. Thanks for sharing this tutorial.
@KevinPowell
@KevinPowell 5 лет назад
Really glad you enjoyed it!
@asadrana2
@asadrana2 5 лет назад
thank you just the video i was looking for
@jaskolkaoknowka
@jaskolkaoknowka 3 года назад
I needed that video in my life Praise the CSS God
@UltimatePiccolo
@UltimatePiccolo 4 года назад
Maybe this should be 7 minute sundays.
@muneebahmad8772
@muneebahmad8772 4 года назад
Amazing boss
@Digmen1
@Digmen1 4 года назад
Great, but with flex and grid, how do you just centre vertically and not horizontally as well?
@happynight6533
@happynight6533 4 года назад
Bro (claps) you showed ways that are too good to be real :P
@parasarora5869
@parasarora5869 6 лет назад
i really needed this topic...i loved all the solutions...thanks for the tips Sir✌️😋✌️
@KevinPowell
@KevinPowell 6 лет назад
Glad it was a helpful topic :)
@kerbman456
@kerbman456 3 года назад
Flexbox ❤️
@ChrisLocke1969
@ChrisLocke1969 5 лет назад
Great tips! It would be awesome if you could include a browser version support chart at the end of your videos... personally, i try to avoid considering a feature or style as "old school" until the new school ways are 100% supported. Thanks for the videos.
@KevinPowell
@KevinPowell 5 лет назад
I have a video coming out just about browser support, but you have to wonder if anything will ever be 100% supported! Even border-radius isn't! I would prefer to link in the description though, rather than include it in the video, because a year from now the screenshot I have in my video would be out of date. Don't let new things scare you off though. Just because something isn't supported doesn't mean we can't use it. Grid is being used in production by large companies today, as are many other more modern things. There are simple ways that we can work and ensure that people still have a good experience even if what we are doing isn't perfectly supported.
@nitram_nosnibor
@nitram_nosnibor 2 года назад
I really like this, but not the time limit. I have never understood with, it's not like the old days of SMS eh :) So what if it takes 8 minutes, the more the merrier in my book - Cheers Kevin
@skyfreak42
@skyfreak42 3 года назад
very nice series your #fiveminutefriday pls do not stop and a topic that I could wish for If I had a wish ... CSSing select boxes the right way
@geographerr
@geographerr 3 года назад
Amazing😍
@555pontifex
@555pontifex 5 лет назад
The first 1 minute and thirty seconds was useless waffle. Thereafter, it was ninja-level stuff. Thanks.
@KevinPowell
@KevinPowell 5 лет назад
Some people like my waffling, others don't. Glad you enjoyed the main content though :)
@krantitawade3111
@krantitawade3111 5 лет назад
Superb
@christossotirlis2247
@christossotirlis2247 5 лет назад
hello there. nice video. but what about fixed popups that sometimes we want to be centered?
@KevinPowell
@KevinPowell 5 лет назад
the transform: translate(-50%) trick with absolute positioning would work perfectly :)
@ianfischer103
@ianfischer103 5 лет назад
Currently, As a beginner, it's staggering how many ways there are to solve the same problem. It's also hard to know what way is best to implement. Pros, cons, and gotchas would help, though maybe in a bit longer format than 5 mins. Thanks
@KevinPowell
@KevinPowell 5 лет назад
Great point Ian! It's great that we can do it so many ways, but yes, totally overwhelming too. As a general rule of thumb, I'd use the flex one as the default choice these days (or grid if your project is using grid), and then the position absolute one where the flex option can't work for some reason. But yup, totally might do a more in depth video on this!
@ianfischer103
@ianfischer103 5 лет назад
I would totally love a more in-depth video from you since you explain things so clearly! Thanks for making these videos and keeping them free to watch.
@bs5744
@bs5744 3 года назад
And how to vertically align 3 divs with 2-3 divs inside of each one of them? I did try with flexbox and it's not working sadly . Not sure why . Can you help please ?
@PhilLesh69
@PhilLesh69 3 года назад
I remember when a single pixel transparent gif was the primary tool for centering text vertically.
@KevinPowell
@KevinPowell 3 года назад
Don't remind me 🤣
@pierrecarvalho6878
@pierrecarvalho6878 5 лет назад
1) table 2) absolute (top 50%) 3) flexbox 4) grid 5) margin auto
@SazikimiJaeger
@SazikimiJaeger 6 лет назад
☺☺☺ Very helpful. Thanks Man.
@benzflynn
@benzflynn 3 года назад
_place-items: center;_ This also works with flexbox.
@kallejungstedt2785
@kallejungstedt2785 5 лет назад
really good viedo thanks!!!
@nawabali385
@nawabali385 4 года назад
Awesome :)
@mohan9285
@mohan9285 4 года назад
#fiveminutefriday is an awesome idea.
@techshab9060
@techshab9060 6 лет назад
Thank you soooooo much sir
@roadtoroad9374
@roadtoroad9374 4 года назад
Awesome
@jonmichaelgalindo
@jonmichaelgalindo 4 года назад
Back in the day, we had to specify a height of an element.
@JR-em2hn
@JR-em2hn 4 года назад
Great video Kevin! Can we use this method for centering logo on the navigation bar? All the other elements are moving like home, about etc...
@KevinPowell
@KevinPowell 4 года назад
Sure can!
@maxmanuel_dev
@maxmanuel_dev 5 лет назад
nice !
@hridoytech5030
@hridoytech5030 3 года назад
I will bring the big paragraph in the margin auto in absolute please help me sir
@BalachandranSumathiB
@BalachandranSumathiB 4 года назад
For images also same?
@sridhark8947
@sridhark8947 5 лет назад
Amazing Kev! Simply amazing! Had you been a lady I would've showered you with flowers and bouquets.
@KevinPowell
@KevinPowell 5 лет назад
haha, I'll take some beer instead 🍻
@john_wick_v2gamer361
@john_wick_v2gamer361 3 года назад
o my lord god.... bless your well deserved soul...
@premkumar-rw9jg
@premkumar-rw9jg 3 года назад
tq
@Prutswerk
@Prutswerk 5 лет назад
The flex/grid box method is the only sensible one here. Changing block level elements into inline elements or changing elements into table cells is just dumb, then you better stick with using tables as layout and put the valing="middle" property in the td element.
@KevinPowell
@KevinPowell 5 лет назад
I still use the position: absolute one with transforms on it quite regularly. Seems like we wouldn't have to with flex and grid, but it comes up as a useful solution often enough that I'm very happy to know it :)
@babsake
@babsake 5 лет назад
If you had issues with centering your element using the second method(absolute positioning) despite doing exactly what Kevin did, all you need to do is to remove the margin of the paragraph element ie .absolute p{ margin: 0; }
@inayathkhan100
@inayathkhan100 5 лет назад
Too good Sir, You're from which country ? I am UI/ UX Designer from India
@KevinPowell
@KevinPowell 5 лет назад
I'm in Canada :)
@ahsujon725
@ahsujon725 4 года назад
In table, p element no align vertically center, its element content align center!
@vikkramv4573
@vikkramv4573 4 года назад
the best
@wgm247
@wgm247 5 лет назад
1.39 it starts
@javascriptwar9525
@javascriptwar9525 5 лет назад
sir please upload video on svg with animations.
@KevinPowell
@KevinPowell 5 лет назад
It's really not an area of expertise for me!
@lowzhao
@lowzhao 5 лет назад
When the content is img i always have problem center it, flex just break the aspect ratio of the image and i dont want to set the width and height together because the images might have different aspect ratio. Any suggestions?
@KevinPowell
@KevinPowell 5 лет назад
using 'align-self: center' on the image should work with flex. Flex defaults to 'align-items: stretch', which can stretch images, so yes, we usually need to change that behaviour :)
@lowzhao
@lowzhao 5 лет назад
@@KevinPowell Thank you so much I think it finally works.
@jefthesales
@jefthesales 6 лет назад
That's cool! Can I just ask you something? I'm learning CSS like a 3 months and a lot of your videos you use Sass.. Can I learn Sass with CSS at the same time?
@KevinPowell
@KevinPowell 6 лет назад
You can! I'd say to be moderately comfortable with CSS first though, there are a few things that Sass makes really easy to do, which can build a few bad habits along the way, so to be careful with that. But I don't see why not, at the end of the day, you're just adding some extra functionality on to CSS. Might make the learning curve a little steeper, but it's easy enough just to add a few basic things to start with.
@jefthesales
@jefthesales 6 лет назад
Kevin Powell Thank you so much
@andy5003
@andy5003 5 лет назад
Which way is most performant and compatible tho?
@KevinPowell
@KevinPowell 5 лет назад
I'd believe they'd all be just as performant. Flexbox has wide enough support that, except for some edge cases, it's probably the best bet at the moment, and if you don't mind pushing things a little (or building in a fallback), grid support is actually pretty high.
@KevinPowell
@KevinPowell 5 лет назад
I'd believe they'd all be just as performant. Flexbox has wide enough support that, except for some edge cases, it's probably the best bet at the moment, and if you don't mind pushing things a little (or building in a fallback), grid support is actually pretty high.
@KevinPowell
@KevinPowell 5 лет назад
I'd believe they'd all be just as performant. Flexbox has wide enough support that, except for some edge cases, it's probably the best bet at the moment, and if you don't mind pushing things a little (or building in a fallback), grid support is actually pretty high.
@ernestogutierrez5684
@ernestogutierrez5684 6 лет назад
You'll have quite a few views for this very soon. Nice.
@KevinPowell
@KevinPowell 6 лет назад
Glad you liked it Ernesto! Thanks for the words of encouragement!
@jamesbrooks9321
@jamesbrooks9321 5 лет назад
hahaha i just watched another of your 5 minute videos and thought of peter
@KevinPowell
@KevinPowell 5 лет назад
Who's peter?
@jamesbrooks9321
@jamesbrooks9321 5 лет назад
@@KevinPowell Peter McKinnon
@georgesmith3022
@georgesmith3022 6 лет назад
i have seen somewhere using line-height, but i don't remember the details.
@KevinPowell
@KevinPowell 6 лет назад
Oh, I forgot about that. I used to do that. The problem with it is, it relies on something being a fixed height, but basically, if you have one line of text, you can center it vertically by making the line-height be equal to the height.
@USPSLaura
@USPSLaura Год назад
what if i want to center the child of a flexbox item
@АртурГайдов
@АртурГайдов 5 лет назад
FlexBox is top
@harishaananth5167
@harishaananth5167 3 года назад
1:10
Далее
Flexbox or grid - How to decide?
18:51
Просмотров 729 тыс.
5 CSS mistakes that I see way too often
19:03
Просмотров 360 тыс.
Катаю тележки  🛒
08:48
Просмотров 293 тыс.
Se las dejo ahí.
00:10
Просмотров 851 тыс.
Flexbox design patterns you can use in your projects
15:33
5 simple tips to making responsive layouts the easy way
15:54
How to take control of Flexbox
16:01
Просмотров 135 тыс.
Learn CSS Grid the easy way
37:04
Просмотров 911 тыс.
Learn CSS Flexbox in 20 Minutes (Course)
20:37
Просмотров 130 тыс.