html - CSS - 左右对齐在同一行

标签 html css

下面是一些示例代码,其中所有链接都是右对齐的。我想更改 CSS,使“左”链接左对齐,其他链接右对齐,但它们都在同一行上。我该怎么做?

提前致谢

约翰

HTML:

<div class="mainlinks">
    <a href="left.php" class="links">Left</a>
    <a href="right1.php" class="links">Right1</a>
    <a href="right2.php" class="links">Right2</a>
</div>

CSS:

.mainlinks
    {
    text-align:right;
    margin-top:3px;
    margin-right:10px;
    margin-bottom:0px;
    padding:0px;
    }

 a.links:link {
    color: #FF0000; text-decoration: none;
    text-align:center;
    margin-left:8px;
    margin-top:300px;
    margin-bottom:0px;
    padding:2px;
    font-family:Arial, Helvetica, sans-serif;
    font-size: 14px;
    }

最佳答案

这是一篇旧文章,但它在 google 上的排名很高,因此仍然具有相关性。

我用了另一种方法在同一条线上左右对齐,没有使用任何丑陋的 float 。它使用类似表格的显示:

HTML:


    <footer>
      <nav>links (to the left)</nav>
      <p>copyright (to the right)</p>
    </footer>

CSS:


    footer
    {
      display: table;
      width: 100%;
    }
    footer nav
    {
      display: table-cell;
      text-align: left;
    }
    footer p
    {
      display: table-cell;
      text-align: right;
    }

我发现这样更干净。

希望这对某人有帮助!

关于html - CSS - 左右对齐在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1062783/

相关文章:

android - 多色字符串 (android)

html - 自定义形状的 Photoshop 切片到 HTML

javascript - HTML5 Canvas 线宽错误?

javascript - 更改设备方向时 CSS 失败

php - Prestashop 在使用 jquery 多 css 方法时显示白页

javascript - Canvas 渲染分辨率 - 如何在 flex 布局中使用 Canvas

javascript - 单击时隐藏/关闭(下一个)div,但有可能显示多个 div

javascript - 将标题放在顶部一个下面,类似于页面索引

html - 在媒体查询中使用绝对定位元素

css - Angular 2 Flex 布局右对齐图标