gpt4 book ai didi

javascript - 如何使 nav-fixed-top 像非固定导航栏一样下推内容?

转载 作者:太空狗 更新时间:2023-10-29 16:39:33 24 4
gpt4 key购买 nike

我想让我的导航栏固定在顶部并在我打开折叠菜单时按下内容,就像通常在静态或只是导航中所做的那样。

像这样:(https://getbootstrap.com/examples/navbar-static-top/)但我希望导航栏固定在顶部。

我之前读过这个:Navbar-fixed-top pushes content on page up

但是加padding不行,请帮我解决这个问题xD

我的代码

CSS 和 HTML:

/*------------------------------------------------- Hero Image -------------------------------------------------*/

.calltoaction {
text-align: center;
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
/* Rules below not implemented in browsers yet */
-o-user-select: none;
user-select: none;
}

.calltoaction h1 {
text-align: center;
display: inline-block;
font-size: 70px;
/*text-transform: uppercase;*/
letter-spacing: 2px;
border: 8px solid #FFFFFF;
border-radius: 13px;
padding: 17px 20px;
color: white;
font-family: sans-serif;
font-weight: 900;
}

.calltoaction h3 {
color: #FFFFFF;
font-size: 29px;
text-align: center;
}


#hero-image {
height: 870px;
background: #e8eced url('http://twnateserver.no-ip.org/Pictures/taiwan-taipei.jpg') no-repeat center;
}

#hero-image h1 {
margin: 215px 0 7px 0;
}

#hero-image h3 {
margin: 3% 0 7px 0;
}


/*#hero-image a {
margin: 3% 0 7px 0;
}*/



/*------------------------------------------------- Hero Image -------------------------------------------------*/




/*------------------------------------------------- navbar----------------------------------------------*/
.navbar {
background-color: rgba(15, 91, 121, 0.03);
background: rgba(15, 91, 121, 0.03);
border-color: rgba(15, 91, 121, 0.03);
margin-bottom: 0px;

/*Line 4213-4217 in Bootstrap.css*/
/*Goal effect: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_navbar_collapse&stacked=h*/

}

.navbar li {
color: #000;
}


.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
list-style: none;
background-color: rgba(233, 237, 239, 0.42);
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(15, 91, 121, 0.03);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
}


/*Line 4513-4574 in Bootstrap.css define the colors of navbar texts and hover colors*/


/*---------------------------------------------------------------------------------------------------------------*/
<!DOCTYPE html>
<html>

<head>
<title>Nate</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/index.css" rel="stylesheet">
<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel='shortcut icon' type='image/x-icon' href='favicons/0.ico' />



</head>

<body>

<!-- Fixed Top Navbar, please add middle to top fixed navbar too when you can... -->

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Nate's Testing Place</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<!-- li class="active" -> transform button to grey -->
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span>&nbsp Log in</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>



<!-- Hero Image and texts -->
<div id="hero-image">
<div class="calltoaction">
<h1><b>Nate's Testing Place</b></h1>
<h3>Just a testing site, always open but not seven-eleven...</h3>
<!--<a href="#" class="btn btn-lg btn-info" role="button">Let's Go</a>-->
</div>
</div>
<!-- Hero Image and texts -->


<div class="containter widgetpadding">
<div class="col-md-4 col-xs-6">
<h4>My First Unity Game: Roller Madness (Project 2 of the coursera course)</h4>
<a href="Test.html" class="btn btn-info" role="button">Play Roller Madness</a>
</div>
<div class="col-md-4 col-xs-6">
<h4>Just a nevbar testing page, css is so tricky......</h4>
<a href="NavTest.html" class="btn btn-info" role="button">Go to nevbar test page</a>
</div>
<div class="col-md-4 col-xs-6">
<h4>Some installation info for installing Kali linux, no installation required now...</h4>
<a href="KaliLinux.html" class="btn btn-info" role="button">Kali Linux Installation info</a>
</div>
<div class="col-md-4 col-xs-6">
<h4>Text Tutorial for dual-booting Arch and Windows10 UEFI......</h4>
<a href="Arch.html" class="btn btn-info" role="button">Arch info</a>
</div>
<div class="col-md-4 col-xs-6">
<h4>Installing arch by installing Antergos is much more easier and pleasant......</h4>
<a href="Antergos.html" class="btn btn-info" role="button">Antergos info</a>
</div>
<div class="col-md-4 col-xs-6">
<h4>sdfsadfsdfsdfasdfawefregergtrhrtyhjytjtyjtyjtyjtyjtyjtyjtyjtryjtryjrtyjrtyjtyj</h4>
<a href="ITX.html" class="btn btn-info" role="button">aetvretevtdsfv</a>
</div>
</div>



<!--Back to Top Widget: http://html-tuts.com/back-to-top-button-jquery/ -->
<div class="">

</div>
<!--Back to Top Widget-->

</body>

</html>

最佳答案

如果padding不适合你,试试这个 <nav> :

nav.navbar-fixed-top {
position:fixed;
top:0;
}

然后是下面的 <body> :

body::before {
display:block;
content: '';
height:60px; /* or whatever */
}

关于javascript - 如何使 nav-fixed-top 像非固定导航栏一样下推内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37391541/

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