How to position two divs horizontally within another div

前端 未结 13 1005
悲哀的现实
悲哀的现实 2020-12-12 11:12

I haven\'t played with CSS for too long a time and am without references at the moment. My question should be fairly easy but googling isn\'t bringing up a sufficient answer

13条回答
  •  抹茶落季
    2020-12-12 11:38

    This answer adds to the solutions above to address your last sentence that reads:

    how do I ensure that sub-left and sub-right stay within sub-title

    The problem is that as the content of sub-left or sub-right expands they will extend below sub-title. This behaviour is designed into CSS but does cause problems for most of us. The easiest solution is to have a div that is styled with the CSS Clear declaration.

    To do this include a CSS statement to define a closing div (can be Clear Left or RIght rather than both, depending on what Float declarations have been used:

    #sub_close {clear:both;}
    

    And the HTML becomes:

    Right
    Left

    Sorry, just realized this was posted previously, shouldn't have made that cup of coffee while typing my reply!

    @Darko Z: you are right, the best description for the overflow:auto (or overflow:hidden) solution that I have found was in a a post on SitePoint a while ago Simple Clearing of FLoats and there is also a good description in a 456bereastreet article CSS Tips and Tricks Part-2. Have to admit to being too lazy to implement these solutions myself, as the closing div cludge works OK although it is of course very inelegant. So will make an effort from now on to clean up my act.

提交回复
热议问题