那么如何让一个 anchor 标签链接垂直和水平居中呢?没有使用 div 或任何父元素。我只想将它居中,如下图所示。 This is how i want it to look like.
这是我的代码:
<html>
<head>
<style type="text/css">
body{
background:#000;
}
.link{
font-size:40px;
}
</style>
</head>
<body>
<center><a class="link" href="#">BornExplorer</a></center>
</body>
</html>
最佳答案
如果您要使用单个链接进行完整页面设置,您可以使用 line-height:100vh
设置居中,这意味着行高是页面高度的 100%。
html,body{width:100%;height:100%;margin:0;}
body{
background:#000;
line-height:100vh;
}
.link{
font-size:40px;
line-height:1;
display:inline-block;
}
<center><a class="link" href="#">BornExplorer</a></center>
关于html - 如何在没有任何 div 的情况下将 anchor 标记元素垂直和水平居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37057264/