Drop down leaves gap in navigation when hidden - html

I'm trying to make my current CSS navigation responsive for mobile devices.
I currently have it set up with a media query so that when the screen width falls below the specified size it changes to block form (stacked) and a menu icon appears on the right hand side of the logo (to later be made into a button).
The problem I'm currently having is that the drop down menu which is used for my second link in the navigation, is causing a gap to appear between the second and third link (as if the drop down content is taking up the space whilst hidden).
I've tried looking for solutions but can't seem to find the right answer for my particular setup. Basically, the link "How It Works" should sit right beneath "Sections" when on mobile.
http://jsfiddle.net/fc45c7p5/
<a href="#">
<img class="logo" src="images/logo.png" alt="Logo" style="width:330px;height:100px"/>
</a>
<div id="menu-icon"></div>
<br></br>
</div>
<div class="navbar">
<ul class="navbar cf">
<li>HOME</li>
<li>SECTIONS
<ul>
<li>RETAIL</li>
<li>HOTEL</li>
<li>RESTAURANT</li>
<li>SHOPPING</li>
</ul>
<li>HOW IT WORKS</li>
<li>OUR EXPERIENCE</li>
<li>TESTIMONIALS</li>
<li>NEWS</li>
<li>CONTACT US</li>
</ul>
</div>
Don't take too much note of the media query max-width of 1008px, I'm aware this isn't standard mobile size, it's just temporary whilst I get it working first.
Any help regarding this is really appreciated.

visibility keeps your elements there without displaying them. You should use display:none when you do not want show the space the hidden element takes. Use display:block to show them again. Add some CSS transitions to the height of the a elements to make the reveal somewhat smoother.
Here : http://jsfiddle.net/6eshy7n2/

Add the following.
ul.navbar ul li { float: none; width: 100%; display:none;}
ul.navbar li:hover > ul li{display: block;}
You have to make the lis inside the uls actually not display when the parent li is not being hovered. When it is hovered you then change the display value to block to make it visible.

Related

How can I move my navigation links from top of the page to the bottom

I basically want to keep the nav with all of its contents at the top of the HTML, but have it moved to the bottom of the page with CSS as I am doing mobile-first approach and want the navigation to appear at the top when I resize it to tablet or laptop. I tried using minus with bottom tag but it takes forever to get it to the bottom and does not seem to be the most efficient way to do it. Is the only way to move the context to the bottom of the page is to put it at the bottom of HTML file or is there a completely different way I should approach this?
This is what I have at the moment:
I want to move the underlined links to the bottom, my code:
#topnavigationmenu li {
display: inline-block;
list-style-type: none;
font-size: 3rem;
padding: 10px;
}
<div id="mainpage">
<nav id="topnavigationmenu">
<ul>
<li> example </li>
<li> example </li>
<li> example </li>
</ul>
</nav>
The easiest solution: You can create two instances of <nav> and show one on mobile and on desktop using media queries.
Possibly better solution: You can use Flexbox (and even CSS Grid I guess) to change the order, so let's say inside the mainpage div you have two sections the nav and a div with your page content:
<nav id="topnavigationmenu">
<ul>
<li> example </li>
<li> example </li>
<li> example </li>
</ul>
</nav>
<div class="page-content">
<!-- Content here -->
</div>
You can add display:flex; to mainpage and manipulate the order these appear on mobile vs desktop/tablet using media queries.
I'd suggest checking these articles out:
Ordering Flex Items
A Complete guide to Flexbox

My nav will not display as inline block

I'm working on a project(using bootstrap) and I can't seem to figure out why my nav is still stacked up instead of being laid out horizontally. I've tried just about everything I can think of and even sought help online where I'm learning to code but they couldn't figure it out either. They told me it should be working and in fact it does work in their code editor, it just doesn't work on my computer which is where the files are located since I don't have web hosting and I'm just learning. I also noticed that in my browser the nav pull-right works and the links are on the right hand side(although they're still not horizontal) but when I ran it through here where it says "run code snippet" the nav appears right underneath the img placeholder, don't know if that means anything but I thought I'd include that bit of information.
header nav ul{
display: inline-block;
}
<header>
<div class="container">
<div class="row">
<img id="logo" src="http://placehold.it/150x150">
<nav>
<ul class="nav pull-right">
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</header>
enter image description here
Do you mean you want to make the navigation to align horizontally?
Then you can try using this
header nav ul li {
display: inline-block;
}
working example here.
The reason your method doesn't work is because you apply to ul instead of the li element.

Items in drop down are not clickable

I did some searches on the matter but seem to receiving mixed answers and I'm not entirely sure how to go about this given my limited coding knowledge.
I downloaded a website template called Brushed by Alessio Atzeni (mentioned for easier reference). The template is fantastic but unfortunately it does not come with dropdown functionality so I looked up a couple of tutorials and have managed to create my own.
<div class="sticky-nav">
<a id="mobile-nav" class="menu-nav" href="#menu-nav"></a>
<div id="logo">
<a id="goUp" href="#home-slider" title="rando"></a>
</div>
<nav id="menu">
<ul id="menu-nav">
<li class="current">Home</li>
<li>Intro</li>
<li class="dropdown">Our Services
<ul id="menu-nav-dropdown">
<li>Social Media</li>
<li>Graphic Design</li>
<li>Development</li>
</ul>
</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
This is the HTML for index.html for the navbar, when I hover over "services" the dropdown appears and each individual element highlights as a result of me hovering but when I click it nothing happens. However, if I right click and "open in new tab" that proper page is generated.
I chose not to include the CSS to prevent cluttering the post, but if you need any other information I'll gladly provide it as soon as possible. Does anyone know what the issue might be? Thank you in advance.
EDIT: here is the http://jsfiddle.net/tuvon83p/1/ it doesn't look good at all but I believe the functionality is there and working properly (you just need to hover over to the right to see the links because there isn't a background).
Try
nav ul li ul li a{
position: relative;
top:0;
left: 0;
z-index: 999;
display: block;
}
basically: In the navigation, locate all ul, locate all li, locate all ul, locate all li, and select the a and it should go to the unclickable and put it above all things. There may be something above it?

How to create horizontal sub-menu that positions between parent and logo

Looking for help in creating a navigation menu, where the navigation bar sits above a site logo. I want the sub-menu to expand out of the navigation bar horizontally and position itself between the parent navigation bar and the logo.
The sub-menu is horizontal
The logo is below the navigation bar when collapsed
The sub-menu will expand out of the navigation bar and push down the position of the logo.
Main navigation:
<nav>
<div class="container">
<ul class="menu">
<li> One
<ul class="sub-menu">
<li>Sub Menu One
</li>
<li>Sub Menu Two
</li>
<li>Sub Menu Three
</li>
<li>Sub Menu Four
</li>
<li>Sub Menu Five
</li>
</ul>
</li>
<li> Two
</li>
<li> Three
</li>
<li> Four
</li>
<li> Five
</li>
</ul>
</div>
</div>
</nav>
<div class="logo"></div>
I have made a mock example here: http://jsfiddle.net/GSfpj/11/ including the CSS I've been playing with.
Instead of the sub-menu expanding underneath the logo, I would like to be able to push the logo downwards and position the sub-menu in between both parent navigation and logo.
I would prefer to do this in pure CSS if possible, any help would be greatly appreciated :)
You could perhaps do something like this:
ul:hover {padding-bottom:25px;}
... although, to be honest, I don't think the behavior is vary nice anyway. Why not have the sub menu appear over the top of the logo?
Here's a working example: http://jsfiddle.net/GSfpj/27/
There are a few things I don't like about this, though:
Because the sub-menus need to be taken out of the DOM layout to make the main menu display properly, you need to set them to position: absolute. Because of this, you are forced to specify heights, which makes things a bit sloppy and hard to reuse.
If you make the <li>s position:relative, you end up with extra space before the sub-menu. If you instead position the sub-menu relative to the parent <ul>, the sub-menu might not even overlap its parent <li>, which also brings about issues with the :hover state.
Because the layout is not done dynamically (you need to explicitly specify heights and padding), you end up with blank space when you hover over a menu item without a submenu.
There really isn't much you can do to get around these issues without getting into javascript or different markup (add classes to represent whether something has a sub-menu or not, etc.)
It works, though, so take it as you will.
Here is your updated feddle link. You have to change the following css:
ul.menu li {
display:inline;
padding:10px;
position:relative;
z-index:9999;
}
ul.menu li ul.sub-menu {
position:absolute;
margin:0;
padding:0;
background:#2f2f2f;
width:300px;
}

Why is my navigation bar jumbled up when the screen is tight? Also why do my headers interfere with it?

Here is the jsfiddle for it http://jsfiddle.net/8PcxE/
<div id="container">
<div id="header">
<div id="nav-container">
<ul id ="nav-list">
<li id=nav-title>lymbo</li>
<li>Playmaps</li>
<li>Map</li>
<li>About</li>
<li>My Account</li>
<li>Log Out</li>
</ul>
</div>
</div>
It is fine on a wider page, but when I run it on a small page everything is cramped and the options get pushed together making a zipper-like pattern.
My other problem is when I type something in my headers or paragraphs it will be at the top and intersecting with my navigation bar making it look like a mess.
My goal is to make a sort of "gradient" looking navigation bar hence the shadows. But that also doesn't seem to look right. If someone can give me some input on that, it would be much appreciated.
I found that after I changed my nav-container CSS to position: relative from position: fixed it works out. Are there any negative effects of doing this?
Since you've changed all the <li> to inline, the simplest solution would be to prevent wrapping on the <ul>:
#nav-list {
white-space: nowrap;
/* ... */
}
http://jsfiddle.net/mblase75/Lt72p/