I am added three items to my navigation menu. It added soem css to get it to fall in line. But it keeps pushing up my serviices title. I have tried many different ways to try to solve the problem. Here is a copy of my code.
//HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!------------------------------ css stylesheets -------------------------------------->
<link rel='stylesheet' href='css/utilities.css' />
<link rel='stylesheet' media='screen and (min-width: 0px) and (max-width: 480px)' href='css/mobile.css' />
<link rel='stylesheet' media='screen and (min-width: 481px) and (max-width: 768px)' href='css/tablet.css' />
<link rel='stylesheet' media='screen and (min-width: 769px) and (max-width: 1279px)' href='css/landscape.css' />
<link rel='stylesheet' media='screen and (min-width: 1280px) ' href='css/large.css' />
</head>
<body>
<header>
<!---------------------- MAIN NAVIGATION START -->
<div class="container">
<a href="#" class="nav-branding">DEV.</a>
<nav class="navbar">
<ul class="nav-menu">
<li class="nav-item">
<a href="#" class="nav-link">Home</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">About</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Services</a>
<ul class="dropdown">
<li><a href="#">Service 1</a></li>
<li><a href="#">Service 2</a></li>
<li><a href="#">Service 3</a></li>
</ul>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Contact</a>
</li>
</ul>
<div class="hamburger">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
</nav>
</div>
<!-------------------------MAIN NAVIGATION END -->
</header>
<main>
</main>
<footer>
<div class="footer-box box-1">
<h2>About Us</h2>
<p>We are a company that specializes in providing high-quality products and services. We are committed to providing our customers with the best possible experience.</p>
</div>
<div class="footer-box box-2">
<h2>Contact Us</h2>
<p>If you have any questions or concerns, please feel free to contact us. We would be happy to hear from you.</p>
</div>
<div class="footer-box box-3">
<h2>Social Media</h2>
<p>Follow us on social media to stay up-to-date on our latest products and services.</p>
</div>
<div class="footer-box box-4">
<h2>Copyright</h2>
<p>All rights reserved. Copyright 2023.</p>
</div>
</footer>
<script src="script.js"></script>
</body>
</html>
I am getting a issues with the the landscape version. The first was a to much margin between the li item when it dropped down. I found how to fix that.The second is that when I toggle the menu down the shows. But my logo diappaers. any suggestion on hoe to toggle doen the menu and keep the logo
@lancechise: please format your code so it will display correctly. I’ve edited your last two posts for you, but in future please use the </> button in the editor window, or place three backticks ``` on a line above your code, and three on a line below.
You need a higher z-index on the nav-branding if you want it to stay on top of the fixed menu.
.nav-branding{
position:relative;
z-index:2;
}
[Off Topic]
Note that a more efficient way to do media queries is only to style the differences. You are repeating whole blocks of code where 90% of it will be the same as before.
You are repeating that twice already and there is much more code like that.
The way I work is to start at desktop first (because its easier for me but it can be done in reverse just the same). So for desktop styles there would be no media query and the whole page styled without a media query in sight.
Then I will close the browser window smaller until the design looks awkward or something breaks or I need to go from 3 columns to one (or whatever) and then at that point only I will create a media query to make it fit nicely.
e.g.
@ media screen and (max-width:980px){
/* a few well chose n styles go here */
}
No need to mix min and max-width at the same time as that is too awkward to maintain in the long run and prone to error.
Once I’ve fixed the design at that point I will keep closing the browser window until it breaks again or looks awkward and then create another media query at that point. … and so on …
If you have a fluid site and a few well chosen media queries then with this method you cope for every device ever invented now or in the future without knowing anything about them. There are no set sizes for tablets and phones these days so you need a design-centric approach where the design dictates the breakpoints and not some imaginary device.
In the end you end up with much more precise (and less) code and with code that suits the design in hand.
So I got the logo to show. But now the services when you click on the services. It just goes over the contact instead of pushing it down. Any ideas whats causing that ?
I don’t think you posted the correct code above as that’s for the larger screen?
Taking what you posted so far and the html you posted I’ve put it into a codepen just to see where we are.
If I understand correctly you are making the nav vertical at this breakpoint and therefore you can no longer absolutely place it if you want it to take up space in the flow.
I changed the dropdown position to relative. It is falling to to position. But with a big black space . You said there were some other things off. Please share . I’ll try them out to see how it works . here is my code for landscape view as of now.
As the menu is now in the flow it can’t be animated like before because it has to be hidden by using a zero height and then changing to auto height when revealed. In Css you cannot animate to auto. You can animate other things such as the opacity but not the height, There are other methods but I don’t want to go there if its not necessary.
I assume you are toggling the left-100% value with JS as I could see no classes in the CSS. You would be better getting js to simplay add and remove a css class (such as open) and then use that class in the css to move the menu into view. Its best to separate the behaviour of js and not start styling things directly through js unless its some sort of continuous dynamic effect.
When you use absolute or fixed positioning you need to specify the top and left co-ordinates at least otherwise it just becomes absolute at the point it occupies in the document which may not be the top as in your fixed menu example.