How to force div to appear below not next to another?

前端 未结 6 1082
野的像风
野的像风 2021-01-30 12:07

I would like to place my div below the list, but actually it is placed next to the list.The list is generated dynamically, so it doesn\'t have a fixed hight. I would like to hav

相关标签:
6条回答
  • 2021-01-30 12:46

    Float the #list and #similar the right and add clear: right; to #similar

    Like so:

    #map { float:left; width:700px; height:500px; }
    #list { float:right; width:200px; background:#eee; list-style:none; padding:0; }
    #similar { float:right; width:200px; background:#000; clear:right; } 
    
    
    <div id="map"></div>        
    <ul id="list"></ul>
    <div id="similar">this text should be below, not next to ul.</div>
    

    You might need a wrapper(div) around all of them though that's the same width of the left and right element.

    0 讨论(0)
  • 2021-01-30 12:50

    use clear:left; or clear:both in your css.

    #map { float:left; width:700px; height:500px; }
     #list { float:left; width:200px; background:#eee; list-style:none; padding:0; }
     #similar { float:left; width:200px; background:#000; clear:both; } 
    
    
    <div id="map"></div>        
    <ul id="list"></ul>
    <div id ="similar">
     this text should be below, not next to ul.
    </div>
    
    0 讨论(0)
  • 2021-01-30 12:51

    I think what you want requires an extra wrapper div.

    #map {
        float: left; 
        width: 700px; 
        height: 500px;
    }
    #wrapper {
        float: left;
        width: 200px;
    }
    #list {
        background: #eee;
        list-style: none; 
        padding: 0; 
    }
    #similar {
        background: #000; 
    }
    <div id="map">Lorem Ipsum</div>        
    <div id="wrapper">
      <ul id="list"><li>Dolor</li><li>Sit</li><li>Amet</li></ul>
      <div id ="similar">
        this text should be below, not next to ul.
      </div>
    </div>

    0 讨论(0)
  • 2021-01-30 13:00
    #map {
      float: right;
      width: 700px;
      height: 500px;
    }
    #list {
      float:left;
      width:200px;
      background: #eee;
      list-style: none;
      padding: 0;
    }
    #similar {
      float: left;
      clear: left;
      width: 200px;
      background: #000;
    }
    
    0 讨论(0)
  • 2021-01-30 13:02

    what u can also do i place an extra "dummy" div before your last div.

    Make it 1 px heigh and the width as much needed to cover the container div/body

    This will make the last div appear under it, starting from the left.

    0 讨论(0)
  • 2021-01-30 13:11
    #similar { 
    float:left; 
    width:200px; 
    background:#000; 
    clear:both;
    }
    
    0 讨论(0)
提交回复
热议问题