简体   繁体   English

HTML CSS Javascript汉堡菜单问题

[英]HTML CSS Javascript Hamburger Menu problem

would someone mind looking at a website please? 有人介意浏览一个网站吗? The address is test.dvps.uk/index.html 地址是test.dvps.uk/index.html

I'm having issues with the Hamburger Menu, its in a 50% column and I want it right aligned. 我在“汉堡菜单”中遇到了问题,该菜单位于50%的列中,我希望它正确对齐。 I've tried align content, floating and different position and displays but can seem to get it right. 我试过对齐内容,浮动和不同的位置和显示,但似乎可以正确处理。 The other problem i'm having is that when the menu is toggled, it expands but pushes the content down of the container below but I want it to move the container too. 我遇到的另一个问题是,当菜单切换时,菜单会展开,但会将内容推到下面的容器中,但我也希望它也移动容器。

I'm sure that my tinkering to align the menu has caused this issue, so before I break it any further would you mind helping, please? 我确定我修改菜单的方式引起了此问题,所以在我进一步解决该问题之前,您想帮忙吗? Thank you :) 谢谢 :)

 $(document).ready(function() { $(".hamburger").click(function() { $(".nav").slideToggle("slow"); }); }); 
 *, *:before, *:after { box-sizing: inherit; } * { margin: 0; padding: 0; border: none; } html { box-sizing: border-box; } body { font-family: "Arial"; font-size: 1.2em; } .container { margin: 0 auto; padding-top: 10px; max-width: 1000px; } .container-bottom-pad { margin: 0 auto; padding-top: 10px; max-width: 1000px; padding-bottom: 80px; } .outerContainer { background-color: #F1F1F1; } .row::before, .row::after { display: table; content: " "; clear: both; } .row { padding: 10px 0; } .one, .one-third, .two-thirds, .one-fourth { width: 100%; } #headerAndNav { background-color: rgba(135, 196, 66, 0.60); margin-bottom: 10px; } header img { z-index: -2; position: absolute; width: 20%; margin: 0 auto; } .header-logo { position: relative; height: 100px; width: auto; } .nav { display: none; padding: 0; overflow: hidden; /* Makes the sliding animation cleaner */ } .nav-item { list-style-type: none; text-align: center; background: #87c442; display: block; margin: 12px 0; padding: 10px 20px; border-radius: 5px; box-shadow: 0px 6px #2c3e50; } .nav-link { text-decoration: none; color: #333; } .nav-item:active { box-shadow: none; transform: translate(0px, 6px); transition: transform .20s; } .hamburger span { display: block; width: 35px; height: 4px; background: #625948; margin: 5px 0px; padding: 0; } .hamburger:hover span { transition: background ease-in-out .25s; background: #87c442; } .hamburger:hover { cursor: pointer; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="container" id="headerAndNav"> <div class="row"> <header> <div class="eleven-twelths column"> <nav> <span class="flex-container"> <div class="align"> <div class="hamburger"> <span></span> <span></span> <span></span> </div> <ul class="nav"> <li class="nav-item"> <a class="nav-link" href="index.html">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="login.html">Login</a> </li> <li class="nav-item"> <a class="nav-link" href="signup.html">Signup</a> </li> <li class="nav-item"> <a class="nav-link" href="successes.html">Successes</a> </li> <li class="nav-item"> <a class="nav-link" href="prices.html">Prices</a> </li> <li class="nav-item"> <a class="nav-link" href="about.html">About</a> </li> <li class="nav-item"> <a class="nav-link" href="contact.html">Contact</a> </li> </ul> </div> </span> </nav> </div> <div class="one-twelth column"> <img alt="logo" class="header-logo" src="images/site/opaque-logo.png"> </div> <!-- end of one-twelth--> </div> <!-- end of row --> </header> </div> <!-- end of container --> 

Well, if you want a brute force solution, just do this in the CSS file: 好吧,如果您需要强力解决方案,只需在CSS文件中执行此操作:

.hamburger { position:fixed; top: 25px; right: 30px; }

This will take the hamburger div out from the document flow and it will always stick to the given position. 这会将汉堡包div从文档流中移出,并且将始终固定在给定位置。

I see a couple other issues arising on the horizon, but keep going. 我看到即将出现其他一些问题,但请继续。

And take the whole align div out of the HTML. 并将整个align div从HTML中删除。

After looking the adress you mention (test.dvps.uk/index.html) and following your questions: 查看地址后,您提到(test.dvps.uk/index.html)并关注您的问题:

1) " ... the Hamburger Menu, its in a 50% column and I want it right aligned ... " 1) ...汉堡菜单,在50%的列中,我希望它正确对齐...

The problems it's related to the div with class flex-container and the next div with class align (and note you have two definitions of class align : one floating right and the other floating left!) 它的问题与具有flex-container类的div和具有align类的下一个div有关(请注意,您有align类的两个定义:一个向右浮动,另一个向左浮动!)

2) ...pushes the content down of the container below but I want it to move the container too... 2) ...将内容放入下面的容器中,但我也希望它也移动容器...

You can try with clear: right in the container after the menu. 您可以尝试使用clear:菜单之后的容器中。

Also you must note some properties in your file custom.css are misspelled (ie bot instead bottom ). 另外,您还必须注意文件custom.css中的某些属性拼写错误(即bot而不是bottom )。 Check it out this too. 也检查一下。

I hope this help. 希望对您有所帮助。

Saludos! Saludos!

1) The alignment, as noted by others, is due to the flex container. 1)如其他人所述,对齐是由于flex容器引起的。 Add: 加:

justify-content: flex-end to right align. justify-content: flex-end右对齐。

2) The toggled menu pushing the content down is due to the DOM being changed (think of it as an element that goes from 0px width/height to 100px width/height). 2)向下切换内容的切换菜单归因于DOM的更改(将其视为从0px宽度/高度到100px宽度/高度的元素)。 The easiest fix is to take the element out of the DOM flow. 最简单的解决方法是将元素移出DOM流。 One way is using position . 一种方法是使用position So, an example: 举个例子:

position: absolute; right: 0; z-index: 1 position: absolute; right: 0; z-index: 1 to ul.nav position: absolute; right: 0; z-index: 1ul.nav

Your hamburger should now be right aligned, and the hamburger content should not interfere/push down the other content. 现在,您的汉堡包应正确对齐,并且汉堡包内容不应干扰/压下其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM