Margin and Padding Deep Dive: Collapsing margins, resets, and CSS box-sizing

Поділитися
Вставка
  • Опубліковано 9 вер 2024

КОМЕНТАРІ • 200

  • @benibeats4516
    @benibeats4516 6 років тому +122

    Good tutorials, Kevin. Please, don't ever quit UA-cam, you're my inspiration. I'm 16 years old and i want to learn coding and all that stuff to help my family with some income, at the moment i can't afford a paid online class, you're my hope. I will always support you! :)

    • @KevinPowell
      @KevinPowell  6 років тому +32

      That's so awesome! I wish I was as inspired as you at 16. Keep on working hard and it'll pay off!

    • @deltatropie3571
      @deltatropie3571 5 років тому +8

      Hey how is it going? Did you manage to make money out of it and help your family?

    • @andrei8299
      @andrei8299 4 роки тому +4

      @@deltatropie3571 I guess it's too early to have a huge progress which will give a lot of money. He's only 17 currently.

    • @sheldonyu4912
      @sheldonyu4912 4 роки тому +1

      u

    • @terrap0b_ps995
      @terrap0b_ps995 2 роки тому +2

      @Christian Thone probably 20 now. He might have grown super good at coding or might have left it forever.

  • @mdridoy-ef2pw
    @mdridoy-ef2pw 3 роки тому +5

    when starting any project, i always do
    margin:0;
    padding:0;
    box-sizing: border-box;
    never really thought about these problems.
    i just used them because everyone does it as best practice.
    but now i know.
    Thanks a lot!

  • @bencrossley4085
    @bencrossley4085 6 років тому +36

    These tutorials are the best! What you are explaining is genuinely useful and solving the sort of problems we are actually facing. Your delivery is very friendly, well-paced and the explanations are easy to follow. I really look forward to the updates to your channel. Thank you so much!

    • @KevinPowell
      @KevinPowell  6 років тому +2

      Your welcome Ben, thanks for the feedback!

    • @webpad2570
      @webpad2570 6 років тому

      So true!! Very helpful and easy to follow

  • @cindykee3719
    @cindykee3719 5 років тому +5

    Wow, in all of the programming I have done, I never really knew that's what collapsing margins meant! Thank you, Kevin! Your tutorials are great!

  • @AndyMorrisArt
    @AndyMorrisArt 4 дні тому

    Another great video. I now understand a whole lot more than I did 28 minutes ago!

  • @kcsecurity439
    @kcsecurity439 4 роки тому +6

    4:45. Kevin, you coined the international web developer’s motto: “We live to get around it.”

  • @ShortGirlsClimbCounters
    @ShortGirlsClimbCounters 4 роки тому +3

    Loving this series. So so helpful. I've been getting hung up on margin and padding: what they do differently, when to use, etc. Thanks for the tutorials, very straight forward!

  • @Prodkid360
    @Prodkid360 6 років тому +1

    You sir, you have one of the best front end UA-cam channels out, I'm gonna religiously watch all your videos. Thank you for the uploads. I'm learning so much! Keep the great work going, don't stop.

    • @KevinPowell
      @KevinPowell  6 років тому

      Thanks for the kind words, and I'm glad that you're enjoying my content :D

  • @carlos_novais
    @carlos_novais 3 роки тому +2

    Great video tutorial, Kevin. One would think that it would take only 10 minutes to teach Margin and Padding. I really dig these Deep Dive videos. Thank you very much!

  • @nitram_nosnibor
    @nitram_nosnibor 3 роки тому +2

    That was all so well explained, thank you Kevin. I always wondered why it was called "border-box", now I know. Excellent - cheers

  • @kosticivan3921
    @kosticivan3921 4 роки тому +2

    Good job brother! You are friendly, direct, understandable and I really love your content! Your explanations are better than paid curses in my country. Keep on doing a great job!

  • @user-sy7lm6lw8i
    @user-sy7lm6lw8i 2 роки тому

    So many questions I didn't even know how to ask correctly have been finally answered!

  • @Banalitude
    @Banalitude 6 років тому +10

    These videos are so helpful, thank you! They really help to clear some confusion that I previously had.

    • @KevinPowell
      @KevinPowell  6 років тому +3

      So happy to hear that Banalitude!

  • @Ali-wu1rd
    @Ali-wu1rd 3 роки тому +1

    you are a life saver. I was literally scratching my head off due to this annoying collapsing border thing. thanks a lot man. 💖

  • @khyatimamaniya750
    @khyatimamaniya750 4 роки тому +3

    This has helped me understand the margin-collapse problem. This is one of the best explanation I have found. Keep doing the great work. This was really helpful.👌✌

  • @seap9570
    @seap9570 4 роки тому +2

    You've done an excellent job of explaining the collapsing phenomena

  • @unknownperson7298
    @unknownperson7298 5 років тому +2

    You is the man! I took a breath of relief after watching this!

  • @shwezin1565
    @shwezin1565 3 роки тому

    oh man you save my whole night from being wasted on these problems in 22 minutes. Thank you for your great presentation sir

  • @hitabratanath305
    @hitabratanath305 2 роки тому +1

    That was really helpful. You are indeed a great tutor.
    Really appreciate your quality work.

  • @buttslaya
    @buttslaya 3 роки тому +1

    Thanks man, never took the time to dig into CSS so its always seemed so obtuse to me. Videos like this one clear up so much for me.

  • @zakarianassar4264
    @zakarianassar4264 2 роки тому

    Margin and padding are not bad things anymore, go ahead Mr. king of CSS.

  • @holycrimpsauce
    @holycrimpsauce 3 роки тому +3

    Great stuff. My preference is still to add margin top or left first over the other directions. The reasoning being that margin on something should appear to be moving the element it’s on and not the next element.

  • @LupuAlex
    @LupuAlex 5 років тому +1

    These tutorials are great because there's stuff I use to hack around (like using calc(size - padding) to have the actual size of an element) but there's some super obvious solution using an attribute I didn't know about!!!

  • @RyoLight128
    @RyoLight128 5 років тому +2

    4:35 Found myself flabberghasted by this exact behavior before I found your video. Thank you for saving my sanity Kevin.

  • @waliddu62
    @waliddu62 5 років тому

    Wow ty a lot I don't know how much time I had to deal with this collapsing margin, you just saved a lot of my time just with 40 mins of video.

  • @tahaansari2515
    @tahaansari2515 4 роки тому +1

    that was a amazing video kevin this cleared the concept of margin collapsing, i was facing hell lot of issues because of that

  • @shuukeyare8388
    @shuukeyare8388 5 років тому

    Kevin Powell the father of CSS.. really you helped me out with that margin collapse. Thank you buddy

  • @biketips1337
    @biketips1337 4 роки тому

    thanks so much for solving no one youtuber tell this

  • @jellyfish1772
    @jellyfish1772 2 роки тому

    4:20 thanks for showing this.I recently ran into this problem

  • @ryanamberger
    @ryanamberger 5 років тому

    Our teacher taught us about resets (border, padding, margin to 0) but he had us typing out every single element (audio, body, h1, h2, img, p, video, etc) and we would just add to that each time we added something new on our html pages. Didn't teach us about the wild card, makes it much simpler for sure.

  • @JudaBorrayo
    @JudaBorrayo 3 роки тому +1

    You're the man, Kevin! Thank you.

  • @AdolfoBarreto75
    @AdolfoBarreto75 5 років тому +1

    I was going through your videos and found this. Great tutorial, I'm a little stronger on the server side so this helps. Thanks!

  • @mohammadrahmanzazai2601
    @mohammadrahmanzazai2601 3 роки тому

    You are such a great lecturer in my life.

  • @Ezinma88
    @Ezinma88 2 роки тому

    Very good video. This is much more understandable than a similar one you made specifically on border-box.

  • @grohomot
    @grohomot 3 роки тому +1

    Thank for yout tutorials Kev! They helps me a lot!

  • @SYPCWAK
    @SYPCWAK 4 роки тому +1

    Thanks Kevin! Your videos are always very helpful. This explains a lot!

  • @nitsanbh
    @nitsanbh 3 роки тому

    Kevin, you are the best.

  • @Blobtheblobfish
    @Blobtheblobfish 3 роки тому

    I never knew about box-sizing: border-box. Good to know that the default is box-sizing: content-box and when you don't want padding to affect the size, use border-box

  • @beng7615
    @beng7615 4 роки тому

    OMG - I was not aware that margins don't collapse in grid and flex boxes!!
    Thanks!!

  • @liu-river
    @liu-river 4 роки тому +1

    Thanks so much for making this serie, it totally makes sense to me now, and the tips are super helpful.

  • @bonbonpony
    @bonbonpony 2 роки тому

    Nice tutorial. The only thing missing was a little talk about negative margins. They can come in handy sometimes ;)

  • @MathinusG
    @MathinusG 6 років тому

    This is a revelation! Nobody else showed this.

    • @KevinPowell
      @KevinPowell  6 років тому

      Really glad to hear it helped you out :)

  • @noobme1068
    @noobme1068 3 роки тому

    very helpful and explained a lot than other videos out there, good job!!!

  • @IhsanMujdeci
    @IhsanMujdeci 2 роки тому

    I ran into this when making a tutorial for beginners. So strange, I probably run into this pretty often

  • @jaroslawtrzybinski
    @jaroslawtrzybinski 4 роки тому

    Thanks Kevin. You've helped with padding problem.

  • @morgancastro2924
    @morgancastro2924 6 років тому +1

    Thank you for sharing all this! You have great tutorials for beginners like me, I actually understand what you're talking about!! Thank you :)

    • @KevinPowell
      @KevinPowell  6 років тому

      Awesome, so glad they've helped!

  • @brunoferreira1125
    @brunoferreira1125 5 років тому

    Awesome video Kevin, quite deep yet clear to understand! Good job

  • @phantomwolf9929
    @phantomwolf9929 5 років тому

    You seriously cleared up so much confusion for me

  • @MichaelSalo
    @MichaelSalo 3 роки тому

    Really clear demo here.

  • @OrincyWhyteDesigns
    @OrincyWhyteDesigns 2 роки тому

    Yes my official goal is to be a css master, but my real goal is to watch every single video Kevin has ever made.

  • @Dr.smileclinic
    @Dr.smileclinic 4 роки тому

    Crazy kevin.. i love your teaching..

  • @mldrenful
    @mldrenful 3 роки тому

    Thanks for sharing it. so helpful. I'm always confused about margin and padding. lol

  • @insaneviruss
    @insaneviruss 5 років тому

    Woaahh... Where were you when I was wasting hours and hours debugging weird margin behavior? Good video. Especially the collapse and reset thing.

    • @KevinPowell
      @KevinPowell  5 років тому

      Haha, I've been there wasting hours of my time debugging the strangest and simplest things in the past. Hopefully I can help people not have to do the same :)

  • @kaylamusic325
    @kaylamusic325 Рік тому

    These videos are so helpful!

  • @joemcdonough2510
    @joemcdonough2510 3 роки тому +1

    Awesome tutorials! I've found that when I set widths as percentages on children elements of parent elements whose box-sizing is set to border-box, the result was surprising at first. The width percentage on the child element will be a percentage of the parent's content width, not total width. So in your example at the end, if the total width of the parent is 200px, but the content-width is 120px (200px total width minus 30px padding-left minus 25px border-left minus 25px border-right = 120px content-box width), and then I set a percentage width on a child of that box, say 80%; that 80% is calculated based on the 120px, NOT the 200px total width. Has this ever taken you by surprise?

    • @clevermissfox
      @clevermissfox 10 місяців тому

      Hm I’ve never noticed this. I’m mostly using flex or grid though and still haven’t figured out how borderbox works on flex items, I keep getting conflicting answers when I look into it or ask.

  • @salarkazazi7584
    @salarkazazi7584 3 роки тому

    Thank kevin, u r indeed very experienced.

  • @T25de
    @T25de 2 роки тому

    Box-sizing made me smile

  • @hadargool5717
    @hadargool5717 2 роки тому

    Thank you!! I finally got this 💓🙏

  • @andrei8299
    @andrei8299 4 роки тому

    Thanks for the explanation, I'm a Russian beginner and all my friends who are experienced in programming told me to use tutorials in English, because they are better than Russian ones. So it might be true, because some topics are covered and explained much better.
    p.s BTW your voice and pace of speaking are good and a bit remind me of Roman Mars, maybe you've heard of this man.

  • @aram5642
    @aram5642 2 роки тому

    I am so old I can remember days when using wildcards in css and id attributes in html was considered a performance issue.

  • @cindybello1915
    @cindybello1915 4 роки тому

    Pretty awesome! I didn't know that. Love your channel!

  • @ericdy2118
    @ericdy2118 3 роки тому

    Thank you so much! Super helpful!

  • @everlastproducciones9280
    @everlastproducciones9280 4 роки тому

    Thanks for your time

  • @Utchinsons
    @Utchinsons Рік тому

    thankz for your great way of sharing info !

  • @theboringprogrammer4444
    @theboringprogrammer4444 4 роки тому +4

    "Inspect element"
    6th graders: *The Expert*

  • @sashatv138
    @sashatv138 4 роки тому

    Cool and very useful!

  • @bjornotto98
    @bjornotto98 4 роки тому

    Thank you for the high quality content, I just wish I would enjoy CSS more I love doing the backend stuff also JavaScript but I don't have the creativity the get some own designs, that's really another way of thinking than doing problem solving

  • @wonga07
    @wonga07 6 років тому +1

    Fantastic series!

  • @abdiag603
    @abdiag603 Рік тому +1

    Hi Kevin, thanks so much for the tutorial, am learning alot brushing through these basics after some years. One quick question. Do images have default margins? And also do they experience collapsing margins especially when you do resets on images like you usually do by setting images to display:block

  • @desnillight
    @desnillight Місяць тому

    you saved my life!

  • @miloskostic2239
    @miloskostic2239 5 років тому

    Very helpful informations as always. Thank you

  • @yashdabi248
    @yashdabi248 4 роки тому

    I was really wanted tutorial like this

  • @adnansafaraz5986
    @adnansafaraz5986 5 років тому

    Thank you kevin, this is so helpful!

  • @turabnaveed9765
    @turabnaveed9765 6 років тому +1

    best tutorials 😁

  • @josema-boy7610
    @josema-boy7610 5 років тому

    Definitely learned. OMG your the best. Thank you very much.

  • @asadrana2
    @asadrana2 5 років тому

    your teaching method is good thank you for the effort

  • @Angela-lp7zw
    @Angela-lp7zw Рік тому

    Great tutorial!
    7:14, I'm still confused as to how does the top padding of the demo-box creates a separation between the demo-box and the one box. Why isn't it a padding-bottom of the demo-box instead?

  • @thanigaivelk2112
    @thanigaivelk2112 5 років тому

    You post awesome tutorials... From your tutorials only .. I learn a lot... Can you please post a video on inline block and how vertical align works with inline block... And what is actually inline block...
    Ever one say that inline block that an inline element which takes padding margin width and height.. But i think its more than that..please do post a video...

  • @vivekdaiya9324
    @vivekdaiya9324 2 роки тому

    To Summarise:-
    1) When Margins of two elements touch each other they collapse and merge into each other (even between Parent and Child Element) and then Margin of only one Element works.
    2) This Collapsing Property is not present with Padding and will never merge.
    3) To get rid of this Problem, use little padding as a separator between two elements as Padding doesn't collapse.
    4) To make your life easy, use Presets ( margin: 0; padding: 0; box-sizing: border-box; )
    5) There is no such thing as margin-box or padding-box cuz no browser supports that.
    Bonus Point:-
    Use Inspector Tool to check where your Margins and Paddings are actually going.

  • @fritz-creates
    @fritz-creates 5 років тому

    THANK YOU! :) Yes you helped a lot! Just subscribed to your channel!
    Have a nice day,
    Fritz

  • @davitjanashia9344
    @davitjanashia9344 4 роки тому

    Great explanation thanks very much!! I would like to know how to center (display: blocks, inlines, inline-blocks) vertically and horizontally in automatic way? pls make this video!

  • @yohendryy
    @yohendryy 2 роки тому

    i just straight love you

  • @christinegivens9048
    @christinegivens9048 4 роки тому

    Amazing content. Thank you!

  • @DrinkCola
    @DrinkCola 4 роки тому

    Dude ! you have a Hollywood smile … keep on that

  • @cap.blue-97sama99
    @cap.blue-97sama99 3 роки тому

    Thanks a lot!!!!! For this video

  • @frankkj1995
    @frankkj1995 5 років тому

    Amazing work with these tutorials, although I've been following Angela Yu's paid udemy course, which is a great course, there are aspects in which you go into far more detail than she, so this is really a great help, thank you!

  • @gabrielpereiramendes3463
    @gabrielpereiramendes3463 4 роки тому

    #Excelent!
    Thanks a lot from Brazil.
    I really liked it because I want to improve my Front-end skills.

  • @mikhaillebedev7117
    @mikhaillebedev7117 6 років тому

    English is not my native language, but even for me it's very clear explanation, thanks so much.

    • @KevinPowell
      @KevinPowell  6 років тому +1

      Glad to hear that Mikhail!

  • @carpediem73
    @carpediem73 4 роки тому

    thank you, that was helpful

  • @mateuszb4387
    @mateuszb4387 6 років тому

    Awesome stuff. There are countless vids about what collapsing margins are, but You, as always show, what does it MEAN for us. I spent last few days digging this topic, but drop-shadow example at 4:30 was a WOW-thing for me. Another priceless-knowledge-vid. BTW: I like to fork interesting codepens to make my own note-comments. I can't fork these codepens, are they protected in some way? Once again: thank you, thank you aaand thank you!

    • @KevinPowell
      @KevinPowell  6 років тому

      So glad to hear that you got something from the video! Sorry about the forking thing, I make the videos ahead of time and mark them as private, I'll have to go through and update them to public.

  • @bloc-notes6751
    @bloc-notes6751 5 років тому

    Merci, merci et merci encore, j'adore tes videos !!!

  • @RedEyedJedi
    @RedEyedJedi 5 років тому

    If you are using Internet Explorer or Safari, use them for what they were designed to do i.e. download Chrome or Firefox.

  • @js_programmer8423
    @js_programmer8423 2 роки тому

    Just apply -> display: flow-root; on the parent container. This should fix it.

  • @blahdelablah
    @blahdelablah 6 років тому

    @John MX
    Kevin is using CodePen for these videos.

  • @nikfadeev2058
    @nikfadeev2058 3 роки тому

    good explanation

  • @esraamohamed5601
    @esraamohamed5601 Рік тому

    Thank you 🙏

  • @rubensmailbag
    @rubensmailbag 5 років тому

    Really like the tutorial thanks!

  • @romarta.3546
    @romarta.3546 6 років тому +1

    Hello Kevin, Thanks so much for the tutorials. It really help me a lot. Would you be able to discuss about CLEARFIX and whats its scope or when to apply it? :)

    • @KevinPowell
      @KevinPowell  6 років тому +1

      You'd want to use the clearfix in layouts where you're using floats, which shouldn't be very often these days.
      It's used to help controls layouts with floated items, as when we float multiple items, the element they are inside collapses. Clearfix stops that, more or less.

    • @romarta.3546
      @romarta.3546 6 років тому

      Thanks Kevin ^_^

  • @jimceron
    @jimceron 5 років тому

    Great video!

  • @rajashekhar433
    @rajashekhar433 3 роки тому

    Thank you