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

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 200

  • @benibeats4516
    @benibeats4516 6 лет назад +122

    Good tutorials, Kevin. Please, don't ever quit RUclips, 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 2 дня назад

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

  • @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!

  • @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.👌✌

  • @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!

  • @Prodkid360
    @Prodkid360 6 лет назад +1

    You sir, you have one of the best front end RUclips 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

  • @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

  • @kcsecurity439
    @kcsecurity439 4 года назад +6

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

  • @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. 💖

  • @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!

  • @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!

  • @user-sy7lm6lw8i
    @user-sy7lm6lw8i 2 года назад

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

  • @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.

  • @zakarianassar4264
    @zakarianassar4264 2 года назад

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

  • @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!

  • @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.

  • @hitabratanath305
    @hitabratanath305 2 года назад +1

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

  • @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

  • @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!!!

  • @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.

  • @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.

  • @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

  • @bonbonpony
    @bonbonpony 2 года назад

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

  • @jellyfish1772
    @jellyfish1772 2 года назад

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

  • @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!

  • @Ezinma88
    @Ezinma88 2 года назад

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

  • @JudaBorrayo
    @JudaBorrayo 3 года назад +1

    You're the man, Kevin! Thank you.

  • @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.

  • @nitsanbh
    @nitsanbh 3 года назад

    Kevin, you are the best.

  • @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!

  • @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.

  • @MathinusG
    @MathinusG 6 лет назад

    This is a revelation! Nobody else showed this.

    • @KevinPowell
      @KevinPowell  6 лет назад

      Really glad to hear it helped you out :)

  • @jaroslawtrzybinski
    @jaroslawtrzybinski 4 года назад

    Thanks Kevin. You've helped with padding problem.

  • @IhsanMujdeci
    @IhsanMujdeci 2 года назад

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

  • @beng7615
    @beng7615 4 года назад

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

  • @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!

  • @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

  • @mohammadrahmanzazai2601
    @mohammadrahmanzazai2601 3 года назад

    You are such a great lecturer in my life.

  • @MichaelSalo
    @MichaelSalo 3 года назад

    Really clear demo here.

  • @noobme1068
    @noobme1068 3 года назад

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

  • @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 :)

  • @salarkazazi7584
    @salarkazazi7584 3 года назад

    Thank kevin, u r indeed very experienced.

  • @mldrenful
    @mldrenful 3 года назад

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

  • @phantomwolf9929
    @phantomwolf9929 5 лет назад

    You seriously cleared up so much confusion for me

  • @brunoferreira1125
    @brunoferreira1125 5 лет назад

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

  • @everlastproducciones9280
    @everlastproducciones9280 4 года назад

    Thanks for your time

  • @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.

  • @Dr.smileclinic
    @Dr.smileclinic 4 года назад

    Crazy kevin.. i love your teaching..

  • @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.

  • @kaylamusic325
    @kaylamusic325 Год назад

    These videos are so helpful!

  • @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.

  • @hadargool5717
    @hadargool5717 2 года назад

    Thank you!! I finally got this 💓🙏

  • @ericdy2118
    @ericdy2118 3 года назад

    Thank you so much! Super helpful!

  • @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

  • @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.

  • @Utchinsons
    @Utchinsons Год назад

    thankz for your great way of sharing info !

  • @T25de
    @T25de 2 года назад

    Box-sizing made me smile

  • @cindybello1915
    @cindybello1915 4 года назад

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

  • @sashatv138
    @sashatv138 4 года назад

    Cool and very useful!

  • @wonga07
    @wonga07 6 лет назад +1

    Fantastic series!

  • @desnillight
    @desnillight Месяц назад

    you saved my life!

  • @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...

  • @miloskostic2239
    @miloskostic2239 5 лет назад

    Very helpful informations as always. Thank you

  • @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

  • @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!

  • @adnansafaraz5986
    @adnansafaraz5986 5 лет назад

    Thank you kevin, this is so helpful!

  • @josema-boy7610
    @josema-boy7610 5 лет назад

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

  • @turabnaveed9765
    @turabnaveed9765 6 лет назад +1

    best tutorials 😁

  • @asadrana2
    @asadrana2 5 лет назад

    your teaching method is good thank you for the effort

  • @yohendryy
    @yohendryy 2 года назад

    i just straight love you

  • @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!

  • @cap.blue-97sama99
    @cap.blue-97sama99 3 года назад

    Thanks a lot!!!!! For this video

  • @yashdabi248
    @yashdabi248 4 года назад

    I was really wanted tutorial like this

  • @carpediem73
    @carpediem73 4 года назад

    thank you, that was helpful

  • @christinegivens9048
    @christinegivens9048 4 года назад

    Amazing content. Thank you!

  • @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.

  • @gabrielpereiramendes3463
    @gabrielpereiramendes3463 4 года назад

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

  • @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?

  • @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.

  • @bloc-notes6751
    @bloc-notes6751 5 лет назад

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

  • @fritz-creates
    @fritz-creates 5 лет назад

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

  • @DrinkCola
    @DrinkCola 4 года назад

    Dude ! you have a Hollywood smile … keep on that

  • @nikfadeev2058
    @nikfadeev2058 3 года назад

    good explanation

  • @mikhaillebedev7117
    @mikhaillebedev7117 6 лет назад

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

  • @esraamohamed5601
    @esraamohamed5601 Год назад

    Thank you 🙏

  • @rubensmailbag
    @rubensmailbag 4 года назад

    Really like the tutorial thanks!

  • @jimceron
    @jimceron 5 лет назад

    Great video!

  • @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 ^_^

  • @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.

  • @theboringprogrammer4444
    @theboringprogrammer4444 4 года назад +4

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

  • @blahdelablah
    @blahdelablah 6 лет назад

    @John MX
    Kevin is using CodePen for these videos.

  • @js_programmer8423
    @js_programmer8423 2 года назад

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

  • @rajashekhar433
    @rajashekhar433 3 года назад

    Thank you