gpt4 book ai didi

html - 为非滚动创建固定位置会弄乱页面上的 div 位置

转载 作者:可可西里 更新时间:2023-11-01 14:59:50 33 4
gpt4 key购买 nike

你好,我遇到了一个问题,当我让我的顶部区域不可滚动时,该区域几乎完全消失了。

Before Fixed Picture

标题html

<section id="header">
<div class="container">
<ul class="top-nav">
<li>
<a href="#" class="choose-language" data-toggle="popover" id="languageChooser" data-original-title="" title="">
English
<b class="caret"></b>
</a>
<div id="languageChooserContent" class="hidden">
<ul>
<li>
<a href="/index.php?language=arabic">العربية</a>
</li>
<li>
<a href="/index.php?language=azerbaijani">Azerbaijani</a>
</li>
<li>
<a href="/index.php?language=catalan">Català</a>
</li>
<li>
<a href="/index.php?language=chinese">中文</a>
</li>
<li>
<a href="/index.php?language=croatian">Hrvatski</a>
</li>
<li>
<a href="/index.php?language=czech">Čeština</a>
</li>
<li>
<a href="/index.php?language=danish">Dansk</a>
</li>
<li>
<a href="/index.php?language=dutch">Nederlands</a>
</li>
<li>
<a href="/index.php?language=english">English</a>
</li>
<li>
<a href="/index.php?language=estonian">Estonian</a>
</li>
<li>
<a href="/index.php?language=farsi">Persian</a>
</li>
<li>
<a href="/index.php?language=french">Français</a>
</li>
<li>
<a href="/index.php?language=german">Deutsch</a>
</li>
<li>
<a href="/index.php?language=hebrew">עברית</a>
</li>
<li>
<a href="/index.php?language=hungarian">Magyar</a>
</li>
<li>
<a href="/index.php?language=italian">Italiano</a>
</li>
<li>
<a href="/index.php?language=macedonian">Macedonian</a>
</li>
<li>
<a href="/index.php?language=norwegian">Norwegian</a>
</li>
<li>
<a href="/index.php?language=portuguese-br">Português</a>
</li>
<li>
<a href="/index.php?language=portuguese-pt">Português</a>
</li>
<li>
<a href="/index.php?language=romanian">Română</a>
</li>
<li>
<a href="/index.php?language=russian">Русский</a>
</li>
<li>
<a href="/index.php?language=spanish">Español</a>
</li>
<li>
<a href="/index.php?language=swedish">Svenska</a>
</li>
<li>
<a href="/index.php?language=turkish">Türkçe</a>
</li>
<li>
<a href="/index.php?language=ukranian">Українська</a>
</li>
</ul>
</div>
</li>
<li>
<a href="/clientarea.php">Login</a>
</li>
<li>
<a href="/register.php">Register</a>
</li>
<li class="primary-action">
<a href="/cart.php?a=view" class="btn">
View Cart
</a>
</li>
</ul>

<a href="/index.php" class="logo"><img src="/assets/img/logo.png" alt="WebKing Web Services"></a>

</div>
</section>

导航栏的html 切换导航

        <!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="primary-nav">

<ul class="nav navbar-nav">

<li menuitemname="Home" class="" id="Primary_Navbar-Home">
<a href="/index.php">
Home
</a>
</li>
<li menuitemname="Store" class="dropdown" id="Primary_Navbar-Store">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Store
&nbsp;<b class="caret"></b> </a>
<ul class="dropdown-menu">
<li menuitemname="Browse Products Services" id="Primary_Navbar-Store-Browse_Products_Services">
<a href="/cart.php">
Browse All
</a>
</li>
<li menuitemname="Shop Divider 1" class="nav-divider" id="Primary_Navbar-Store-Shop_Divider_1">
<a href="">
-----
</a>
</li>
<li menuitemname="Select Your Perfect Plan" id="Primary_Navbar-Store-Select_Your_Perfect_Plan">
<a href="/cart.php?gid=1">
Select Your Perfect Plan
</a>
</li>
<li menuitemname="symantec" id="Primary_Navbar-Store-symantec">
<a href="/index.php?rp=/store/ssl-certificates">
SSL Certificates
</a>
</li>
<li menuitemname="Shop Divider 2" class="nav-divider" id="Primary_Navbar-Store-Shop_Divider_2">
<a href="">
-----
</a>
</li>
<li menuitemname="Register a New Domain" id="Primary_Navbar-Store-Register_a_New_Domain">
<a href="/cart.php?a=add&amp;domain=register">
Register a New Domain
</a>
</li>
<li menuitemname="Transfer a Domain to Us" id="Primary_Navbar-Store-Transfer_a_Domain_to_Us">
<a href="/cart.php?a=add&amp;domain=transfer">
Transfer Domains to Us
</a>
</li>
</ul>
</li>
<li menuitemname="Announcements" class="" id="Primary_Navbar-Announcements">
<a href="/index.php?rp=/announcements">
Announcements
</a>
</li>
<li menuitemname="Knowledgebase" class="" id="Primary_Navbar-Knowledgebase">
<a href="/index.php?rp=/knowledgebase">
Knowledgebase
</a>
</li>
<li menuitemname="Network Status" class="" id="Primary_Navbar-Network_Status">
<a href="/serverstatus.php">
Network Status
</a>
</li>
<li menuitemname="Contact Us" class="" id="Primary_Navbar-Contact_Us">
<a href="/contact.php">
Contact Us
</a>
</li>

</ul>

<ul class="nav navbar-nav navbar-right">

<li menuitemname="Account" class="dropdown" id="Secondary_Navbar-Account">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Account
&nbsp;<b class="caret"></b> </a>
<ul class="dropdown-menu">
<li menuitemname="Login" id="Secondary_Navbar-Account-Login">
<a href="/clientarea.php">
Login
</a>
</li>
<li menuitemname="Register" id="Secondary_Navbar-Account-Register">
<a href="/register.php">
Register
</a>
</li>
<li menuitemname="Divider" class="nav-divider" id="Secondary_Navbar-Account-Divider">
<a href="">
-----
</a>
</li>
<li menuitemname="Forgot Password?" id="Secondary_Navbar-Account-Forgot_Password?">
<a href="/pwreset.php">
Forgot Password?
</a>
</li>
</ul>
</li>

</ul>

</div><!-- /.navbar-collapse -->
</div>
</nav>

</section>

代码:

section#header {
margin: 0;
padding: 10px 0;
background-color: #fff;
border-radius: 5px 5px 0 0;
}

现在,当我添加固定位置并尝试使其无法控制时,白色部分和 Logo 区域不再滚动,但是在我什至开始滚动之前,我的菜单栏被向上推并超出了位置。

Picture now fixed you can see the menu bar has changed its location.这是新代码

section#header {
position: fixed;
width: 100%;
margin: 0;
padding: 10px 0;
background-color: #fff;
border-radius: 5px 5px 0 0;
}

这不是 z-index 问题,因为这是在我向下滚动页面之前发生的。

我已经被困了好几天了,如果有任何帮助,我将不胜感激。

更新:好的,我有固定的菜单,但现在每个页面都有这个问题,我不知道为什么每个 div 和部分都向上移动,就好像标题不存在一样。请注意,这是在任何滚动开始之前。请随时访问 webking.com 并导航到任何页面以了解我的意思。

As you can see a huge mess

谢谢

最佳答案

所以这是我最后的更正:

第一步修复标题:

section#header {
position: fixed; /* We want the header fixed at top */
z-index: 1000; /* We want header over other elements when scrolling */
/* margin: -5px 0 0 0; */ /* Remove seems not needed */
height: 60px; /* We should fix the header height */
width: 100%; /* header will take all available width */
background-color: #fff;
border-radius: 5px 5px 0 0;
}

第二步修复菜单:

section#main-menu {
/* margin: 60px auto 0; */ /* It is not the place for the marin-top. We don't need this */
position: fixed; /* We want the menu fixed at top */
width: 100%;
background-color: #006687;
top: 60px; /* We want menu above the header so we shift the menu of the height of the header */
z-index: 1000; /* We want menu over other elements when scrolling */
}

第三步内容更正:

在这里,我不明白为什么(也许需要更多调查)但是浏览器获取 section#main-bodymargin-top 和将其应用于标题。这不是我们想要的,它就在这里将用这个修复它:

我们将添加 margin-top 技巧并将其应用到.container 位于 section#main-body 内像这样:

section#main-body .container {
margin-top: 100px; /* header : 60 + menu : 40 */
}

关于html - 为非滚动创建固定位置会弄乱页面上的 div 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53841693/

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