【问题标题】:Place background image in middle of table cell将背景图片放在表格单元格的中间
【发布时间】:2013-04-28 07:06:07
【问题描述】:

看下图

如何在表格列 (<td>) 中居中图像?填充不要在顶部仅在右侧和底部留出空间

这是表格的html代码

<table>
<tbody>
<tr>
<td class="bedButton ward-A">A115:1</td>
<td class="bedButton ward-A">A116:1</td>
</tr>
</tbody>
</table>

这里是 CSS:

.bedButton{
    padding:25px;
    width:250px;
    height:300px;
    background:url(../images/bedview/bed-background.png) no-repeat;
    margin-left: auto;
    margin-right: auto
}

【问题讨论】:

  • 您的意思是在 td 中间对齐文本??文本对齐和垂直居中对齐?
  • 不,我的意思是在 的中心对齐背景图像 =)
  • 哦,您可能想编辑问题以明确说明您要做什么。背景位置:中心中心;可能会这样做
  • 请包含背景图像的绝对 URL,因为我们看不到它..
  • Background.position 搞定了,谢谢 :)

标签: html css html-table


【解决方案1】:

要使文本水平居中,请使用:

td {
    text-align:center;
}

jsFiddle example

【讨论】:

  • 背景图片怎么样?背景:url(../images/bedview/bed-background.png)不重复; ? =)
  • 在背景的位置部分设置50% 50%,如background: url('http://www.placekitten.com/250/300') no-repeat 50% 50%;。见jsfiddle.net/j08691/qmRLa/2
猜你喜欢
相关资源
最近更新 更多
热门标签