0

我有我的 html 标记这样的东西

  <table>
    <tr>
      <td>
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="images/img-1.jpg">
        <h3>Battle Field dsvadv dsadhjkba dsakjdbsa</h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
        <a href="#">Add to cart</a>
      </td>
      <td>
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="images/img-2.jpg">
        <h3>Battle Field </h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
        <a href="#">Add to cart</a>
      </td>
    </tr>
  </table>

而css是这样的

<style type="text/css">
table tr td {
  vertical-align: top;
  border-collapse: collapse;
  width: 100px;
}
td img {
  padding: 10px;
  border: 1px solid #ccc;
}
td h3 {
  font-size: 12px;
  line-height: 22px;
  text-align: center;
  margin: 0;
}
td span {
  display: inline-block;
  font-size: 12px;
}
td a {
  clear: both;
  display: block;
  vertical-align: bottom;
  margin: 20px 0 0 0;
}
</style>

在此之后我的布局是这样的

现在的布局是这样的

但我希望我的布局应该是这样的

我想要这种类型的布局

请帮帮我。

笔记

在不同的产品中,文本长度内的标题<h3>...</h3>可能会有所不同。所以价格应该在标题下方,按钮应该在一条直线上,即在内容的底部,就像第二个参考图像一样。

4

3 回答 3

1

只需创建另一个<tr>并将按钮移动到<tr>.

<table>
<tr>
  <td>
    <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="y5g17.png">
    <h3>Battle Field dsvadv dsadhjkba dsakjdbsa</h3>
    <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
  </td>
  <td>
    <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="y5g17.png">
    <h3>Battle Field </h3>
    <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
  </td>
</tr>
<tr>
    <td><a href="#">Add to cart</a></td>
    <td><a href="#">Add to cart</a></td>
</tr>
</table>

这是您现有代码最简单的方法。

另一种方法是使用div's而不是表。

于 2012-10-19T05:43:18.600 回答
0

一个简单的解决方案是将您的内容分成多行。所有图片都在第一行,标题在第二行,金额在下一行,依此类推。请参考以下代码:

<table>
<tr>
    <td>
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="images/img-1.jpg">
    </td>
    <td>
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="images/img-2.jpg">
    </td>
</tr>

<tr>
    <td>
        <h3>Battle Field dsvadv dsadhjkba dsakjdbsa</h3>
    </td>
    <td>
        <h3>Battle Field </h3>
    </td>
</tr>

<tr>
    <td>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
    </td>
    <td>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
    </td>
</tr>

<tr>
    <td>
        <a href="#">Add to cart</a>
    </td>
    <td>
        <a href="#">Add to cart</a>
    </td>
</tr>

于 2012-10-19T05:39:57.133 回答
0

......现场演示......

嗨,现在这可能会抛出 css,因为现在您可以创建两个 div并习惯于使用position定义tr height 100%

现在你可以像这样写 css

CSS

table tr{
height:100%;
}
table tr td {
  vertical-align: top;
  border-collapse: collapse;
  width: 100px;
  height:100%;
}
td img {
  padding: 10px;
  border: 1px solid #ccc;
}
td h3 {
  font-size: 12px;
  line-height: 22px;
  text-align: center;
  margin: 0;
}
td span {
  display: inline-block;
  font-size: 12px;
}
td a {
  clear: both;
  display: block;
  vertical-align: bottom;
  margin: 20px 0 0 0;
}



.order{
position:relative;
  border:solid 1px red;
  height:100%;
  margin-bottom:20px;
}
.add_to_cart{
background:yellow;
  position:absolute;
  left:0;
  right:0;
  bottom:0;
}

HTML

<table>
    <tr>
      <td>
        <div class="order">
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://www.gravatar.com/avatar/f20d2122fec97d8544bdbb998f5da742?s=32&d=identicon&r=PG">
        <h3>Battle Field dsvadv dsadhjkba dsakjdbsa</h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
        <a href="#" class="add_to_cart">Add to cart</a>
          </div>
      </td>
      <td>
        <div class="order">
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://www.gravatar.com/avatar/f20d2122fec97d8544bdbb998f5da742?s=32&d=identicon&r=PG">
        <h3>Battle Field </h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
          <a href="#" class="add_to_cart">Add to cart</a></div>
      </td>
    </tr>


        <tr>
      <td>
        <div class="order">
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://www.gravatar.com/avatar/f20d2122fec97d8544bdbb998f5da742?s=32&d=identicon&r=PG">
        <h3>Battle Field dsvadv dsadhjkba dsakjdbsa</h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
        <a href="#" class="add_to_cart">Add to cart</a>
          </div>
      </td>
      <td>
        <div class="order">
        <img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://www.gravatar.com/avatar/f20d2122fec97d8544bdbb998f5da742?s=32&d=identicon&r=PG">
        <h3>Battle Field </h3>
        <span class="price"><del><span class="amount">$&nbsp;67.00</span></del> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
          <a href="#" class="add_to_cart">Add to cart</a></div>
      </td>
    </tr>
  </table>

现场演示

于 2012-10-19T05:44:44.267 回答