我似乎无法将“主页”按钮置于中央。主页文本位于左侧而不是中心。我的 htm 和 css 链接如下: HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="background.css"/>
</head>
<body>
<h1>Bully-Free Zone</h1>
<h2>"Online harassment has an off-line impact"</h2>
<a href="New.html" class="nav-link">Home</a>
</body>
</html>
CSS:
a.nav-link:link
{
color: black;
text-decoration: underline;
font-family:broadway;
font-size:30px;
text-align:center;
}
a.nav-link:visited
{
color: black;
text-decoration: none;
}
a.nav-link:hover
{
color: black;
text-decoration: none;
}
a.nav-link:active
{
color: black;
text-decoration: none;
}
最佳答案
您可以将其包装在 div
中:
<div align="center">
<a href="New.html" class="nav-link">Home</a>
</div>
或者您可以为 div
创建一个类:
HTML:
<div class="myDiv">
<a href="New.html" class="nav-link">Home</a>
</div>
CSS:
.myDiv {
text-align: center;
width: 300px;
}
关于html - 无法文本对齐 :center on css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10183800/