html - align table column right

心已入冬 提交于 2020-01-06 19:37:34

问题


I have a header for my website (see in the picture)

which are basically <td><a href>'s styled with css. now my question is what do I do if want to add one or more buttons in the same row but align them to the right?

It does not have to be a css solution, I'm looking for a way to do this in html's <table> or <td> tags.

Thanks.

Edit: This is the part of php that generates the header:

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;

and this is the 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;

}

回答1:


First of all, you really shouldn't use tables for anything other than tabular data. Semantic markup is always better, so in your case it would be better to use an unnumbered list for your menu.

Anyhow, let's say this is your table:

<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>

Then you can use this CSS to align one item to the right:

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

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




回答2:


Is this what you're looking for? http://jsfiddle.net/henrikandersson/aayxV/



来源:https://stackoverflow.com/questions/12446645/html-align-table-column-right

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!