2012-09-16 139 views
0

我有我的網站的標題(見圖片)buttons of the headerHTML - 對齊表格列權

它們基本上<td><a href>「用CSS樣式秒。現在我的問題是如果要在同一行中添加一個或多個按鈕但將它們對齊到右側,我該怎麼辦?

它不一定是一個CSS解決方案,我正在尋找一種方法來做到這一點在HTML的<table><td>標籤。

謝謝。

編輯:這是生成的頭PHP的一部分:

echo<<<TOPBARHEREDOC2 
<link rel="stylesheet" href="/css/horizontal_navbar.css" type="text/css" media="screen"> 
<table border="auto" id="topbar" >   
    <td><a class="topbarlink" href="index.php">Ana Sayfa</a></td> 
    <td><a class="topbarlink" href="userstats.php?category=$category">İstatistik</a></td> 
    <td><a class="topbarlink" href="contact.php">İletişim</a></td> 
    <td><a class="topbarlink" href="useful_links.php">Linkler</a></td> 
    <td><a class="topbarlink" href=$lastlink_address>$lastlink_name</a></td> 
</table> 
<hr> 
<br> 
TOPBARHEREDOC2; 

,這是CSS:

table a.topbarlink{ 
/*TOP, RIGHT, BOTTOM, & LEFT*/ 
margin:0px 0px 0px 0px; 
font-family: Futura, "Trebuchet MS", Arial, sans-serif; 
font-weight:bold; 
color:#069; 
background-color: #f2f2f2; 
text-decoration: none;  
    border-bottom: 2px solid #ccc; 
    border-top: 2px #ccc; 
    border-right: 2px solid #ccc; 
    border-left: 2px #ccc; 
    /*padding (ordered)*/ 
    padding-top:0.2em; 
    padding-right: 1em; 
    padding-bottom:0.2em; 
    padding-left: 1em; 

} 
+0

你能提供一些代碼,例如在jsfiddle.net? –

+0

nope,簡單的html(用php生成)和css。將代碼添加到問題中。 – void

回答

3

首先,你真的不應該使用什麼表除表格數據外。語義標記總是更好,所以在你的情況下,最好爲你的菜單使用未編號的列表。

不管怎樣,讓我們​​說這是你的表:

<table> 
    <tr> 
    <th><a href="#">Item 1</a></th> 
    <th><a href="#">Item 2</a></th> 
    <th><a href="#">Item 3</a></th> 
    <th class="right"><a href="#">Item 4</a></th> 
    </tr> 
</table> 

然後你就可以使用這個CSS到一個項目右對齊:

table { width: 100%; } 
th { float: left; } 
th.right { float: right; }​ 

http://fiddle.jshell.net/6z97w/

+0

+1比我的更好的答案:) –