html - 文本对齐 :centre not aligning text correctly in <a>

标签 html css

我正在试验以下 HTML 代码。它在底部显示一个段落和两个按钮(上一页和下一页)。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>HTML Test</title>

<!-- stylesheet -->
        <style type="text/css" media="screen">
<!-- for UL. Hopefully straightforward to understand-->    
            #navigation {
            list-style-type:none;
            border-top:1px solid red;
            margin:0;
            padding:0;
            }
    <!-- to float left.Hopefully straightforward to understand -->
            ul#navigation .left{
                float:left;
                width:5em;
                margin: 10px 0 0 0;
            }
    <!-- to float right. Hopefully straightforward to understand -->
            ul#navigation .right {
                float:right;
                width:5em;
                margin: 10px 0 0 0;
            }
    <!-- for a in li. Hopefully straightforward to understand -->
            ul#navigation li a {
            display:block;
            padding:.2 em;
            color:#fff;
            width:5em;
            background-color:#00f;
            text-align:centre; <!-- this isn't effective!-->
            text-decoration:none;
            }

        </style>
    </head>
<!-- mainbody-->

我希望文本居中对齐,但没有。我已经使用 text-align:centre 来设置 .我做错了什么?

<body>


    <p>
        1. Some Para.
    </p>
    <ul id="navigation" >
    <!-- The Back and Next should centre up but they are left aligned -->
        <li class="left"> <a href="#">Back</a></li>
        <li class="right"> <a href="#">Next</a></li>
    </ul>


    </body>
    </html>

最佳答案

您需要使用 text-align: center,而不是 'centre'。

ul#navigation li a {
    display: block;
    padding: .2 em;
    color: #fff;
    width: 5em;
    background-color:#00f;
    text-align: center;
    text-decoration: none;
}

关于html - 文本对齐 :centre not aligning text correctly in <a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868110/

相关文章:

css - 你能把按钮居中吗?

javascript - jQueryUI 按钮 : How to change Button-Icon 'color'

javascript - 堆叠条形图的 D3 到 CSS 颜色

javascript - 如何克服 CHtmlView 中的脚本错误?

html - 如何让 flexbox 填充 100% 的高度

javascript - CSS网格布局使用javascript更改列宽

javascript - 如何为 RadioButtonList 的每个重复列设置不同的背景颜色

javascript - 在 Knockout 中调整 Leaflet JS map 的大小

javascript - 在 Electron 中使用 ipc 从渲染器设置全局变量

javascript - 无法使用 jQuery 定位多个单词