将 <img> 垂直居中放在表格 <td> 内
Centering an <img> vertically inside of a table <td>
我正在尝试将这些图像垂直居中在表格内,而无需编辑图片以使它们大小相同。尝试了一些事情...我知道每当我想水平居中时,我都会使用 margin-left: auto; margin-right: auto;
所以我想也许同样适用于这里,但有顶部和底部,但没有骰子。
编辑:这是另一个想法...是否可以设置一个JavaScript在页面打开时运行,以将所有文本跨度定位为该行中的最低跨度?只是一个想法...让我知道你的想法
任何帮助将不胜感激。
这是小提琴:http://jsfiddle.net/58u4g/1/
提前致谢
CSS 垂直对齐方式在所有浏览器中都是不同的 - 特别是如果您想将文本保留在同一单元格中。
我建议为要进入的图像创建一个固定高度的块,并使用垂直对齐技巧使图像在该div 内垂直居中(我知道,黑客很糟糕)。
JSFiddle: http://jsfiddle.net/58u4g/8/
垂直对齐黑客:http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
相关 CSS:
.valign {
width: 100%;
display: block;
display: table;
height: 100%;
#position: relative;
overflow: hidden;
}
.valign > span {
display: block;
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
}
.valign> span > span {
display: block;
#position: relative;
#top: -50%;
}
#posiflex_directory td .image {
height: 160px;
display: block;
}
为了
分离元素以更好地控制它们,我会以不同的方式做,即使我的小提琴不干净,并且是你的样本加上我在:)通过的部分的混合
体<table id="posiflex_directory">
<tr class="theimgs">
<td>
<a href="../posiflex/tx_overview.aspx" id="posiTXIcon">
<span class="valigner"></span>
<img height="125" src="https://www.metsales.com/MetropolitanSales/microsite/posiflex/images/home_icons/tx-4200.png" width="200"/>
</a>
</td>
<td>
<a href="../posiflex/cd_overview.aspx" id="posiCDIcon">
<span class="valigner"></span>
<img height="103" src="https://www.metsales.com/MetropolitanSales/microsite/posiflex/images/home_icons/CR6300.png" width="200"/>
</a>
</td>
</tr>
<tr>
<td class="imgtext"><a href="../posiflex/tx_overview.aspx" id="posiTXIcon"><span>TX Fan-Free Series</span></a></td>
<td class="imgtext"><a href="../posiflex/cd_overview.aspx" id="posiCDIcon"><span>Cash Drawers</span></a></td>
</tr>
</table>
#posiflex_directory {
text-align: center;
}
#posiflex_directory a {
color: inherit;
position: relative;
}
#posiflex_directory td {
border: solid 1px;
}
#posiflex_directory .theimgs {
width: 215px;
height: 225px;
padding: 5px;
border: solid 1px;
}
#posiflex_directory span {
left: 0;
right: 0;
top:100%;
bottom: 5px;
text-decoration: underline;
font-weight: bold;
}
img {
border: solid 1px;
}
.valigner {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.imgtext{
height:40px;
}
相关文章:
- 使用谷歌地图api计算距离并将其设置在表格中<td>
- 通过指定类更改表格td边框颜色
- 获取表格行数据td并选择
- 动态生成的表格 - 使用数组填充TD值
- 循环通过表格查找第一个具有 CSS CSSstablelisttdselect 的 TD 文本
- 如何使用JavaScript在HTML表格中获取td内部的链接文本
- 如何防止 td 中的文本破坏表格的对齐方式
- Javascript 使用表格 td 的宽度过滤 HTML 内容
- 具有固定标题以及水平和垂直滚动的表格,不给 td 或 th 提供宽度
- 无法引发 HTML 表格 TD“更改”事件
- 更改表格中单个单元格(TD)的CSS
- 根据表格单元格按钮动态访问 td
- jQuery从TD(HTML表格)内的输入字段中获取值
- 如何使用两个不同颜色的按钮更改表格单元格(td)的背景颜色
- 单击添加和删除表格数据的背景色(td)
- 我如何根据需要在表格中添加我的 td
- 如何使表格td tr根据文本长度自动宽度
- 如何转换表格td内联样式宽度pt以转换百分比以适合响应
- 我想用javascript填充html表格td's与数学运算结果
- 表格td标签中弹出窗口提示的问题