CSS table layout: why does table-row not accept a margin?

后端 未结 10 2235
余生分开走
余生分开走 2020-12-12 23:34



        
相关标签:
10条回答
  • 2020-12-12 23:41

    Have you tried setting the bottom margin to .row div, i.e. to your "cells"? When you work with actual HTML tables, you cannot set margins to rows, too - only to cells.

    0 讨论(0)
  • 2020-12-12 23:42

    There is a pretty simple fix for this, the border-spacing and border-collapse CSS attributes work on display: table.

    You can use the following to get padding/margins in your cells.

    .container {
      width: 850px;
      padding: 0;
      display: table;
      margin-left: auto;
      margin-right: auto;
      border-collapse: separate;
      border-spacing: 15px;
    }
    
    .row {
      display: table-row;
    }
    
    .home_1 {
      width: 64px;
      height: 64px;
      padding-right: 20px;
      margin-right: 10px;
      display: table-cell;
    }
    
    .home_2 {
      width: 350px;
      height: 64px;
      padding: 0px;
      vertical-align: middle;
      font-size: 150%;
      display: table-cell;
    }
    
    .home_3 {
      width: 64px;
      height: 64px;
      padding-right: 20px;
      margin-right: 10px;
      display: table-cell;
    }
    
    .home_4 {
      width: 350px;
      height: 64px;
      padding: 0px;
      vertical-align: middle;
      font-size: 150%;
      display: table-cell;
    }
    <div class="container">
      <div class="row">
        <div class="home_1">Foo</div>
        <div class="home_2">Foo</div>
        <div class="home_3">Foo</div>
        <div class="home_4">Foo</div>
      </div>
    
      <div class="row">
        <div class="home_1">Foo</div>
        <div class="home_2">Foo</div>
      </div>
    </div>

    Note that you have to have

    border-collapse: separate;
    

    Otherwise it will not work.

    0 讨论(0)
  • 2020-12-12 23:44

    Works - Add Spacing To Table

    #options table {
      border-spacing: 8px;
    }
    
    0 讨论(0)
  • 2020-12-12 23:50

    adding a br tag between the divs worked. add br tag between two divs that are display:table-row in a parent with display:table

    0 讨论(0)
  • 2020-12-12 23:51

    Add spacer span between two elements, then make it unvisible:

    <img src="#" />
    <span class="spacer">---</span>
    <span>Text TEXT</span>
    
    .spacer {
        visibility: hidden
    }
    
    0 讨论(0)
  • 2020-12-12 23:52

    See the CSS 2.1 standard, section 17.5.3. When you use display:table-row, the height of the DIV is solely determined by the height of the table-cell elements in it. Thus, margin, padding, and height on those elements have no effect.

    http://www.w3.org/TR/CSS2/tables.html

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