如何在不使用表的情况下实现表格布局?

big*_*dia 10 html css html-table

以进度(和学习)的名义如何从代码中删除表并实现相同的布局?

例如,这是我的表:

<table cellspacing="0px">
    <tr>
        <td>
            <img src="http://www.poltairhomes.com/images/footerlogo.png" />
        </td>
        <td id="footertext">
            <p>Poltair Homes Plc<br />Registered Office: The Old Chapel, Greenbottom, Truro, Cornwall, TR4 8QP.<br />Registered in England & Wales: 3955425<br />www.poltairhomes.com<br />info@poltairhomes.com</p>
        </td>
        <td id="footertext">
            <p>Terms and Conditions | Privacy Policy | Sitemap</p>
        </td>
        <td id="footertext">
            <p>SIGN UP FOR OUR NEWSLETTER:</p>
            <img src="http://www.poltairhomes.com/images/signup(temp).png" />
        </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

和相关的CSS:

.footertext {
    margin: 0;
    padding:0 5px 0 5px;
    color: #AAA;
    font-size: 10px;
    font-family:Arial, Helvetica, sans-serif;
    text-align:center;
    border-left: 1px solid #CCC;
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/userdude/tYjKw/

小智 16

CSS:

.table {
  display: table;
}
.table-row {
  display: table-row;
}
.table-cell {
  display: table-cell;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="table">
  <div class="table-row">
    <div class="table-cell">Table cell 1</div>
    <div class="table-cell">Table cell 2</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)


小智 9

<div class="table">
    <div class="row">
       <div class="cell twocol">
           <span>Content1</span>
       </div>
       <div class="cell twocol">
           <span>Content2</span>
       </div>
    </div>
    <div class="row">
       <div class="cell onecol">
           <span>Content3</span>
       </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

和CSS

.table {width: 100%; height: 100%;}
.row {width: 100%; min-height: 1px; height: auto; margin: 0;}
.cell {float: left; margin: 0; padding: 0;}
.onecol {width: 100%;}
.twocol {width: 50%;}
Run Code Online (Sandbox Code Playgroud)

我建议你研究一些网格系统,比如960grid(http://960.gs/)或1140grid(http://cssgrid.net/),会对你有所帮助.


Dav*_*ave 1

创建样式为:

.footerItem { float: left; }
Run Code Online (Sandbox Code Playgroud)
<div class="footerItem">
        <img src="http://www.poltairhomes.com/images/footerlogo.png" />
    </div>
    <div class="footerItem">
        <p>Poltair Homes Plc<br />Registered Office: The Old Chapel, Greenbottom, Truro, Cornwall, TR4 8QP.<br />Registered in England & Wales: 3955425<br />www.poltairhomes.com<br />info@poltairhomes.com</p>
    </div>
    <div class="footerItem">
        <p>Terms and Conditions | Privacy Policy | Sitemap</p>
    </div>   
    <div class="footerItem">
        <p>SIGN UP FOR OUR NEWSLETTER:</p><img src="http://www.poltairhomes.com/images/signup(temp).png" />
    </div>
Run Code Online (Sandbox Code Playgroud)

然后使用 DIV 创建主体来分隔块并将该类应用于每个块: