【问题标题】:Prevent table column border from touching bottom or top of table防止表格列边框接触表格底部或顶部
【发布时间】:2018-07-12 00:30:27
【问题描述】:

我在 html 中创建一个表格,两列之间的线条边界完全向上和向下延伸。我怎样才能改变它,使它不接触桌子的顶部或底部?

              <title>Home Styles</title>
                <meta http-equiv="content-type" 
                  content="text/html; charset=iso-8859-1" />
               <style type="text/css">
                 p {font-size:small; margin-left: .2in }
               }
             </style>
              </head>
            <h1>Central Valley Construction</h1>
              <h2>Home Styles</h2>

                <table border="1" frame="hsides" width="1170px">
             <tr>
              <td valign="top" 
             style="border-right: 1px black solid; padding- top:70px"align="center">
              <a href="Chalet.html">Chalet</a><br />
              <a href="ContemporaryRanch.html">Contemporary Ranch</a><br />
              <a href="Cottage.html">Country Cottage</a>
              </td>

            <td align="center" style="padding-top:40px">



              <img src="chalet.jpg" alt="Image of a chalet" height="113" width="200" />
              <p><strong>Style</strong>: chalet</p>
              <p><strong>Square feet</strong>: 1305<br/>
             <strong>Bedrooms</strong>: 3<br />
             <strong>Baths</strong>: 2</p>


            </td>
           </tr>
        </table>
     </body>

【问题讨论】:

  • 首先,考虑不要对表格进行布局,其次,在tr/td 内有一个元素在顶部和底部都有边距
  • IT 必须用表格来完成,不幸的是,我会试试边距
  • 我会把下面的小提琴改成表格。
  • 那太好了,谢谢!

标签: html html-table border


【解决方案1】:

在tr/td 中有一个元素,该元素在顶部和底部都有边距。我在下面使用了divs,但它的概念相同。

更新版本,带表格

小提琴:http://jsfiddle.net/LwKGG/1/

.wrap{
    width:500px;
    background:#ccc;
    height:300px;
}

.border{
    margin:20px 5px;
    padding:10px;
    border-right:solid 3px #000;
    height:200px;
    width:300px;
}

.right{
    height:150px;
    background:#369;
    width:100px;
    padding:5px;
    margin:5px 0;
}
<table>
    <tr class="wrap">
        <td>
            <div class="border">
            Lorem ipsum.... blah blah blah.
            </div>
        </td>
        <td class="right">
            Lorem ipsum.... blah blah blah.
        </td>
    </tr>
</table>

原版

div {
  float: left;
}

.wrap {
  width: 500px;
  background: #ccc;
  height: 800px;
}

.border {
  margin: 20px 5px;
  padding: 10px;
  border-right: solid 3px #000;
  height: 200px;
  width: 300px;
}

.right {
  height: 150px;
  background: #369;
  width: 100px;
  padding: 5px;
  margin: 5px 0;
}
<div class="wrap">
  <div class="border">
    Lorem ipsum.... blah blah blah.
  </div>
  <div class="right">
    Lorem ipsum.... blah blah blah.
  </div>
</div>

【讨论】:

  • 嗨!我更新了您的答案,将链接的 JsFiddle 包含为可运行的代码 sn-p。但是,我不想删除您答案中的原始版本,并且与 JsFiddle 不同。请考虑是否要保留它。谢谢!
猜你喜欢
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 2012-08-25
  • 2012-06-04
  • 2020-05-24
  • 1970-01-01
  • 1970-01-01
  • 2017-03-29
相关资源
最近更新 更多