Тёмный

Margin and Padding Deep Dive: The basics 

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

Margins and padding cause a lot of confusion amongst new developers. This video is the start of a deep dive miniseries taking a look at them.
This video is really a look at the very basics of margins and padding, what each one do, and what the differences are between the two of them.
I also take a look at how auto margins work, and why & how we can use them to center something vertically on the screen. In this section though, I did forget to mention that for these to work, the element also needs to have an assigned width as well (thanks to Jon for pointing that out in the comments)!
Part 1: The Very Basics (this video)
Part 2: Collapsing margins and box-sizing - • Margin and Padding Dee...
Part 3: Using Whitespace effectively - • Margin and Padding Dee...
---
My Code Editor: VS Code - code.visualstudio.com/
How my browser refreshes when I save: • How to automatically r...
---
Support me on Patreon: / kevinpowell
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my RU-vid channel, make sure to follow me on Instagram and Twitter.
Instagram: / kevinpowell.co
Twitter: / kevinjpowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell

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

 

31 май 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 131   
@Anon-te2bz
@Anon-te2bz 5 лет назад
What I've learned so far from this vid: So padding is creating space inside of a content, while margin is creating space outside of a content. You can also adjust specific spaces for both padding and margin, such as -left, -right, -top, -bottom, or you can all do it in one property. Lastly, using auto will take the biggest space as much as possible. You can also use auto to center objects. However, auto will be calculated as 0 when using it for -top and -bottom. Good video, thank you!
@KevinPowell
@KevinPowell 5 лет назад
You summed it up the entire video in a couple of sentences. I think I could have made this shorter, lol.
@hackzgamezyt
@hackzgamezyt 3 года назад
Someone's taking notes!
@closetgrasshopper2627
@closetgrasshopper2627 6 лет назад
Your explanation is so clear and concise. I feel like 90% of programming tuts videos here are some Indian guy or some computer science nerd who have no social skills, trying to explain things but end up just rambling. Thank you for this. VERY MUCH
@KevinPowell
@KevinPowell 6 лет назад
You're very welcome Closet Grasshopper! Really glad that you like the video and how I present my stuff :)
@rootuser5652
@rootuser5652 3 года назад
@shashanka Mg pretty sure she was referring to the “computer science nerd” as the one with no social skills.
@Hannibalism
@Hannibalism 3 года назад
Ah, finally someone that gives it loud and clear with no confusing metaphors.
@ginasta7575
@ginasta7575 2 года назад
Exactly! Sometimes I prefer watching the indian tutorials because they get straight to the point (even though I don't speak Hindi I somehow learn visually)
@mdchowdhury3874
@mdchowdhury3874 4 года назад
Your explanation was very clear. Though I've finished my course, I can say confidently that today, after watching this video, I've learned margin and padding and now, no more nervous about these two confusing things. Thanks, Kevin for your nice video.
@sebastiandelima7385
@sebastiandelima7385 4 года назад
Thank you so much for taking the time to explain these concepts, you can tell that you put a lot of good intention and consideration on this video, it's a total like for me.
@abdulrehman5159
@abdulrehman5159 2 года назад
Now I understood completely! Thanks for the detailed video on the topic.
@pelosuelto70
@pelosuelto70 4 года назад
You are a Godsend to those learning how to code! I finally understand how margin and padding works in a deeper way. Thank you!! Subbed!
@KevinPowell
@KevinPowell 4 года назад
Welcome aboard!
@yadusolparterre
@yadusolparterre 2 года назад
Excellent tutorial, there are so many tutos here but this one goes deeper and I finally got it after many years of confusion
@Bas_Code
@Bas_Code 5 лет назад
Trust me, you are jzt the best all...... The teaching is so so accurate and clear... Kudos..am subscribing right away
@NeroIvanY
@NeroIvanY 6 лет назад
Thanks for your work, Kevin. Very clear explanation. Looking forward to the third video! very interested in your thoughts about real life cases!
@KevinPowell
@KevinPowell 6 лет назад
Thanks Ivan, glad you liked it. And that video will be out Friday, so not too long to wait 👍
@benjirification
@benjirification 6 лет назад
I just loved this series and the way you explained it easily.Looking forward to watch next :)
@KevinPowell
@KevinPowell 6 лет назад
Thanks Benjir, glad you liked it :)
@NeoKarthik
@NeoKarthik 4 года назад
I finally get he margin: auto statement. Thank you so much!
@niraj2216
@niraj2216 Год назад
Beautifully Explained. Thank You.
@BUDX
@BUDX 4 года назад
Thank you very much for explaining this. I was really struggling with this but now it's all clear.
@vanessakimana3929
@vanessakimana3929 2 года назад
Thanks Kevin for clarifying this 👏🏽
@marana.th4
@marana.th4 2 года назад
he literally took oversimplification to another level, I wish all my teachers were like you🥲thanks a bunchhh
@tbgan6675
@tbgan6675 6 лет назад
Thumbs up for every series. Helping many of us especially those who just beginner
@KevinPowell
@KevinPowell 6 лет назад
Thanks a lot, and I'm happy to help 😁
@adhityapoernama940
@adhityapoernama940 6 лет назад
A very straight and clear explanation video! thank you!
@KevinPowell
@KevinPowell 6 лет назад
Thanks, glad that you liked it!
@omphemetsemafoko830
@omphemetsemafoko830 10 месяцев назад
Thank you for the clear explanation.
@Brospeh00
@Brospeh00 3 года назад
Very informative, thanks Kevin!
@paketa7736
@paketa7736 4 года назад
You are a great teacher. Thank you, teacher!
@robertrydlewski9538
@robertrydlewski9538 5 лет назад
Kevin ... Your the best, period. Thanks a lot
@drummerdev5522
@drummerdev5522 6 лет назад
Great series on margins and padding. One thing that may help new learners with the margin auto centering method is making sure they know the containing div's width. I can't count how many times I tried to use the margin auto method and wanted to shake my computer, because I nested or the parent width was not 100% of the screen size. I also enjoyed seeing the BEM naming convention in the third video. It seems to be the current favorite of the industry and it is something I myself am currently trying to get into the habit of using. :)
@KevinPowell
@KevinPowell 6 лет назад
Oh man, I totally should have mentioned giving it a width for that to work, totally missed the mark on that. Thanks for mentioning it though, I'll add it in the description of the video. I always liked the concept of BEM, but the whole double underscore thing sort of annoyed me, but the more complicated projects you work on, you start to see the benefit of it all. I'm happy I'm playing around with it now, and I think it's won me over at this point.
@marcusmorrow3900
@marcusmorrow3900 4 года назад
Good stuff. Well explained
@JLDReactions
@JLDReactions 2 года назад
Great explanation.
@everlastproducciones9280
@everlastproducciones9280 3 года назад
Thanks for your time
@calvinebun-amu5397
@calvinebun-amu5397 3 года назад
Great video, Kevin.
@rahuldora1587
@rahuldora1587 3 года назад
Awesome explanation love It ❤️
@ingridhernandez2782
@ingridhernandez2782 3 года назад
I appreciate your videos so much. Thank you
@arvindk4813
@arvindk4813 4 года назад
I was looking for this , yeah this is it thank you.
@anyzzas7149
@anyzzas7149 6 лет назад
Thanks for the good tutorial.
@abouhashim100
@abouhashim100 3 года назад
first time to know the difference... thanks
@moritz584
@moritz584 3 года назад
great vid!
@shivarammuthukumaraswamy7164
@shivarammuthukumaraswamy7164 4 года назад
loved the explanation..tysm buddy..
@webb-developer
@webb-developer 9 месяцев назад
perfectly explained ✅
@muratg9395
@muratg9395 2 года назад
Thank you Kevin.
@Tesla-Live____
@Tesla-Live____ 4 года назад
thanks the tutorial was so helpful
@KradianKrad
@KradianKrad 4 года назад
Best explanation!
@jashanpreet880
@jashanpreet880 3 года назад
welll done sir i was struggling with this property
@krishnamohanyerrabilli4040
@krishnamohanyerrabilli4040 3 года назад
Thanks for that Sir.
@pauljohn3898
@pauljohn3898 3 года назад
Feel lucky to know you from the very beginning I learn CSS
@_ata_3
@_ata_3 Год назад
Thank you. Do you recommend using background or background-color when setting a colored background?
@brogen100
@brogen100 5 лет назад
mind blown! I nominate you teacher of the year
@KevinPowell
@KevinPowell 5 лет назад
Thanks so much 😊
@mohammadakramsheik1657
@mohammadakramsheik1657 5 лет назад
Best video, thank u very much
@olenasid8
@olenasid8 2 года назад
Thank you!
@acidhauss7018
@acidhauss7018 3 года назад
I am a full stack developer bodge together website and i have no fing clue what im doing with css but your videos help me a lot thank you
@tristanmckellen9972
@tristanmckellen9972 4 года назад
thank you so much!
@mahdi3521
@mahdi3521 3 года назад
man can't thank u enough legend
@ericdy2118
@ericdy2118 3 года назад
thanks so much!
@RamonMartinez-jz9uv
@RamonMartinez-jz9uv 6 лет назад
Great job Kevin, very clear video. A couple questions seem to arise though...does it seem strange that css defaults div boxes to the upper left hand corner? Like why wouldn't it default to any other alignment, say centered, or to the upper right corner, or lower left corner? Is that just per the spec--and if so where can we view the spec details themselves? My initial guess was CSS mimics the left to right nature of western languages, but then why does CSS stack the boxes in a column and not in a row, again as western languages do? Any thoughts are greatly appreciated.
@KevinPowell
@KevinPowell 6 лет назад
Divs are block-level elements. Any block level element automatically starts a new line of content and takes up the full width of its parent (by default). This is also why it stacks things, because block-level elements automatically start a new line of content, whereas inline and inline-block elements do not. A div behaves the same way as a paragraph, they are both block-level. If paragraphs created columns instead of new rows of content, that would be a pain! If we give it a set width, then yes, it's on the left side. It starts at the top because, well, I'm not 100% sure where in the specifications it talks about that, but if it didn't it would be hard to build a website (from bottom to top???). I could be wrong, but starting from the top makes it a lot easier than anything else, that way our content follows the flow of the HTML we're writing. As far as it being on the left, if we give it a width, yes, it's on the top left. However, like you said, if you set your site up for a right-to-left language, it would go to the top right, instead of top left (you can read more on that here: www.w3.org/International/questions/qa-html-dir ). This, I think, makes a lot of sense. As far as the documentation, w3.org is where all of it would be, in relation to the standards, though I often find that the MDN is much more user-friendly as it includes examples and browser support tables, as also links to both the existing standard, as well as working drafts for future implimentations - developer.mozilla.org/en-US/
@space_monkey125
@space_monkey125 6 лет назад
Hi kevin, thanks for the awesome videos. It helps me alot. :)
@KevinPowell
@KevinPowell 6 лет назад
Glad to hear that Ameen!
@gaetanoalessandro286
@gaetanoalessandro286 4 года назад
Hi, thanks a lot for sharing your knowledge: you 're helping me!! :-)
@vampirekabir
@vampirekabir 5 лет назад
man!you explain like a bosss!!
@KevinPowell
@KevinPowell 5 лет назад
Thanks! Super glad you liked it!
@khilapsingh2838
@khilapsingh2838 6 лет назад
Thank you very much Kevin!!!!!!
@KevinPowell
@KevinPowell 6 лет назад
No problem!
@cow240
@cow240 4 года назад
very useful, thanks! However you mentioned margin-left and margin-right 0 will centre it across the screen at the 12.03 minute mark. Is that right?
@baljeetgulati4605
@baljeetgulati4605 4 года назад
hats off to u sir!
@alvarocarrilho
@alvarocarrilho 4 года назад
Thks From Lisbon - Portugal
@AmanSharma-bv4ii
@AmanSharma-bv4ii 2 года назад
thank you uncle 🙏🏼
@bloc-notes6751
@bloc-notes6751 5 лет назад
You are the best !
@JonFuller1004
@JonFuller1004 6 лет назад
One thing I have bumped into recently was padding and or margin was causing my elements to break out of the container when using grid. Not quite sure why they wanted to do that. I thought with grid. If the size of he object or the margin or padding got to wide it would auto go on to next column. Maybe I was mucking something up
@KevinPowell
@KevinPowell 6 лет назад
Nah, things will overflow outside of their cell if they are bigger than the cell. By default, something will be taking up one row and one column, it won't automatically assume that it should actually take up two. That *could* be a cool behaviour, but I could also see it causing some problems.
@justaguywholikeshentai9019
@justaguywholikeshentai9019 2 года назад
KING OF CSS!
@seemsas
@seemsas 6 лет назад
Thank you
@lifeofdidrik
@lifeofdidrik 7 месяцев назад
Please correct me if i am wrong Margin creates space outside the element with the content on the inside and padding creates space on the inside?
@wilfredomendez3450
@wilfredomendez3450 6 лет назад
Sweet, thanks
@KevinPowell
@KevinPowell 6 лет назад
No problem 👍
@learntocode1878
@learntocode1878 4 года назад
Hi Kevin, thank you for this video brother. I subscribed. Your videos are the best. Can you please show how to create a one page scroll
@dhanushsivajaya1356
@dhanushsivajaya1356 3 года назад
Thankyou sir
@dynamic-homepages
@dynamic-homepages 2 года назад
Thanks =)
@namekomuna1129
@namekomuna1129 2 года назад
Yeah I got this. Choose according to your need. If you are done with margin, stick with it. If padding can do it, use padding.
@shrookwageh5976
@shrookwageh5976 4 года назад
what to say. you're so awesome
@damion5874
@damion5874 5 лет назад
Thanks for the teaching. Looks like the thumb nail for this video has a misspelling.
@iboro-kun84
@iboro-kun84 3 года назад
No, thank you, Mr Powell. You're awesome, not a little bit.🤝
@chma0
@chma0 2 года назад
Hi , can you help me with a website i build I have a problem with show more bottom and the position of the bottom. If u will I'll show you the code and pic for the problems please help me
@tochiojukwu2614
@tochiojukwu2614 Год назад
So i can use margin to change the position right?
@sbtoolman12123
@sbtoolman12123 2 года назад
This is going to seem like a stupid question, (and more than likely is). But, if you set for values for the margin ( say 100 50 100 50 and it sets these in a clockwise fashion, you then erase the last one so it is now 100 50 100, why would css use the 50 value instead of just using the default (since there is no value assigned to it)? Yes i am VERY new to all of this. (HTML, CSS...all of it.)
@BishalDas-xu4zi
@BishalDas-xu4zi 2 года назад
A thanks from an Indian ❤️
@kevincrum2375
@kevincrum2375 9 месяцев назад
ive been curious about how gap also fits into this
@adarshsoni5323
@adarshsoni5323 6 лет назад
Hi Kevin please make video series on JavaScript from beginners to expert level .....please
@KevinPowell
@KevinPowell 6 лет назад
I'll be making and using JavaScript more, but I think a whole series would kill me, haha. There is just sooooo much to cover.
@Bas_Code
@Bas_Code 5 лет назад
Pls try a teaching on java script from basic jzt like you did on this..... Pls pls pls....
@willl0014
@willl0014 6 лет назад
Black deep!!
@eileenmfox4266
@eileenmfox4266 2 года назад
I don't see a link to the codepen.
@TheCrusaderRabbits
@TheCrusaderRabbits 6 лет назад
It is good.
@KevinPowell
@KevinPowell 6 лет назад
Thanks, glad you liked it :D
@elhamzeinodini4828
@elhamzeinodini4828 3 года назад
💥🌹
@happyhuman8549
@happyhuman8549 5 лет назад
pls make a video about borders!!
@KevinPowell
@KevinPowell 5 лет назад
What do you want to know about borders? I generally don't do much with them, so I'm curious :)
@amitpandhare2663
@amitpandhare2663 Год назад
my mam used to say, "never trust a man who does a spelling mistake in a thumbnail"
@sheeshee6351
@sheeshee6351 3 года назад
The thumbnail says Bascis. Is it intentional or no one noticed in 3 years ?
@ycombinator765
@ycombinator765 3 года назад
B A S C I S
@amirani836
@amirani836 3 года назад
your video's, maks me feel, that I have progess
@sknEK_code_chef
@sknEK_code_chef Год назад
very helpful. but the image is "the very bascis" :)
@rio2572
@rio2572 3 года назад
thought this was about stocks.. i was eating then was sooooo confused when he started coding lmao oops wrong video
@wholeness
@wholeness 4 года назад
Just for the observer, you never actually answered the question when to use one versus the other. Great tutorial though.
@KevinPowell
@KevinPowell 4 года назад
It's not always so simple, but I like to look at it as padding for more background, margin for extra space.
@SM-ok3sz
@SM-ok3sz 3 года назад
Your title card is misspelled
@network_noob
@network_noob 2 года назад
@driziiD
@driziiD 3 года назад
damn, i wanmted you to explain border
@PswACC
@PswACC 3 года назад
Your thumnail for this video has a Typo
@william3588
@william3588 2 года назад
Margin does not affect element width, its just border and padding, no?
@tanushs08
@tanushs08 3 года назад
10:50 margin top : auto = 0 margin bottom : auto = 0
@MesutAkcan
@MesutAkcan 4 года назад
the very BASCiS !!! ???
@js_programmer8423
@js_programmer8423 5 лет назад
so padding is basically height & width in an alternative way
@KevinPowell
@KevinPowell 5 лет назад
A more dynamic way, yes :) - will adjust to your content, which is nice.
@psyrotix2463
@psyrotix2463 5 лет назад
"Deep Dive: The Basics" LOL
@KevinPowell
@KevinPowell 5 лет назад
Gotta start somewhere with the deep dive 😁
@psyrotix2463
@psyrotix2463 5 лет назад
No I was just laughing at the oxymoron, great video though!
@TheDJDannyJ
@TheDJDannyJ 3 года назад
it works very, exactly, much the same... hahahah, oookay.
@ninjaaljun7674
@ninjaaljun7674 2 года назад
.
Далее
5 CSS mistakes that I see way too often
19:03
Просмотров 358 тыс.
КОРОЧЕ ГОВОРЯ, 100 ДНЕЙ В СССР 2
08:37
HELLUVA BOSS - THE FULL MOON  // S2: Episode 8
23:10
Просмотров 4,4 млн
12 VS Code Extensions to INCREASE Productivity 2024
27:13
CSS Selectors - beyond the very basics
18:47
Просмотров 39 тыс.
Learn Zod In 30 Minutes
31:03
Просмотров 130 тыс.
Zed - A Visual Studio Code Killer?
9:28
Просмотров 88 тыс.
min(), max(), and clamp() are CSS magic!
18:12
Просмотров 288 тыс.
10 CSS Pro Tips - Code this, NOT that!
9:39
Просмотров 2,1 млн
Avoid these 5 beginner CSS mistakes
21:38
Просмотров 50 тыс.
Margin and Padding Basics in Elementor
12:51
Просмотров 71 тыс.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
Просмотров 891 тыс.