代码之家  ›  专栏  ›  技术社区  ›  Vithushan

如何使“display:table”的多div以单行显示

  •  1
  • Vithushan  · 技术社区  · 8 年前

    Im使用div而不是table来显示数据,如下所示。 enter image description here

    我想在一行显示数字,比如1-30,而不是打断到下一行。我的代码是:

    <div class="div-table">
        <div class="div-table-row">
            <div class="div-header-col">Levels</div>
            <div *ngFor="let x of dates" class="div-date-col">{{x}}</div>
        </div>
    </div>
    

    和css:

    .div-table {
        display: table;         
        width: auto;         
        background-color: #eee;
        // border-spacing: 5px;
    }
    .div-table-row {
        display: table-row;
        width: auto;
        clear: both;
    }
    
    .div-date-col {
        float: left;
        display: table-column;         
        width: 50px;    
        text-align:  center;
        border: 1px solid black;     
    }
    
    .div-header-col {
        float: left;
        display: table-column;         
        width: 200px;         
    }
    

    4 回复  |  直到 8 年前
        1
  •  1
  •   Raúl Álvarez Hinojosa    8 年前

        2
  •  0
  •   silpa jacob    8 年前

    你可以试试这个。

    .div-table {
      background-color: #eee;
    }
    
    .div-table-row {
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -ms-flex-wrap: wrap;
          flex-wrap: wrap;
      width: auto;
      clear: both;
    }
    
    .div-date-col {
      width: calc(100%/30);
      text-align: center;
      border: 1px solid black;
    }
    
    .div-header-col {
      width: 200px;
    }
    
        3
  •  0
  •   Richard Pariath    8 年前

    添加 把它放在同一排。

    <div style="display: flex;flex-wrap:nowrap">   
     <div class="div-table">
         <div class="div-table-row">
                <div class="div-header-col">Levels</div>
                <div *ngFor="let x of dates" class="div-date-col">{{x}}</div>
          </div>
      </div>
    </div>
    
        4
  •  0
  •   harkesh kumar    8 年前
    <table>
      <tr >
        <td> Levels</td>
      </tr>
      <tr *ngFor="let x of dates">
        <td class="div-date-col"> {{x}}</td>
      </tr>
    </table> 
    

    Demo