Learn CSS Box Model In 8 Minutes

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

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

  • @thelitterateman
    @thelitterateman 3 года назад +1289

    The Odin Project is officially pumping some viewership to you.

    • @ricardodelacruz8666
      @ricardodelacruz8666 3 года назад +39

      I came from The Odin Project too!!! lol

    • @carlosrangel4500
      @carlosrangel4500 3 года назад +10

      @@ricardodelacruz8666 Me too :)

    • @willywonka4761
      @willywonka4761 3 года назад +4

      @@ricardodelacruz8666 same

    • @ItTakesTimeToBeGood
      @ItTakesTimeToBeGood 3 года назад +5

      Just came after searching for box model on youtube. Found what I was looking for to clear out all confusions. Exactly what I needed. I was having trouble formatting content with float and clear based on box model. This was super helpful! 👏🏼

    • @ninjamaster7986
      @ninjamaster7986 3 года назад +2

      Lol, What are you doing here?

  • @madalchemist31
    @madalchemist31 Год назад +113

    The part at 6:29 might be confusing for some people, so I explained it here:
    User here tells you that the total size of the element is 180x180, despite him specifying the height and width properties with value of 100px.
    So, user here wants the total size of the element to be 100x100, not 180x180.
    He tells you that there is a property called "box-sizing" with value "border-box".
    "border-box" takes into account the height and width values you mentioned, which are 100px for height and 100px for width.
    What "border-box" will do is make the total size of the element 100x100.
    To do this, it will first look at the current border and padding numbers (margin is out of the question because we said margin is not taken into account in the total element size), and it will work out the total element size using these numbers.
    User changes the border size to 20px, and padding still remains as 10px.
    Let's work this out. Assume the initial total element size is 0px.
    20px border up and 20px border down means that the total element size is now 40px.
    Padding. 10px padding up and 10px padding down means that the total element size is now 40px + 10px + 10px = 60px.
    FInally, "border-box" subtracts this 60px from the desired total element size, which is 100px. So 100px - 60px is 40px.
    This 40px number we just calculated will be given to the element content size. So now, the total element size is 40px (the element content size) + 60px (the element padding and border sizes) which gives us a total element size of 100px.
    This entire process repeats for left and right (the width), causing the total element area to be 100x100. Pretty cool, right? Rewatch this part if you're still confused while reading, and focus, and tell me if you got it!
    ALSO I'M A THE ODIN PROJECT STUDENT!!!

  • @AlexTechie
    @AlexTechie 5 лет назад +255

    This is one of the most important things to understand about web design, arguably the first thing everyone needs to learn, but a lot of us just go on without fully understanding it, myself included. Thank you for breaking it down and telling us what the Box Model is, what the different properties do, and what we need to know in order to style elements exactly how we want them to look. I'm gonna get to work on it and make notes in my HTML/CSS lab! 👍

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +30

      You are so correct. Many people including myself skipped over the box model when learning since it is boring but it would have saved me so much time if I understood it properly.

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

      This video is a equivalent to a holy scripture like Bible/bhagwat Geeta for people to understand how to design apps be it on Android/iOS/web.This was helpful for me as a flutter developer.

  • @neilrudnick7875
    @neilrudnick7875 2 года назад +60

    Pay attention to how he "comments out" an element at 6:35. ctrl + / has been a game changer for me. It allows me to select an element and toggle it on/off and see its effect.

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

      how do i do this lol? doing ctrl + shift +7 doesnt work lmao

    • @rohanofgondor
      @rohanofgondor Год назад +2

      ​@@SmartSleeper if you're on Linux/Windows, it's Ctrl + K + Ctrl + C and for windows, Mac: Command + K + C.

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

      For Mac it's ( Alt / )

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

      This was super helpful, thanks noticing it and sharing!

    • @Eyezick-l5z
      @Eyezick-l5z 23 дня назад

      As a cs grad working on his webdev skills for jobs, WOW dude what the hell! I could've saved actual real time with this!

  • @DANNYFIGDESIGNS
    @DANNYFIGDESIGNS 5 лет назад +230

    Did not know the margins collapse. Thank you.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +49

      It is something that I did not realize for a long time as well. It definitely confused me a few times.

    • @komkwam
      @komkwam 5 лет назад +9

      But in CSS grid that is no longer the case anymore, then both margins are displayed.

    • @knyto2
      @knyto2 4 года назад +3

      @@komkwam This is the case for CSS flex as well

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

      ya , this help me a lot

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

      what would be the idea behind margins behaving like that, very confusing!!!

  • @Jedi.Trader
    @Jedi.Trader 3 года назад +37

    Gets tricky with the height and width being eaten up after box sizing, but you make it easier to understand! Thanks!

  • @catherinesmart5000
    @catherinesmart5000 2 года назад +7

    Odin Project FTW!!!! We got this, and our future is bright :D

  • @watchmanscall2643
    @watchmanscall2643 5 лет назад +11

    I'm a student of coding and programming and this box model stuff with the content, padding, border and margin has always confused me. Today I am no longer confused but rather empowered to conquer this. i just told my wife, where's this fella been all my life. lol Thank you sir! Hell, I even broke out the crayons to draw this stuff in my notebook! lol

  • @ozzyfromspace
    @ozzyfromspace 5 лет назад +41

    OMG for some reason I wasn't getting it during my class lectures. You cleared it up so well man, thank you! I really appreciate how easy you are to understand. Best wishes my man!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +10

      I'm really glad I was able to help. Good luck on your future learning!

  • @dmc549
    @dmc549 5 лет назад +39

    Excellent explanation. This is by far the clearest I've found so far. Thanks!

  • @PM-4564
    @PM-4564 4 года назад +6

    I've been watching tutorials where I would type in the CSS line by line hoping to finally understand what it means, but this video finally did it.

  • @gboostt
    @gboostt 4 месяца назад +1

    Studied the box model for 2 days and couldn't understand it yet
    you explained it to me in 8 minutes and i understood everything!
    Thanks!

  • @AshishGupta-be2yz
    @AshishGupta-be2yz 4 года назад +42

    The way you explained too easily is amazing. Got cleared many doubts. Thanks a lot

  • @Habert-Kungu
    @Habert-Kungu 10 месяцев назад +6

    still consistent from odin project starting to realize how css is important to learn dont rush over

  • @kylerkeeley
    @kylerkeeley 3 года назад +13

    *realizing I’ve spent a couple weeks trying to understand something you explained so clearly in 8 minutes*
    Thank you!

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

    If the Odin Project considers your channel quality content, then you earned a sub. I've seen a lot of other RUclipsrs and they're more about themselves and being mental health career gurus than programmers. Don't sell out.

  • @ragnar0721
    @ragnar0721 9 месяцев назад

    This was the fastest 8mins I've spent on a coding video. Love the conciseness

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

    i highly recommend any one still starting in css to take Kyle css course one friend on mine took the course and after going through it with him I definitely learn more about css and not still that afraid about it really thanks to you Kyle and to my friends that took the course

  • @Guy-de6ul
    @Guy-de6ul 6 месяцев назад +3

    Key Takeaways
    1. Every CSS element is a box.
    2. We can use padding increase size of our boxes.
    3. Border goes around padding

    4. Margin goes around border and adds spacing

    5. We can use inspect to see model
    6. We can also set width and and height
    7. If we add margins to the second box, the box above it will compare the margin it has with second box and the larger margin will be the space between them.

    8. Height is shown as 180 because 100 + 20(padding) + 60 (border).
    9. We can use box-sizing to make it actual height we specified in code. Suppose we change padding or borders, other numbers adjust by itself.
    10. We can use chrome dev tools to understand box model in a better way.

  • @hiteshchalise3988
    @hiteshchalise3988 4 года назад +17

    Margin Collapse surprised me, didn't know thanks :)

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

    I don't know what it is about this video but every other explanation of the box model I've encountered so far just completely threw me. Thanks so much for breaking down such an important concept so perfectly

  • @cienyan
    @cienyan 3 года назад +5

    I learned so much in 8 mins. It's very easy to understand the way you explained. Thank you!

  • @omermasood3241
    @omermasood3241 8 месяцев назад

    Your videos are making a positive difference in everyone; the way of teaching has erased my long-term confusion in the concept. Keep it up bro, and keep making videos like these!

  • @vietanhmkt
    @vietanhmkt 2 месяца назад

    Thanks for elaborate on CSS box model, keynote:
    - Use margin to set apart between adjacent elements
    - Each element will have padding, border, margin attribute
    - Use box-sizing: border-box to get actual size of element without specify width or height of elements
    From Odin Project

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

    Thanks man!I truly appreciate you taking your time to help people on youtube get the content we need.
    Much Respect from KENYA 🇰🇪

  • @crazybieberchic
    @crazybieberchic 3 года назад +8

    Thank you, this was so simple to understand. You're a great teacher

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

    I learned more from this 8.5 minutes than most tutorials online! Thanks.

  • @anup_narvekar
    @anup_narvekar 6 месяцев назад

    Still one of the best channel for leaning web dev in 2024

  • @dvirhanum9530
    @dvirhanum9530 5 лет назад +48

    I'm coding web for 8 years. And the thing with margin that you showed right now which it uses 30 from this and 70 from this, I didn't know that. In my mind it was always 70 + 100 of the other element. I'v got to check it.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +12

      That is what I made this channel for. I want to help everyone understand web development as deeply as possible

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

      no way!

    • @brighga33
      @brighga33 5 лет назад +1

      There is a MDN article on this topic:developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing 😀

    • @error53ish
      @error53ish 5 лет назад +1

      Same here with the overlapping margins. Yikes. You'd think that more people would talk about that in learning resources.

  • @GabrielPerboni
    @GabrielPerboni Год назад +1

    The folks at The Odin Project were right. This is really very important and having this fundamental knowledge will indeed end a lot of frustration and suffering in the future. Thanks! If only I knew this in the past 😜

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

    Thanks a lot, you made it so much easier to understand by using crystal-clear explanations and live examples!

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

    i am taking an online course and i am just stucked here thank you sir for this clear explanation

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

    Thank you so much for this video. My brain just totally burnt out in my WebDev course and you were able to explain it in a way I can actually take in.

  • @danilopriscilla1934
    @danilopriscilla1934 5 лет назад +2

    this dude is pure gold

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

    u r simply the best ..... dont know how u make concepts and topic so clear and easy .

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

    what a great surprise! I already knew your chanel, and The Odin Project linked this tutorial in one of the chapters!

  • @nidhalabidi69
    @nidhalabidi69 5 лет назад +2

    Thank you for explaining the box model so well !! I'm going to use your channel as the first resource to understand new things in CSS . Keep it up

  • @dipxxqib
    @dipxxqib 7 месяцев назад

    0:13 - Introduction
    1:06 - Content
    1:20 - Padding
    2:05 - Border
    2:25 - Margin
    2:56 - Visualization
    4:22 - Margins collapse
    5:24 - Height and Width
    6:02 - Border box
    7:10 - Chrome Dev tools
    7:25 - Take aways

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

    I finally understood the box model because of you! Thanks a lot sir! You really cleared my confusion!

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

    cheers! I'm doing this at Uni and you made a complicated page very simple.

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

    dude i finally understand the margin... I never knew it collapses to the largest value! Now things make sense!
    You got my sub! You're amazing and thank you very much for this! Really really appreciate it! Vielen Dank!

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

    This is prolly the best tutorial 🆖

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

    i watched lots of video nobody explained this correctly but you do thank you

  • @swtpeteswtpete1515
    @swtpeteswtpete1515 3 года назад +7

    Kudos! Excellent presentation and pace and style. You could teach a udemy or community college class for money for sure. Thanks! I'm just starting to learn CSS3

  • @richardberends7792
    @richardberends7792 5 месяцев назад

    You make this easily understandable and I will now subscribe, thank you!

  • @MelSonio
    @MelSonio 9 месяцев назад

    Thank you. I was very confused on margin and padding until I watched this!

  • @flower-butter3920
    @flower-butter3920 2 года назад

    This is one of the best videos I have seen that explains it perfectly!!! Thank you so much!!!

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

    enjoyable, clear and easy. you are the one to whom I search whenever I stuck in any web situation, thanks for uploading videos for us .

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

    Extremely helpful, didn't have a remote idea that the margin was shared between two elements...Concise explanation, thank you.

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

    Thank you very much man❤

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

    Thank you and to The Odin Project for such helpful information! I do not know how I was learning more advanced things without full understanding of this essential topic.

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

    Best explanation ever thankyou so much Kylle

  • @YangoMangoHD
    @YangoMangoHD 3 года назад +8

    Here from The Odin Project!

  • @THELEMISIS
    @THELEMISIS 7 месяцев назад

    Bro, you are a G for putting this video together! I paid for a course that fumbles the bag in explaining this concept. haha smh

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

    Thanks for the explanation of the box model. This was the best I have seen. Clearly explained and WHY. Thank you much.

  • @DanielJackson-ez6kp
    @DanielJackson-ez6kp 3 года назад

    Great video, i tried skipping css and going straight to react/nextJs…suffice to say i found myself here not long after building up my logic knowledge so i can actually do something with it!

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

    thanks to your videos. Direct and easy to understand.

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

    this is great. as a PM learning to code, this was helpful.
    im learning and sharing my journey on the channel. come say hi :D

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

    Thank you! This video really helped me understand this concept.

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

    BEST and PRECISE explanation EVER !!!
    (for myself, with all do respect for other authors)
    I went through quite a number of other videos;

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

    Great stuff! Thank you for such an insightful video

  • @kidyoshi007
    @kidyoshi007 5 месяцев назад

    Big thank you to you bro, this is teaching me so much. Im going to create something really big.

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

    You videos are helpful for last minute interview prep !

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

    Great work there, Very Simple To Understand

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

    Thanks man. Great video.

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

    Thank you the words are crystal clear. Much love

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

    omg that is the purpose border box I couldn't understand it till now :) good job explaining thanks

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

    Clearest explanation wow ! Where did you learned that (clear and concise explanation), any source ?

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

    This is so good. short and sweet!

  • @Lotus-Bloom
    @Lotus-Bloom 9 месяцев назад

    When I was originally learning about HTML and CSS on my own in high school I could have really used resources like this.
    I remember trying to align elements without the assistance of the box-sizing property. I would have to try and remember to subtract any padding and border from the defined height and width of any element and it felt like a monumental pain in the ass. This was exacerbated by the fact that I had not committed to memory that the usage of margin is crucial in spacing, causing me to severely overusing padding to do so.

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

    Thank you! This really helped me understand CSS better!

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

    This is so helpful. I forget the deets of the box model if I haven't used css in awhile so this is good for the oh yeah, I remember it now.

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

    Thank you my friend, because of you I was able to figure out CSS!

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

    That was great explaining ! Thanks for video.

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

    I’ve been struggling understand this concept. Amazing tutorial ❤

  • @artStuHuerta
    @artStuHuerta 4 месяца назад

    this really sorted things out for me, thank you! :D

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

    you really made it make sense buddy. thanks!

  • @DimeAle
    @DimeAle 4 года назад +1

    THANK YOU. I was struggling with this, you made it easy to understand =].

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

    Thank you, I found this really helpful and easy to digest. much appreciated!

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

    Awesome explanation my teacher could not adequately explain to me.

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

    This saved a lot of headache, very fundamental, thank you 🙏

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

    Thank you so much! Now i finally understand the box model :D

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

    explained very clearly, thank you!

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

    Very Nice Video, great pace!

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

    Thanks!! You example the information very well.

  • @codingwithbasit7801
    @codingwithbasit7801 5 лет назад +3

    Thank you for explaining man! thumbs up.

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

    Thank you so much for this. Its a lot better to understand. I ended up joining a bootcamp, but didn't quite mention the overlapping.
    Do you have a video as well for HTML arranged? for example, content inside the box model?

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

    Thank you for your clear explanation

  • @patrickren7395
    @patrickren7395 5 лет назад +1

    Wow, I dont even know box-sizing before. Awesome video

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +1

      It is one of the best CSS properties in my opinion.

  • @penguin1234ification
    @penguin1234ification 4 года назад +1

    Thank you so much! now I know when to use them rather than hovering over my box model every time :)

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

    Fantastic video!!! Thank you so much!!

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

    The explanation on using border-box was useful.

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

    Woah I never knew about the larger margin rule! Thank you so much!

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

    hey mate, i had seen the graphic before for the box model, i didnt know pre this video that you could inspect the box model in dev options - so your vid helped a lot - much easier than reading MDN notes on the same concet. also good to know that margins auto collapse. thanks!

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

    your explanation is easy to understand, thanks for the video 👍

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

    finally I complete understood the box model. thanks 🍎

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

    great video, thanks! doing the odin project

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

    Ths video is really best for beginners.

  • @Learning_gets_compounded
    @Learning_gets_compounded 8 месяцев назад

    Thanks a lot for providing this quality content 😊

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

    I love the way you explain this