我试图将Nav Bar的内容集中在一起但是,我无法正常工作
我认为一切似乎都比中心更左对齐,但我没有使用浮动:留在任何地方
我正在尝试居中图片和导航
代码:
<!DOCTYPE html>
<html>
<head>
<title>Soni's Computer Repair</title>
<meta name="viewport" content="width=device-width, inital-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<a class="navbar-brand"><img src="Final.png"/></a>
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<h6 class="text-center">Copyright © Soni Computer Repairs</h6>
<p class="text-center">www.SoniRepairs.com</p>
</div>
</footer>
</body>
</html>
CSS:这是CSS代码
.nav, .navbar-nav {
text-align: center;
}
.container img {
height:100%;
display: block;
margin-right: auto;
margin-left: auto;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #f5f5f5;
}
@media screen and (max-width: 500px) {
.navbar-nav, .container img{
margin-left: auto;
margin-right: auto;
display: table;
table-layout: fixed;
float:none;
}
.navbar-brand {
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
}
}
答案 0 :(得分:0)
HTML:我在ul
中移动了navbar品牌<div class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<a class="navbar-brand"><img src="Final.png"></a><li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
CSS:我添加了这3行
@media (min-width: 768px) {
.navbar-nav { float: none; }
.navbar-nav>li { float: none; display: inline-block; }
.navbar>.container .navbar-brand, .navbar>.container-fluid .navbar-brand { float: none; display: inline-block; }
}
它以这种方式为我工作。享受=)