CSS Floats and Clears Tutorial for Beginners

Поділитися
Вставка
  • Опубліковано 8 лют 2025

КОМЕНТАРІ • 54

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 роки тому +8

    CSS Floats have been around for a long time. Before other methods were available, floats were often used to create columns on a page. That is no longer the case, but floats are still useful for their original purpose which is to float any element you desire to the left or right to allow the text content of your page to wrap around the floated element. If you are just getting started with CSS, I recommend going to the start of this CSS for Beginners playlist: ua-cam.com/play/PL0Zuz27SZ-6Mx9fd9elt80G1bPcySmWit.html

  • @camip1519
    @camip1519 Рік тому +2

    the best series i found on youtube , great job!!!

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

    Video 11:51 flow-root. That was something new that i learnt. I have been working in tech for so long. What seems legacy is perhaps some cases used everywhere, sadly! And that's what i thought was the only way. Thank you for this tutorial! Much needed

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

    Done watching again! Thank you Dave! :)

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

    Thank you Dave. I learnt more about floats!

  • @bhanwishree1217
    @bhanwishree1217 2 місяці тому

    Thankyou Dave..You taught amazingly well! Love from India !

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

    Hi Dave,
    I just finished watching your video on closures, and I just wanted to thank you. I had watched quite a few videos on the subject before, but yours was by far the best. Your delivery as a teacher, your pacing, your tone of voice, your attention to details, differentiating between closely related yet discrete/different concepts (e.g. closure vs lexical scope in this case) are all great. Thank you!
    Also, I have just found your channel (and subscribed), so I don't know much about the channel yet, but do you also do full courses on Udemy?
    Thanks,
    Faraz

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

      You're welcome, Faraz! 🙏 I do not have Udemy courses yet. I do plan to release a premium course at some point.

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

      @@DaveGrayTeachesCode looking forward to it; currently going through every video on your channel; both the missus and myself are learning a lot. Thanks.

  • @judahcohen-kw4lj
    @judahcohen-kw4lj 2 місяці тому

    thanks for the course man

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

    Thank you so much sir the video was very helpful

  • @syedaliAbdullahshah-o9l
    @syedaliAbdullahshah-o9l Рік тому

    thank you so much dave you'r the best so for on youtube tutorials

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

    Amazing tutorial thank you

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

    Thank you, Dave

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

    11:00 we can put that clear div inside the section underneath the paragraph

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

      Yes, we can. As mentioned and demonstrated earlier in the video, you see that solution in legacy code and it does work. The solution provided at 11:33 is considered to be the current and correct solution documented by MDN: developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Floats

  • @ram_qr
    @ram_qr 9 місяців тому

    flow-root!!! 🙆‍♂Thanks a lot!

  • @ahmad-murery
    @ahmad-murery 2 роки тому

    I really do remember all the headache using float/clear in the past 🤕
    I also remember that we used the ::after pseudo element to apply clear:both on the last item/paragraph,
    and I just noticed how old I am 👴
    Thanks Dave, you explained it very well,

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

      Thanks, Ahmad! I am also glad the days of the clearfix are behind us! 💯🚀

    • @ahmad-murery
      @ahmad-murery 2 роки тому

      @@DaveGrayTeachesCode just like waking up from a bad dream
      Thanks to flex/grid

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

    Thanks!

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

    thanks

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

    Hi Dave, excellent video and explanation. It really helped make a lot of sense of things regarding float.
    Question: Would overflow:hidden also wrap the floated div inside its container? How about applying clear:both to the second paragraph?
    Thanks in advance for your help!

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

    In "Float Inside container element" I use just above the end of the which gives me the same result as overflow or display. Is it the wrong way to write?

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

      It works concerning your question about the topic starting at 8:32. That said I mentioned earlier you see extra div elements with a clear in legacy code. As I mentioned at 11:33, the correct current way to solve this is with display: flow-root. All in all, the result is the same and this tutorial provides at least 3 ways of fixing the issue.

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

      ​@@DaveGrayTeachesCode Ok, I will follow the method as you mentioned. Thanks.

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

    tnx

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

    Hi Dave! Thanks for a new video.
    I got a problem i try to make a respositive website and all items are perspective to the size of the screen(on original) but on mine it have fixed size. Thats why when i make the screen wider the items get smaler))
    What should i learn not to do this mistakes?

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

      In your CSS, have you tried this
      * {
      padding: 0;
      margin: 0:
      box-sizing: border-box;
      body {
      min-height: 100vh;
      width: 100%;
      and make sure all your elements are within the body. Think of a "sandwhich" the body (or whatever syntax you prefer) is the bread and everthing in-between is the meats, cheese, ect

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

      I'd also highly recommend you don't use this way of styling Dave is teaching in the video. I'm sure he would agree however he's showing this in the event you ever come across this way of styling in your job or ect. But thats whats amazing about CSS, you do your styling however you please and ultimately end up with the same results however if you want to save yourself a lot of code and headache. i'd highly recommend you grasp "FLEX" or "GRID"

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

      It sounds like you need a meta tag in your HTML header that starts like this:

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

      This is a good start, and then width: 100% is not necessary although it will not hurt anything either. The body element is a block element and will expand to the width of the page by default.

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

      Yes, I'm showing simple examples of how each concept works. I think you are suggesting I create classes in a project which is what I would mostly do. There is also the BEM naming convention which I often loosely follow. More on all of that including flex and grid to come. 💯🚀

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

    Why did you use vw for the height of the box? I thought vw units are only for the width and for the height is vh unit?

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

      Did you watch the video where I explain that or are you just looking at the resulting code? I do explain it in the video.

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

    Hi Dave,
    when I gave more content in the section the content coming under the float container what to do when that occurs

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

      I am not sure what you are asking. You can clear a float in a variety of ways that I display in this video. What you do depends on your goal for the page.

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

    Hi everyone! I used the element section, as shown in this lesson, and got this warning on w3 validator: "Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections, or else use a div element instead for any cases where no heading is needed". Is there another element we can use instead of section? VS Code and w3 suggests using div but, in this case, there's already a div inside the supposed section element.

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

      Please see my other reply on this topic - I think you posted the question on the next video in the series.

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

      @@DaveGrayTeachesCode Got it. Thank you, Dave! You're the best!

  • @ecomadvisor.
    @ecomadvisor. 6 місяців тому

    12:50 this float element isn't recommended so watch his Module on flex

  • @GabrielSouza-yy2rq
    @GabrielSouza-yy2rq 2 роки тому

    👏👏

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

    👍

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

    oh boy, your tutorials are killers :)