html - 以 HTML 格式在屏幕上垂直居中链接

标签 html css center

这是我的 HTML 代码:

<!DOCTYPE html>
<html>
<head>
    <title>Start</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="wrapper">
    <a href="start.html" id="start-button">Start</a>
</div>
</body>
</html>

这是我的 CSS:

* {
    margin: 0;
    padding: 0;
}

div#wrapper {
    width: 100%;
    height: 100%;

    background-color: black;

    overflow: hidden;
}

a#start-button {
    /* How to center? *?
}

我的问题是:如何使链接垂直居中?我不想给页面一个固定的高度。我尝试了一些选项,但它们都没有真正起作用或无法解决我的问题。 非常感谢!

最佳答案

See the Demo

你需要给父级 div display: table 和子级 display : table-cell with vertical-align: middle

* {
    margin: 0;
    padding: 0;
}
html, body {
    width: 100%;
    height: 100%;
}
div#wrapper {
    width: 100%;
    height: 100%;
    background-color: black;
    overflow: auto;
    display: table;
}

a#start-button {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

关于html - 以 HTML 格式在屏幕上垂直居中链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159760/

相关文章:

php - 显示动态单选按钮是否被选中

html - Ionic flexbox 无法设置输入垂直

jquery - 如何在 html 和 css 中将 div 居中,始终保持纵横比,并填充最大屏幕宽度/高度?

javascript - 使用来自另一个表的数据动态地将行添加到表中-jQuery

基于 "smoothness"的 CSS Transition 回退

html - 如何使用 Bootstrap 和 960.gs 分离样式和 html

android - Horizo​​ntal RecyclerView 项目居中

html - 在div的中心水平对齐多个图像

html - Internet Explorer 中的图像很大,而 firefox 和 chrome 都很好

javascript - 如何使用 HTML 中的 JSON 外部文件填充下拉按钮