gpt4 book ai didi

html - 如何在 div 中垂直均匀分布链接?

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:18 25 4
gpt4 key购买 nike

我正在制作一个网络应用程序,我需要位于中间列中的 4x 链接在垂直方向上均匀分布,并且链接内的文本也要在水平和垂直方向上居中。

下图是我想要的,请注意网站是响应式的。我想在这个阶段避免使用 flexbox,因为我遇到了一些浏览器兼容性问题。

CodePen Demo

enter image description here

HTML:

<!DOCTYPE html>
<html>
<head>


<title>Runna - Track your run!</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="js/js.js"></script>
<script src="js/modernizr.js"></script>
</head>
<body>
<div class="wrapper">
<header>
<img src="imgs/logo-blue.png" />
</header>
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d11564.804405086046!2d172.59430635!3d-43.56069255!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2snz!4v1418977732755" frameborder="0" style="border:0"></iframe>
<section class="control-container">
<div class="column left">

</div>
<div class="column middle">
<nav>
<ul>
<li>
<a href="#"><i class="fa fa-chevron-down"></i></a>
<a href="#">START</a>
<a href="#">STOP</a>
<a href="#">PAUSE</a>
</li>
</ul>
</nav>
</div>
<div class="column right">

</div>
</section>


</div>
</body>
</html>

CSS:

* {
margin: 0;
padding: 0;
font: 100% arial;
overflow: hidden;
}
@media all and (max-width: 150em) {

header {
width: 100%;
height: 5vh;
background: black;
}

header img {

height: 100%;

}

iframe {
width: 100%;
height: 65vh;
display: block;
}

.control-container {
width: 100%;
height: 30vh;
background: black;
display: table;

}
.column {
display: table-cell;
color: white;
width: 100%;
text-align: center;
}

.row {
display: block;
width: 100%;

}

.left {
background: yellow;
width: 33.3%;
height: 100%;
}

.middle {
background: black;
width: 33.3%;
height: 100%;
}

.right {
background: red;
width: 33.3%;
height: 100%;

}

nav ul {
height: 100%;
margin: 0;
padding: 0;
}

nav li {
display: block;
}

nav a {
color: white;
text-decoration: none;
text-align: center;
width: 100%;
padding: 30px;
}

nav a:hover {
background: green;
}
}

最佳答案

尝试使用display: tabledisplay: table-row

.column.middle ul,.column.middle nav,.column.middle li {
height: 100%;
}
.column.middle li {
display: table;
width: 100%;
}
.column.middle li a {
display: table-row;
width: 100%;
}

Working Fiddle

上述解决方案可行,但如您所见,菜单项并未垂直居中。为了使它们居中,我用 div 元素包裹了菜单项内容。并添加了以下 CSS:

.column.middle li a div {
display: table-cell;
vertical-align: middle;
}

Updated Fiddle

关于html - 如何在 div 中垂直均匀分布链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27631777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com