我正在制作一个网络应用程序,我需要位于中间列的4x链接垂直均匀分布,并且链接内的文本也可以水平和垂直居中。
以下图片是我所追求的,请注意该网站将会有所回应。我想在这个阶段避免使用flexbox,因为我遇到了一些浏览器兼容性问题。
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;
}
}
答案 0 :(得分:1)
尝试使用display: table
和display: 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 强>