gpt4 book ai didi

html - 导航栏的中心内容 - BootStrap

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

我试图将导航栏的内容居中,但是我无法让它正常工作

我认为一切似乎都比居中更左对齐,但我没有在任何地方使用 float:left

我正在尝试将图像和导航居中

代码:

<!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 &copy; 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;
}
}

最佳答案

HTML:我将 navbar-brand 移到了 ul 中

<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; }
}

它对我来说是这样工作的。享受 =)

关于html - 导航栏的中心内容 - BootStrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30286951/

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