2013-08-18 67 views
0

我想有我左欄右對齊,和我的右列左對齊,讓他們排隊沿中心軸,像這樣:如何沿軸對齊文本?

16 January 2013 | Here is a line of text. 
26 December 2013 | Another line of text here. 
     4 May 2011 | Here is something else. 

的HTML是<span> S,這樣的:

<div class="line"> 
    <span class="date">16 January 2013</span> <span class="text">Here is a line of text.</span> 
</div> 

我一直在試圖與.line { display: table-row; }.line span { display: table-cell; }要做到這一點,但它似乎並沒有工作。

+0

是確定的,如果你的線有一個固定的寬度是多少? :D –

+0

我想是的。我想這就是缺少的。 – Jono

回答

1

試試這個..

<div class="line"> 
    <div style="width:50%;float:left;text-align:right;" class="date">16 January 2013</div>  
    <div style="width:50%;float:left;text-align:left;" class="text">Here is a line of text.</div> 
</div> 

DIV-S你合適嗎? :d

0

我會陪着跨度:

CSS:

#container 
{ 
    display: table; 
} 

.left 
{ 
    margin-left: 10px; 
    width: 200px; 
    float: right; 
    text-align: left; 
} 

.right 
{ 
    margin-right: 10px; 
    width: 200px; 
    text-align: right; 
    float: left; 
} 

HTML:

<div id='container'> 
    <span class='left'>Lorem</span> <span class='right'>Ipsum</span><br/> 
    <span class='left'>dolor sit</span> <span class='right'>amet</span> 
</div> 

在這裏看到的動作:http://jsfiddle.net/AyhyZ/1/