CSS链接定位没有居中

时间:2013-11-15 19:31:06

标签: html css

好吧,我几乎可以将文字与中心对齐。我可以使用左右边距自动,他们会在中心,我把文本定位中心和工作,但我试图创建一个链接和链接的标题不移动就像我要对齐一个段落。我几乎想要水平地连接到中心。

div {
    border: black solid 5px;
    margin: 40px;
}

a {
    border: green solid 5px;
    margin-left: 30px;
    margin-right: 30px;
    color: red;  
    text-align:right;
}

p{
    border: green solid 5px;
    margin-left: 30px;
    margin-right: 30px;
    color: red;  
    text-align:center;
}

这是我的HTML

<link type="index/css" rel="stylesheet" href="css/style.css">
</head>
<body>
    <div>

        <a href="sksksk">Link</a>
        <a href="sksksk">Link</a>
        <a href="sksksk">Link</a>


        <p> This is a paragraph and I can write whatever I like
            Yes this is a damn pargraph and I hate it and dont
            know what to say
        <p> This is a paragraph and I can write whatever I like
            Yes this is a damn pargraph and I hate it and dont
            know what to say
        <p> This is a paragraph and I can write whatever I like
            Yes this is a damn pargraph and I hate it and dont
            know what to say
    </div>
</body>

3 个答案:

答案 0 :(得分:1)

DEMO

将您的链接包装在容器中,并让该容器具有text-align:center

<强> HTML

<div id="thisisadamncontainer">
    <a href="sksksk">Link</a>
    <a href="sksksk">Link</a>
    <a href="sksksk">Link</a>
</div>

<强> CSS

#thisisadamncontainer
{
    text-align:center;
}

答案 1 :(得分:0)

text-align: center添加到您的div

   div {
        border: black solid 5px;
        margin: 40px;
        text-align: center;
    }
默认情况下,

a元素为display: inline,这意味着它们会被text-align: center等属性视为文本,因此如果您将其添加到其父容器div,它们将是居中。

这是 working JSFiddle

答案 2 :(得分:0)

行业标准是根据您的需要使用ul DEMO http://jsfiddle.net/LstNS/29/

     <ul>
        <li><a href="sksksk">Link</a></li>
        <li><a href="sksksk">Link</a></li>
        <li><a href="sksksk">Link</a></li>
    </ul>