height when containing floating

后端 未结 4 1120
太阳男子
太阳男子 2020-12-23 20:58

I have a list:

  • Number 1
  • Number 2
  • Number 3
  • ...

All

相关标签:
4条回答
  • 2020-12-23 21:15

    Here, i am presenting, one of the easiest way to handle this kind of situations.

    Float left always have some reaction and not good to use if we have some alternative of it.

    The Alternative is :

    li { display:inline-block; }
    

    No need to add extra code like float:left and overflow:hidden :)

    0 讨论(0)
  • 2020-12-23 21:26

    This isn't a direct answer to your question, but as an alternative could you consider using display:inline-block? These days I just use that instead of float where possible, as essentially most of the time it can achieve the same sort of objective without the total hassle of making containers properly contain inner floating elements and having to clear them all the time.

    0 讨论(0)
  • 2020-12-23 21:34

    Good options to contain the floats:

    • Add overflow: hidden to the ul.
    • Use clearfix.
    0 讨论(0)
  • 2020-12-23 21:35

    test it:

    ul { overflow: hidden; }
    li { float:right; display:block; }
    

    add class to your elements, don't do this for all elements.

    0 讨论(0)
提交回复
热议问题