好吧,我几乎可以将文字与中心对齐。我可以使用左右边距自动,他们会在中心,我把文本定位中心和工作,但我试图创建一个链接和链接的标题不移动就像我要对齐一个段落。我几乎想要水平地连接到中心。
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>
答案 0 :(得分:1)
将您的链接包装在容器中,并让该容器具有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>