Man that was a greeeeeeaaaaaattttt problem solveeeeeedddddd, AMAZINGGGGGGG!!!! THAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANKS!!!!
@@Thorin-uf4yt but., If I want particular size of the div box., That time how to i put value of Height in vh., If I put like ur suggestion., The div height is collapsed..😢
for me if i want to center only horizontally i just do it like in the old days and use the center html tag (although i think it’s deprecated), but if I want to center both ways i use flex like in the video.
I see you also dont see red markings in vscode as errors and rather as suggestions... i, too, used center tag a while back but can't stand red in vscode, so I stopped, but yeah, it still works in all browsers
@@gon2064actually its not a good practice because it will set all 4 direction to auto so @arm162 code is perfect because first value js for top and bottom and second value is for left and right Btw U can use Margin-inline:auto; Sry for bad English
This only works when I include the height of the parent container (100vh) - but now my question is… why doesn’t 100% work, and how do I stay away from vh units, leaning towards percentages while accomplishing the same thing?
Technically nothing at all 😂 I find myself doing that from time to time, but the flex method replaced it in most of my codes. And I also guess it's easier. And ofc there are a few other solutions, and other than using a tag (which is has been outdated because of lost support from browser quite some time ago) and maybe a few other things, they all are working and up to you what you'll choose.
The element (div, body or article) must have a height for it to work. body{ display: flex; justify-content: center; align-items: center; height: 100vh; }
If your div is big enough, it's always centered.
haha, nice one
Lol
it's funny but true af
Is the div classed as „parent“ or why does it start with .parent? (I’m new)
@@overdrive112it's probably just an example, if its .parent then its a class="parent" (I'm 99% sure)
10 seconds later: "oh, lemme google how to center a div again" 😂😂😂
Literally 😭 😭
You are a god amongst men. Working on a project for a class and in seconds you gave me an answer that other videos took minutes to get incorrect.
Except he is so wrong about these being the only correct ways. Remember, the correct way is the way that works
Unless for some reason you need to use position: fixed or absolute in which case you can use inset: 0; margin: auto; 😉
Thank you!
Only option if you want to rotate object in center point when you centered it.
the relief i felt when my way is the first one you mentioned 😅
+1
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%)
margin: 0 auto;
@@RubyPiecI thought I saw center was depreciated?
@@StarForgers oh it is?
Animation - wise this is bad
Saving lives of those who are beginners in coding, thank you !
Wooooewewwww thank you. Bro best video I’ve found
"Carefully, he's a hero"
that grid one... you were sent by god
Man that was a greeeeeeaaaaaattttt problem solveeeeeedddddd, AMAZINGGGGGGG!!!!
THAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANKS!!!!
This vídeo helped me a lot
thanks man i've been searching for a way to center a div without all the extra crap
this was so helpful thank you so much
justify-content : center is what I was looking for
It's 2023 and they are still correct
love it!
place-items: center works in flex aswell.. is a shorthand.. also.. inset prop..
JESUS MY SAVIOR MY SAVIORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
that grid part is new ... thanks man
Brother, thank you very much.
Honestly after learning all these I still kinda like “left: 50vw; translateX: 50%” + repeat for top/y
thanks buddy
Yeah you need to do display: absolute/fixed center as well :)
Can you explain why? I'm learning and not understanding all these different methods
Absolute/fixed is a values from position, nothing related with display bruh
thankyou so much!!!!!!
0:00 for the normal version
thanks brother
sadly it didnt work out for me. I tried both correctly but I dont know where its falling apart.
You need to set the parent div height
@@Thorin-uf4yt but.,
If I want particular size of the div box.,
That time how to i put value of Height in vh.,
If I put like ur suggestion.,
The div height is collapsed..😢
Just subbed
thank you!
Me :
margin-top: 50em;
😂
Very cool 🎉
for me if i want to center only horizontally i just do it like in the old days and use the center html tag (although i think it’s deprecated), but if I want to center both ways i use flex like in the video.
I see you also dont see red markings in vscode as errors and rather as suggestions... i, too, used center tag a while back but can't stand red in vscode, so I stopped, but yeah, it still works in all browsers
Thanks you Soo much
Thank u so much
rip
ohh... thank jesus that's what i am searching for ..
its 2023 man! make another video
Thank youu!
my way to center a div (first one)😅
I cant remember positioning for more than 1 hour 😅
i will use "margin: 0 auto" forever
The king of inline-block
.container {
width: 90%
margin: 0 auto
}
Is it different if i use margin: auto; ? Because its work too
@@gon2064actually its not a good practice because it will set all 4 direction to auto so @arm162 code is perfect because first value js for top and bottom and second value is for left and right
Btw U can use
Margin-inline:auto;
Sry for bad English
This has never worked for me
There are other ways like:
Display: block;
Margin: 0 auto;
And
Parent {
Position : relative;
}
Child{
Position: absolute;
Top: 0;
Left: o;
Transform: translate (-50%,-50%)
}
Best way
Margin-top: 10px;
Margin-left:10px;
😅😅😅😅😅😅😅
Thanku😊
justify content center saved me thanks programming jesus
Align-item center for no reason won't change 💀
Ty!!
thanks!
What about margin:auto;
This only works when I include the height of the parent container (100vh) - but now my question is… why doesn’t 100% work, and how do I stay away from vh units, leaning towards percentages while accomplishing the same thing?
Without first and last point how you find center point?
Position absolute and transform.
thanks dear
So what's wrong with margin: auto; or position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) and many other solutions?
Technically nothing at all 😂 I find myself doing that from time to time, but the flex method replaced it in most of my codes. And I also guess it's easier. And ofc there are a few other solutions, and other than using a tag (which is has been outdated because of lost support from browser quite some time ago) and maybe a few other things, they all are working and up to you what you'll choose.
that is not true. what if my div is position: fixed;? Then it ignores the outer flexbox container.
What about display inline block
What if my parent is the body(entire page) itself? What css should i add in order for this to work?
@@wollie1769 how abt 100dvh?
Not working.,
Bcz.,
we must mention *height:100Vh* before align- items: center
Can we use it when we want to keep webpage centered while zooming out?
Im not good at css, is a center tag and position: relative, then lowering it 50% ok?
You are from Italy?
what about calc() with hardcoded magic numbers?
I thought it would be ask chatgpt
Position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
this is the 'ol reliable and I still use when I feel icky using grid or flexbox out of nowhere
what about text or span?
After 1 hour of researching the only true answer was a YT short.... And all the answers from Google failed.
I put alignt-items: center and nothing happened T.T
The flex box must have height at 100% ofc
@@semlon5266 thx man
what about ;-;
Its no longer used. It's a very old html tag and html can remove It's support of old tags in future therefore it is not recommended to use center tag
Now this one it's outdated too😢
The element (div, body or article) must have a height for it to work.
body{
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
Height for parent is necessary
Please it not working
What if i have multiple Buttons inside parent and they need to be next to each other in center?
Space-between?
So sad… I still use margin: 0 auto 😂
That’s perfectly fine if you want to center a div horizontally. Better yet, use the logical property margin-inline: center;
Thanks Jesus!
daddy tho
So true
obg
✅✅
didn't work
this didn't work
Wtf is a div? 😆
Glt
Free Palestine 🇵🇸