Two divs side by side - Fluid display

后端 未结 8 985
你的背包
你的背包 2020-11-22 03:09

I am trying to place two divs side by side and using the following CSS for it.

#left {
  float: left;
  width: 65%;
          


        
相关标签:
8条回答
  • 2020-11-22 03:28

    You can also use the Grid View its also Responsive its something like this:

    #wrapper {
       width: auto;
        height: auto;
        box-sizing: border-box;
        display: grid;
        grid-auto-flow: row;
        grid-template-columns: repeat(6, 1fr);
    }
    
    #left{
        text-align: left;
        grid-column: 1/4;
    }
    
    #right {
        text-align: right;
        grid-column: 4/6;
    }
    

    and the HTML should look like this :

    <div id="wrapper">
    <div id="left" > ...some awesome stuff </div>
    <div id="right" > ...some awesome stuff </div>
    </div>
    

    here is a link for more information:

    https://www.w3schools.com/css/css_rwd_grid.asp

    im quite new but i thougt i could share my little experience

    0 讨论(0)
  • 2020-11-22 03:36

    Here's my answer for those that are Googling:

    CSS:

    .column {
        float: left;
        width: 50%;
    }
    
    /* Clear floats after the columns */
    .container:after {
        content: "";
        display: table;
        clear: both;
    }
    

    Here's the HTML:

    <div class="container">
        <div class="column"></div>
        <div class="column"></div>
    </div>
    
    0 讨论(0)
  • 2020-11-22 03:38

    <div style="height:50rem; width:100%; margin: auto;">
      <div style="height:50rem; width:20%; margin-left:4%; margin-right:0%; float:left; background-color: black;"></div>
      <div style="height:50rem; width:20%; margin-left:4%; margin-right:0%; float:left;  background-color: black;"></div>
      <div style="height:50rem; width:20%; margin-left:4%; margin-right:0%; float:left;  background-color: black;"></div>
      <div style="height:50rem; width:20%; margin-left:4%; margin-right:0%; float:left;  background-color: black;"></div>
    </div>

    margin-right isn't needed though.

    0 讨论(0)
  • 2020-11-22 03:39

    Using this CSS for my current site. It works perfect!

    #sides{
    margin:0;
    }
    #left{
    float:left;
    width:75%;
    overflow:hidden;
    }
    #right{
    float:left;
    width:25%;
    overflow:hidden;
    } 
    
    0 讨论(0)
  • 2020-11-22 03:39

    Make both divs like this. This will align both divs side-by-side.

    .my-class {
      display : inline-flex;
    } 
    
    0 讨论(0)
  • 2020-11-22 03:42

    Try a system like this instead:

    .container {
      width: 80%;
      height: 200px;
      background: aqua;
      margin: auto;
      padding: 10px;
    }
    
    .one {
      width: 15%;
      height: 200px;
      background: red;
      float: left;
    }
    
    .two {
      margin-left: 15%;
      height: 200px;
      background: black;
    }
    <section class="container">
      <div class="one"></div>
      <div class="two"></div>
    </section>

    You only need to float one div if you use margin-left on the other equal to the first div's width. This will work no matter what the zoom and will not have sub-pixel problems.

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