gpt4 book ai didi

javascript - 如何从静态导航栏转到位置 :fixed without screwing everything?

转载 作者:行者123 更新时间:2023-11-28 01:25:53 26 4
gpt4 key购买 nike

当我从一个位于浏览器顶部的普通导航栏开始时遇到问题,当你向下滚动到一个位置时消失:固定的导航栏即使你滚动也停留在浏览器的顶部。

这是代码笔:https://codepen.io/bleah1/pen/gjYBgQ

问题是当我添加 position:fixed 和 top:0;左:0;右:0;对于 .header-container,它会收缩并向下移动 .navigation-bar,并将 .logo 推向左侧,使其固定在浏览器的左侧。我已经尝试更改一些值,但我仍然无法使其正常工作并且看起来不错。

此外,HTML 的制作方式有点相反:首先针对较小的窗口尺寸,如手机或平板电脑,然后针对较大的设备。

完全披露:这些不是我的想法,我是在 YouTube 上看到的,我重新创建了它们以尝试学习。这些是视频:

https://www.youtube.com/watch?v=FqbOu5ZRFag

https://www.youtube.com/watch?v=Ah_Zitni1y4&

你知道要改变什么才能让它发挥作用吗?谢谢!

/*global $:false */
/*exported formValidationSetup, refreshErrorMessages */
/*jshint unused:false*/


$('.menu-toggle').click(function(){
$('.navigation-bar').toggleClass('navigation-bar--open', 500);
$(this).toggleClass('menu-toggle--open');
});

$(".button").on("click",function(){
$(".input").toggleClass("inclicked");
$(".button").toggleClass("close");
});
@import url('https://fonts.googleapis.com/css?family=Quicksand:400,700');


header{
background-color: #1F2833;
position: relative;
color: #45A29E;
padding: 1em 0;
}

header::after{
content: '';
clear: both;
display: block;
}

body{
font-family: 'Quicksand', sans-serif;
background-color: brown;
margin:0 auto;
/*overflow: hidden;*/
}


.header-container {
position:fixed; /* This creates the problem*/
width:95%; /*changing this to 100% does nothing */
max-width: 1250px;
margin: 0 auto;
backgrounnd-color:#1F2833;

}

.logo {
color:#45A29E;
float:left;
font-size:1rem;
margin: 0;
text-transform: uppercase;
font-weight: 700;
}



.navigation-bar {
position: absolute;
top: 100%;
right: 0%;
background-color: #1F2833;
clip-path: circle(0px at top right);
transition: clip-path ease-in-out 700ms;
}

.navigation-bar--open{
clip-path: circle(150% at top right);

}


.navigation-bar ul {
margin: 0;
padding:0;
list-style: none;
}

.navigation-bar li{
border-bottom: 1px solid #C5C6C7;
}

.navigation-bar li:last-child{
border-bottom: none;
}

.navigation-bar a{
color: #45A29E;
display: block;
padding: 2em 3em 2em 1.5em;
text-decoration: none;
text-transform: uppercase;

}

.navigation-bar a:hover,
.navigation-bar a:focus {
background: #C5C6C7;
color: #0B0C10;
}

.navigation-bar--icon{
display: block;
font-size: 1.5em;
margin-right: 1em;
width:1.3em;
text-align: right;
color: rgba(255,255,255,.25);
}

.menu-toggle {

padding: 1em;
position: absolute;
top: 0.5em;
right: 0.5em;
cursor: pointer;
}


.hamburger,
.hamburger::before,
.hamburger::after {
content:'';
display:block;
background: black;
height: 3px;
width: 1.75em;
border-radius: 3px;
transition: all ease-in-out 500ms;
}

.hamburger::before{
transform: translateY(-6px);
}

.hamburger::after{
transform: translateY(3px);
}

.menu-toggle--open .hamburger{
transform: rotate(45deg);
}

.menu-toggle--open .hamburger::before{
opacity: 0;
}

.menu-toggle--open .hamburger::after{
transform: translateY(-3px) rotate(-90deg);
}

.search-container{
display: none;
}

.cover{
background: blue;
height:300px;
width:400px;

}

@media (min-width: 1250px){

.menu-toggle {
display: none;
}

.header-container{
max-width: 1200px;
}
.navigation-bar {
height: auto;
position: relative;
background: #1F2833;
float:right;
clip-path:initial;
}
.navigation-bar li{
display: inline-block;
border: none;
}
.navigation-bar a{
padding:0;
margin-left: 2em;
}

.navigation-bar a:hover,
.navigation-bar a:focus {
background:transparent;
color: rgba(255,255,255,.25);
}

.navigation-bar--icon {
display: none !important;
}

.search-container{
display: inherit;
position: relative;
float: right;
top:-5px;
margin-left: 2em;
}

}

.input{
width: 30px;
height: 30px;
background: none;
border-radius: 50%;
border: 3px solid rgba(255,255,255,.25);
box-sizing:border-box;
outline:none;
transition: width 600ms ease-in-out, border-radius 800ms ease-in-out, padding 200ms;
transition-delay: 300ms;
color:white;
font-size: 16px;
}

.inclicked{
width: 300px;
border-radius: 0;
padding: 0 15px;
padding-right: 40px;
}

.button{
position: absolute;
width:30px;
height:30px;
top:0;
right:0;
box-sizing:border-box;
background:none;
border:none;
outline: none;
cursor:pointer;

}

.button::before{
content:'';
width:3px;
height:15px;
background:rgba(255,255,255,0.25);
position: absolute;
transform: rotate(-45deg);
bottom: -10px;
right: -5px;
transition:500ms;

}

.close::before, .close::after{
content:'';
width:3px;
height: 20px;
background:rgba(255,255,255,1);
position: absolute;
bottom: 5px;
right: 15px;
border-radius: 10px;

}

.close::before{
transform: rotate(-45deg);

}
.close::after{
transform: rotate(45deg);

}

}
<!doctype HTML>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Open+Sans' type='text/css' rel='stylesheet'>

<link href="navigation-bar.css" type="text/css" rel="stylesheet">
<link href="containers.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">

<title>Mangacious</title>

</head>


<header>
<div class="header-container">
<h1 class="logo">Mangacius</h1>

<div class="search-container search-container-2">
<form class="search-box" action="index.html" method="post">
<input class="input input-2" type="text" name="search">
<button class="button" type="button" name="button"></button>
</form>
</div> <!--Little Browser Search Bar-->

<nav class="navigation-bar">
<ul>
<li><a href=""><i class="fa fa-home navigation-bar--icon"></i>Home</a></li>
<li><a href=""><i class="fa fa-calendar-check navigation-bar--icon"></i>Today's Uploads</a></li>
<li><a href=""><i class="fa fa-list-ol navigation-bar--icon"></i>Top 100</a></li>
<li><a href=""><i class="fa fa-store navigation-bar--icon"></i>Store</a></li>
<li><a href=""><i class="fas fa-th-list navigation-bar--icon"></i>My List</a></li>
<li><a href=""><i class="fas fa-user-cog navigation-bar--icon"></i>User Control Panel</a></li>

</ul>
</nav> <!-- Navigation Bar -->


<div class="menu-toggle">
<div class="hamburger"></div>
</div>

</div><!-- Header Container -->

</header>


<body>


<div class="container new-releseas">
<div class="cover"></div>
<div class="cover"></div>
<div class="cover"></div>
<div class="cover"></div>
</div><!-- New Releseas -->

<div class="container must-reads">

</div><!-- Must Reads -->

<div class="container current-series">

</div><!-- Current Series -->

<div class="footer-container">

</div><!-- Footer Container -->



<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="script.js"></script>


</body>
</html>

最佳答案

检查新的 Codepen 链接,我已经修复了 position 问题 https://codepen.io/nelh/pen/ejOPwE?editors=1100

关于javascript - 如何从静态导航栏转到位置 :fixed without screwing everything?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51250561/

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