Split Div Into 2 Columns Using CSS

后端 未结 14 1877
故里飘歌
故里飘歌 2020-11-29 18:01

I have been attempting to split a div into two columns using CSS, but I have not managed to get it working yet. My basic structure is as follows:

14条回答
  •  佛祖请我去吃肉
    2020-11-29 18:46

    For whatever reason I've never liked the clearing approaches, I rely on floats and percentage widths for things like this.

    Here's something that works in simple cases:

    #content { 
      overflow:auto; 
      width: 600px; 
      background: gray; 
    } 
    
    #left, #right { 
      width: 40%; 
      margin:5px; 
      padding: 1em; 
      background: white; 
    } 
    
    #left  { float:left;  }
    #right { float:right; } 
    

    If you put some content in you'll see that it works:

    some stuff
    some more stuff

    You can see it here: http://cssdesk.com/d64uy

提交回复
热议问题