【发布时间】:2017-02-19 13:04:37
【问题描述】:
我正在为我的网站制作导航栏。导航栏包含一个菜单图标、一个标题“评论”和一个搜索图标。图标需要与边框有 3% 的距离。问题是我无法弄清楚我如何使文本居中。我认为问题出在浮动元素上,我不知道如何将浮动元素居中于其他元素之间(在本例中为两个图标)。我希望有人能给我一个答案:)
这是结果:
* {
padding: 0px;
margin: 0px;
}
#nav {
width: 94%;
background-color: blue;
margin: 3%;
}
.menuButton {
float: left;
}
#nav h1 {
float: left;
}
.searchButton {
float: right;
}
<!DOCTYPE html>
<html>
<head>
<title> Reviews </title>
<link rel="stylesheet" type="text/css" href="main.css">
<meta charset="utf-8">
</head>
<div id="dropMenu"></div>
<body>
<div id="nav">
<img src="menu.jpg" class="menuButton">
<h1> REVIEWS. </h1>
<img src="search.jpg" class="searchButton">
</div>
<div id="content"></div>
<div id="footer"></div>
</body>
</html>
【问题讨论】: