CSS Box Model Tutorial for Beginners

Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
In this CSS Box Model tutorial for beginners, you will learn about the different layers of the CSS box model and how they work together. You will also learn about CSS box sizing and how to apply the different layers of the CSS box model.
🚩 Subscribe ➜ bit.ly/3nGHmNn
🚀 This lesson is part of a CSS for Beginners tutorial series playlist:
• CSS Tutorials for Begi...
🔗 All Resources for this CSS Tutorial Series: github.com/gitdagray/css_course
📬 Course Updates ➜ courses.davegray.codes/
CSS Box Model Tutorial for Beginners
(00:00) Intro
(00:05) Welcome
(00:25) Setup
(01:26) Exploring the CSS Box Model
(04:53) Default Browser Styles
(06:32) CSS Reset
(07:23) box-sizing
(09:17) Styling elements with the box model
(12:28) Margin properties and shorthand
(15:36) Padding properties and shorthand
(17:00) Border properties and shorthand
(20:28) Outline and outline-offset
(21:53) Turn a box into a circle
⚙ Web Dev Tools:
🔗 Chrome Browser: www.google.com/chrome/
🔗 Visual Studio Code (VS Code): code.visualstudio.com/
🔗 Live Server VS Code Extension: marketplace.visualstudio.com/...
🔗 vscode-icons VS Code Extension: marketplace.visualstudio.com/...
🔗 Github Themes VS Code Extension: marketplace.visualstudio.com/...
🔗 W3C CSS Validator: jigsaw.w3.org/css-validator/
🔗 Specificity Calculator: specificity.keegan.st/
📚 References:
🔗 MDN CSS: developer.mozilla.org/en-US/d...
🔗 MDN CSS Basics: developer.mozilla.org/en-US/d...
🔗 MDN CSS Selectors: developer.mozilla.org/en-US/d...
🔗 MDN - How to Apply Colors to HTML Elements with CSS: developer.mozilla.org/en-US/d...
🔗 MDN - CSS Values and Units: developer.mozilla.org/en-US/d...
🔗 MDN - The Box Model: developer.mozilla.org/en-US/d...
📚 Color Resources:
🔗 Coolors Contrast Checker: coolors.co/contrast-checker/1...
🔗 WebAIM Contrast Checker: webaim.org/resources/contrast...
🔗 Coolors Palette Generator: coolors.co/
🔗 HTML Color Codes: htmlcolorcodes.com/
✅ Follow Me:
Github: github.com/gitdagray
Twitter: / yesdavidgray
LinkedIn: / davidagray
Blog: yesdavidgray.com
Reddit: / daveoneleven
Was this tutorial about the CSS Box Model for beginners helpful? If so, please share. Let me know your thoughts in the comments.
#css #box #model

Пікірлер: 60

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode2 жыл бұрын

    To truly comprehend CSS, you need to have a good understanding of the CSS Box Model and all of the layers within. This tutorial covers each layer of the box model and how to apply styling to them. In addition, you will learn how to turn the box into a circle if you want! If you're just getting started with CSS, I recommend going to the start of this CSS for Beginners playlist: kzread.info/head/PL0Zuz27SZ-6Mx9fd9elt80G1bPcySmWit

  • @ahmad-murery
    @ahmad-murery2 жыл бұрын

    Understanding box-model is essential if you really want to learn css, The outline doesn't take up space so it can be useful for highlighting input controls according to their validity status, I personally use 50% for border-radius to avoid doing unnecessary calculations, and although I don't know how to apply it properly but we can specify different values for both horizontal and vertical radius of the border, this will give us more control over the shape of the box corners by simply using value pairs in the form of (ex: 50px / 25px) for each corner, Keep up energized Thanks Dave,

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thank you, Ahmad 🙏 Great suggestions! 💯

  • @AndresGarcia-ed9fh
    @AndresGarcia-ed9fh2 жыл бұрын

    This is the best css box model explanation I've seen!! I can see that understanding the box model I can layout much better elements on the screen. Also, you mentioned a good number of properties that I didn't know about, in addition, you articulate greatly when you speak, it's a communication skill that every teacher should has. Thanks a lot!!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thank you for the kind words, Andres! 🙏 I'm glad this helped! 🚀

  • @stanislavaksenov1700
    @stanislavaksenov1700 Жыл бұрын

    I've tried to set border-radius: 50% instead of 50px and it also made the circle. Thank you for the video!

  • @tylerengland2906
    @tylerengland29062 жыл бұрын

    I see why learning this is all about practice and repetition. I will be doing this exercise a few more times as there are a lot of things to know. Thanks Dave!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Glad I could help, Tyler! 🚀

  • @Grihlo
    @Grihlo2 жыл бұрын

    I really like how detailed are your explanations - it's really a professional way to explain subject. Step by step. Thanks a lot!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    You're very welcome!

  • @fabrice9848
    @fabrice98482 жыл бұрын

    Thank you Dave. You really help us making progress.🚀

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    My pleasure! 💯

  • @louiidelosreyes742
    @louiidelosreyes742 Жыл бұрын

    Done! Thank you for this tutorial video, sir!

  • @SarrahRoseMikhailLeung
    @SarrahRoseMikhailLeung29 күн бұрын

    Awesome video!

  • @spiritual5750
    @spiritual57502 жыл бұрын

    you are amazing dave at explaining and elaborating concepts. Trust me i have made notes on css, could not contemplate them your tutorials made them sensible to understand learning at a exponential rate..

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    You're welcome! I'm glad to hear that I've helped you! 💯🚀

  • @spiritual5750

    @spiritual5750

    2 жыл бұрын

    @@DaveGrayTeachesCode the impact that you are creating is impeccable. 😁💙

  • @GabrielSouza-yy2rq
    @GabrielSouza-yy2rq Жыл бұрын

    Learning is so cool, and teaching is such a noble task.

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Thank you, Gabriel! 🙏

  • @Bol_imla
    @Bol_imla Жыл бұрын

    Best tutorial ever.I enjoyed the teaching method,clearing elaborating on the topic..I have absolutely understood the box model now after searching a lot of tutorials but never got a satisfying understanding.Thumbs up great Tutor🎉🎉🎉🎉

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Glad it was helpful!

  • @TravinskiyVladislav
    @TravinskiyVladislav Жыл бұрын

    Thank you, Dave

  • @napoleon3242
    @napoleon32422 жыл бұрын

    Dave I think flexbox or flex would naturally be a great followup to this video. But great video as always

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thanks! Flexbox and Grid are coming soon. I'm covering typography first. 🚀

  • @devstuff92

    @devstuff92

    2 жыл бұрын

    @@DaveGrayTeachesCode Waiting on grid and flexbox :)

  • @fabrice9848

    @fabrice9848

    2 жыл бұрын

    @@DaveGrayTeachesCode I can't wait.👍

  • @DanyilYevlakhov
    @DanyilYevlakhov19 күн бұрын

    Like your videos. Thank you!

  • @Goorxun-yeer
    @Goorxun-yeer2 жыл бұрын

    Thank you, I listened to your CSS tutorial and it was great. I sent you ☕☕☕☕☕!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thank you so much for the support, Hersi!! 🙏☕☕

  • @Luis001155
    @Luis001155 Жыл бұрын

    Thank you Dave!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    You're welcome!

  • @iambrijeshtoo
    @iambrijeshtoo Жыл бұрын

    Thank you!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    You're welcome!

  • @RoguePRINCE_510
    @RoguePRINCE_510 Жыл бұрын

    I liked your content actually. your kind of explaining the topic with some sense of humour is very likeable and make me more excited to learn more. you are sharing a more Knowledge at free of Cost then a Paid courses .................

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Thank you!

  • @bz101
    @bz101 Жыл бұрын

    Nice. Fundamentals are always important.

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Absolutely!

  • @zakharsyrovatskii6510
    @zakharsyrovatskii65102 жыл бұрын

    Really like ur vids, ur are awesome!

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thank you! 🙏🙏

  • @mailsiraj
    @mailsiraj Жыл бұрын

    Dave, thanks for the great video. I remember the order Top Right Bottom Left as just clockwise. One question I had regarding specifying 50% for border-radius to make the box a circle - why is that number significant? Are there any good use-cases for using outline? - I read the comment by Ahamed, but did not fully understand the practical utility of using outline.

  • @fairytail6896
    @fairytail68966 ай бұрын

    Top Right Bottom Left -> 360° clockwise 😀

  • @user-dh8rm3ob4f
    @user-dh8rm3ob4f Жыл бұрын

    should have mentioned about margin collapsing (vertical), great video

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Thank you! It is a long playlist. I think the topic you mentioned is eventually discussed.

  • @ariaparsa310
    @ariaparsa3102 ай бұрын

    Hi, when I change the h1 to .container with the same data(margin, padding, font-size, ...), the content overflows the border however this is not the case with the h1, any solution? h1{...} vs .container{...}

  • @webb-developer
    @webb-developer11 ай бұрын

    ☑ remaining ==> outline and turn a box into circle

  • @piyushmahapatra5402
    @piyushmahapatra54022 жыл бұрын

    Dave,big fan here ? Where can I share some ideas for your next series of videos ? Would love if you take up RxJs + React !! Thanks a lot

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    Thank you and great suggestion!

  • @ranjithramesh9030
    @ranjithramesh90305 ай бұрын

    here is the another way to create the circle without using border-radius clip-path: circle()

  • @Valdaur
    @Valdaur2 жыл бұрын

    So from what I am understanding: The border shorthand is different than with padding and margin, because you cannot use the border shorthand declaration to specify different widths for each side. You instead need to use declarations such as "border-top", to specify the colour, style and width for each specific border side. Although I suppose you would rarely use different widths for each border side so I guess in that regard it's fine.

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    2 жыл бұрын

    You are correct, IG. The border shorthand is useful when you want the sides to be the same. Many individual properties do exist for changing each side, but the shorthand does not support it. developer.mozilla.org/en-US/docs/Web/CSS/border

  • @Valdaur

    @Valdaur

    2 жыл бұрын

    @@DaveGrayTeachesCode Ok, thanks for your response! :)

  • @liudmyladolzhenko516
    @liudmyladolzhenko516 Жыл бұрын

    Hello Dave! Thank you so much for your amazing videos and opportunity to learn coding with you. But I have a question about a circle. How can I multiplay it, if I need one circle, one square and triangle of various sizes. Could you help me to understand it right please?

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    You're welcome! I think you are asking how you can multiply it? As in, how can you make more than one circle, square, triangle, etc of various sizes? You could create a class that will make apply the rules to make a circle, another for square, and another for triangle - except for the size rules. Then add a separate class that adds the rules for the size you want. Maybe make small, medium, and large size classes like a CSS framework does (see Bootstrap, Tailwind, etc) Then apply these classes as needed.

  • @liudmyladolzhenko516

    @liudmyladolzhenko516

    Жыл бұрын

    @@DaveGrayTeachesCode Okay, I understand and will try to do it. Thank you so much for answer.

  • @miraclemaxwell9988
    @miraclemaxwell998825 күн бұрын

    How to place a div on another div

  • @schoonerthedog
    @schoonerthedog Жыл бұрын

    I keep getting my outline as a box around the circle. What am I doing wrong? My code is EXACTLY yours, down to the color .circle { margin: 3rem auto; background-color: gold; width: 100px; height: 100px; border: 2px solid black; border-radius: 50px; outline: 2px solid red; outline-offset: 0.35rem; } /*border-radius can also use %*/ What am I missing? I have the circle, and I have the border, but the effect for the outline isn't cascading down. Even when VSC only has the code of the circle.

  • @DaveGrayTeachesCode

    @DaveGrayTeachesCode

    Жыл бұрын

    Please review again. When you have different results, there must be a difference. A browser will read the CSS the same way every time. I can review a specific part of the video if you provide a timestamp.

  • @humayunnisarseo
    @humayunnisarseo3 ай бұрын

    Your Student H :) Forever

  • @adamacamara9308
    @adamacamara93089 ай бұрын

    to create a circle: br:0.5% ou 50%;

  • @niyaziozturk3967
    @niyaziozturk3967 Жыл бұрын

    try F12 🙂