2标签内部td对齐

时间:2013-09-20 11:43:32

标签: html css

我在td中有2个标签并且我正在努力使对齐工作

有可能吗?

这是同一个解释问题和我需要的小提琴。

jsFiddle

 <tr>
        <td><label >Some Label Test:</label><label>Some Label Test:</label></td>
    <td>
        <label >Some Label Test:</label>
        <label >here is the long test which exceeds the width and comes to second line but i want it like it should start below after test: instaead from some</label></td>
 </tr>

我在内部寻找第二个标签,如果长度很长,它会进入下一行并从第二个标签开始的地方开始。

2 个答案:

答案 0 :(得分:1)

以下是如何获得所需内容的简单div用法。 http://jsfiddle.net/KHAJz/3/

HTML

<div class="container">
    <div class="first">Some Label Test:</div>
    <div class="first">Some Label Test:</div>
    <div class="first">Some Label Test:</div>
    <div class="text">here is the long test which exceeds the width and comes to second line but i want it like it should start below after test: instead </div>
</div>

CSS

.container{
    width:700px;
    height:60px;
    display:inline-block;

}

.first{
    width:60px;
    height:60px;
    display:inline-block;
    float:left;
}
.text{
    width:300px;
    display:inline-block;
    float:left;
}

你所做的是制作一个容器,将所有东西放在一起,这样桌子或div就不会到处都是。

答案 1 :(得分:0)

如果您不想(或无法)更改您的DOM, 只需将其添加到 CSS

即可
label
{
    display: inline-block;
    height: 100%;
}

请参阅此Working Fiddle

但是如果您可以更改DOM,我建议您保留表格布局并使用div重建布局。就像基思的回答一样。