Reputation: 1459
How can I align vertical text, that is generated by two spans, inside a div inside a table cell. I've tried many combinations of text-align,display but nothing worked. I have this html segment
<table>
<tr>
<td>
<div class="container">
<span>This is span-sentence-1</span>
<span>This is span-sentence-2</span>
</div>
</td>
</tr>
</table>
and the output is
This is span-sentence-1 This is span-sentence-2
while I want to be rendered like this
This is span-sentence-1
This is span-sentence-2
fiddle:http://jsfiddle.net/hjuxdd1b/1/
Upvotes: 2
Views: 1552
Reputation: 24712
You may not need that div:
Set those spans to display: block
so they are each given their own line.
Give vertical-align: middle
to the td so that its content will stay vertically centred.
By default a span is display: inline
so they will line up next to each other. You could read more about the span element over on the MDN.
CSS
td {
vertical-align: middle;
height: 100px;
border: 1px solid black;
}
td span {
display: block;
}
HTML
<table>
<tr>
<td>
<span>This is span-sentence-1</span>
<span>This is span-sentence-2</span>
</td>
</tr>
</table>
Upvotes: 0
Reputation: 167240
Give display: block
to .container span
.container span {display: block;}
Remove the height
and line-height
in the .container
Upvotes: 0