我需要为学校的计算机科学课程制作一个网站,但是我在让菜单栏居中时遇到了问题。我想让它围绕菜单按钮居中,但是我使用的方法会使图标偏离中心。
如何将整个菜单围绕中央的li
元素居中呢?
以下是代码:
body {
background-color: /*#C94421*/
#353535;
margin: 0;
/* reset de standard marges van de body -> geen randen links en rechts naast .menuBar div */
text-align: center;
}
.menuBar {
height: 70px;
width: 100%;
}
.menuBar img {
text-align: center;
}
.menuBar ul li {
display: inline;
padding-right: 65px;
line-height: 70px;
}
.menuBar ul li a {
color: white;
text-decoration: none;
line-height: 70px;
font-family: 'Raleway', sans-serif;
font-size: 36px;
width: 100px;
}
.menuBar a:hover {
border-bottom: 1px solid white;
}
.jumbotron .container {
height: 550px;
width: 60%;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 10px;
border-top: 4.5px double white;
border-bottom: 4.5px double white;
}
<!DOCTYPE html>
<html>
<head>
<title> Homepagina </title>
<link rel="stylesheet" type="text/css" href="main.css">
<link href='https://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
</head>
<body>
<div class="menuBar">
<ul>
<li> <a href="#"> Over mij </a> </li>
<li> <a href="#"> Hobbies </a> </li>
<li>
<a href="#"> <img src="logoNaam.jpg"> </a>
</li>
<li> <a href="#"> Muziek </a> </li>
<li> <a href="#"> Waarom informatica </a> </li>
</ul>
</div>
<div class="jumbotron">
<div class="container">
hoi
</div>
</div>
</body>
</html>
li
元素在页面中心对齐的图片周围流动。 - Maximillian Laumeister