[英]Vertically align span with inline-block div > table
Given this unfortunate but required structure: 鉴于这种不幸但必不可少的结构:
<span>Label Text</span>
<div>
<table>
<tbody>
<tr>
<td>Single Row Table Text</td>
</tr>
</tbody>
</table>
</div>
And the given CSS: 和给定的CSS:
span {
vertical-align: middle;
}
div {
display: inline-block;
}
table {
border: 1px solid red;
}
What is the correct way to style the span so that it appears to be vertically aligned with the div > table? 为跨度设置样式以使其看起来与div>表格垂直对齐的正确方法是什么?
Here is a simple example of what I do not want: http://jsfiddle.net/itslittlejohn/3hLsy1yf/2/ 这是我不想要的简单示例: http : //jsfiddle.net/itslittlejohn/3hLsy1yf/2/
Just set both <span>
and <div>
as inline block and vertical align middle. 只需将
<span>
和<div>
为行内块和垂直对齐中间。
span, div { display: inline-block; border: 1px solid red; vertical-align: middle; }
<span>Label Text</span> <div> <table> <tbody> <tr> <td>Single Row Table Text</td> </tr> </tbody> </table> </div>
Does this get you close to what you want? 这会使您接近所需的东西吗?
span{
vertical-align: top;
padding-top: 4px;
display: inline-block;
}
This may not work in a context where there is more content or there are other factors involved. 在存在更多内容或涉及其他因素的情况下,这可能不起作用。 If there are more elements that would affect the position of the span and/or table could you post that code as well?
如果还有更多元素会影响范围和/或表的位置,您是否也可以发布该代码?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.