I'm asking on here because I'm thoroughly fed up of trying to resolve this myself and getting absolutely nowhere. The only solution I've found so far is to remove the border itself but it's probably best to explain the problem first...
So I'm building a navigation bar for a website and I've done absolutely dozens of these, re-used the same code across multiple projects because... it's a navigation bar! It's incredibly simple, the only difference is that I have an extra nested navigation sub-category. However this occurs regardless whether or not that sub-category exists. When I've built it, it looked absolutely fine but I noticed that there was a small white gap between the elements inside the menu element between them and the border. This gap is incredibly inconsistent however - in the small JS fiddle screen on my old monitor it doesn't appear at all but move it onto my laptop widescreen display and the gaps appear.
I've checked all of my CSS and code, nothing is amiss compared to my other websites and according to Chrome's Computed tab, there isn't actually a gap there at all. There's nothing but the border?! How does it appear then when the Computed tab tells me it's not there? Am I losing my mind?
Regardless, I've posted a JSFiddle to try and get some input on this. I'm using SCSS compiled by Scout App and it appears to only happen on Chrome as far as I can see. Anybody got any ideas?
*,
body {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: auto;
background-color: #D0E9FD;
}
body {
color: #1D1E2C;
font-size: 18px;
font-family: "Kodchasan", sans-serif;
}
a {
text-decoration: underline;
color: #713031;
}
img {
max-width: 100%;
}
h1,
h2,
h3,
h4,
h5 {
color: #2AA6A6;
}
h1 {
font-size: 32px;
margin-top: 10px;
}
h2 {
font-size: 28px;
}
hr {
border: 4px solid #2AA6A6;
}
input,
textarea,
select {
border: 2px solid #2AA6A6;
padding: 10px;
color: #991B1D;
}
input:focus,
textarea:focus,
select:focus {
outline: none;
border: 2px solid #991B1D;
}
input:disabled,
textarea:disabled,
select:disabled {
background-color: #d9f6f6;
border-color: #d9f6f6;
text-align: center;
-webkit-appearance: none;
-moz-appearance: none;
font-family: "Kodchasan", sans-serif;
font-size: 18px;
opacity: 1;
}
input:disabled:-ms-expand,
textarea:disabled:-ms-expand,
select:disabled:-ms-expand {
display: none;
}
form {
border: 2px solid #2AA6A6;
padding: 10px;
}
form input,
form textarea,
form label {
margin-bottom: 10px;
width: 49%;
display: inline-block;
}
form input,
form textarea {
border: 2px solid #2AA6A6;
padding: 10px;
color: #991B1D;
}
form input:focus,
form textarea:focus {
outline: none;
border: 2px solid #991B1D;
}
form input[type="submit"] {
width: 100%;
margin: 0;
}
form button {
background-color: #2AA6A6;
color: #FFFFFF;
border: 2px solid #2AA6A6;
}
form a {
width: 90%;
display: block;
text-align: center;
}
form>p {
width: 50%;
display: block;
margin: 0 auto;
text-align: center;
}
#navigation {
padding: 2px 0;
background-color: #2AA6A6;
}
#navigation ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#navigation li a {
display: block;
color: #FFFFFF;
font-weight: 700;
font-size: 24px;
text-decoration: none;
width: 100%;
padding: 15px;
}
#navigation li.parent-cat ul {
background-color: #FFFFFF;
margin: 10px 0;
margin-left: 20px;
}
#navigation li.parent-cat ul a {
color: #713031;
}
#navigation li ul {
background-color: #FFFFFF;
margin: 10px 0;
margin-left: 20px;
}
#navigation li ul a {
color: #713031;
}
#navigation #nav {
display: none;
border-top: 5px solid #FFFFFF;
}
#navigation #menu {
display: block;
text-align: center;
background-color: #2AA6A6;
cursor: pointer;
padding: 10px 0;
font-size: 24px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
color: #FFFFFF;
}
#navigation #menu.open {
background-color: #713031;
color: #FFFFFF;
}
#navigation li {
display: inline-block;
}
#navigation li a {
font-size: 18px;
padding: 20px 30px;
}
#navigation li a:hover {
background-color: #FFFFFF;
color: #2AA6A6;
}
#navigation li.parent-cat {
position: relative;
}
#navigation li.parent-cat:hover a {
background-color: #FFFFFF;
color: #2AA6A6;
}
#navigation li.parent-cat:hover ul {
display: block;
position: absolute;
width: 100%;
margin-top: 0;
z-index: 99;
margin-left: 0;
border: 2px solid #713031;
margin-bottom: 0;
}
#navigation li.parent-cat:hover ul li {
width: 100%;
}
#navigation li.parent-cat:hover ul a:hover {
background-color: #713031;
color: #FFFFFF;
}
#navigation li.parent-cat:hover .parent-cat:hover ul {
display: block;
margin-left: 100%;
margin-top: -32%;
}
#navigation li.parent-cat:hover .parent-cat ul {
display: none;
}
#navigation li.parent-cat ul {
display: none;
}
#navigation #menu {
display: none;
}
#navigation #nav {
display: block;
border: none;
}
/* EOS */
<div id="navigation">
<ul id="nav">
<li id="one"><span>Home</span></li>
<li id="two" class="parent-cat"><span>Our Workshop</span> <i class="fas fa-level-down-alt"></i>
<ul>
<li id="three"><span>Our Solutions</span></li>
<li id="four" class="parent-cat">
<span>Our Products</span> <i class="fas fa-level-down-alt"></i>
<ul>
<li id="five"><span>Lighting Components</span></li>
<li id="six"><span>Motorcycle Parts</span></li>
<li id="seven"><span>RC Buggy Parts</span></li>
</ul>
</li>
</ul>
</li>
<li id="five"><span>Careers</span></li>
<li id="six"><span>Latest News</span></li>
<li id="seven"><span>Contact Us</span></li>
</ul>
<a id="menu"><i class="fas fa-bars"></i></a>
</div>
Related
updated issue!! I would like my navigation bar to have a drop down effect when hovering over it. I have tried the different methods suggested and my list was hidden behind my section following. So after changing it incorrectly so many time, I have now gotten confused. This is how it is currently. Now the dropdown list is stuck on display. I just want the list to show when hovering. Also the search box is supposed to be on the same line as the nav links but it has now moved below. I can figure out how to fix that if someone can help me with the drop down menu, please.
.navbar {
background: linear-gradient(#9E0A0C,#EBEBEB);
padding: 10px;
border-top: solid 1px #000000;
}
.navbar a{
text-decoration: none;
color: #ffffff;
font-weight: bold;
font-size: 1.5vw;
text-transform: uppercase;
padding: 3px 5px;
margin: auto;
display: inline;
}
.navbar ul {
padding: 0;
margin-top: 0;
width: auto;
}
.navbar ul:after {
content: "";
display: table;
clear: both;
}
.navbar li{
border-left: solid 2px #000000;
list-style-type: none;
display: inline;
width: 800px;
padding: 0;
/*position: relative;*/
}
/*li a {
display: block;
color: white;
text-align: center;
padding: 5px 94px;
text-decoration: none;
}*/
.navbar a:active {
background-color: #000000;
}
.navbar a:hover {
background-color: #ddd;
color: black;
font-size: 1.5vw;
}
li:first-child {
border-left: none;
}
.dropdown {
display: none;
position: relative;
overflow: hidden;
}
.list {
display:none;
/*opacity: 0;
visibility: hidden;*/
z-index: 100;
min-width: 50px;
max-width: 350px;
box-shadow: 0 8px 16px 0 #e7e7e7;
background: #050243;
position: absolute;
left: 0;
top: 100%;
/*transition: 0.3s ease-in-out;*/
}
.list a {
color: #000000;
font-size: 1.25vw;
text-decoration: none;
display: block;
text-align: left;
background: #dddddd;
column-count: 2;
}
.list a:hover {
background-color: #EEEEEE;
font-size: 1.25vw;
}
.dropdown:hover, .list {
display: block;
/*position: absolute;
left: 0;*/
}
<nav class="navbar">
<ul>
<li>Home</li>
<li class="dropdown">Our Lodge
<div class="list"> NEWS FACILITIES OFFICERS GUEST BOOK </div>
</li>
<li class="dropdown">Events
<div class="list"> CALENDAR BINGO </div>
</li>
<li class="dropdown">Contact Us
<div class="list"> WHO ARE WE? </div>
<div class="list"> BECOME AN ELK </div>
</li>
</ul><form action="search.html">
<input class="search" type="text" placeholder="Search.." name="search">
</form>
</nav>
within your css the line .dropdown:hover, .list { should be .dropdown:hover .list { without the comma
put your form into an <li> element within the <ul>. the float: right should be assigned to the form not the input
html:
...
</li>
<li>
<form class="navbar-search" action="search.html">
<input class="search" type="text" placeholder="Search.." name="search">
</form>
</li>
</ul>
</nav>
css:
.navbar-search {
float: right;
}
update:
I don't know why you would like to have a column-count. is this on purpose?
in the last <li>element are two divs -> one overlays the other
please do you self a favour and reduce the amount of whitspaces as well as putting one html element per line and use comments (html AND css)! this makes debugging a whole lot easier and you will still understand what you did yesterday.
update 2:
.navbar {
background: linear-gradient(#9E0A0C, #EBEBEB);
padding: 10px;
border-top: solid 1px #000000;
}
.navbar a {
text-decoration: none;
color: #ffffff;
font-weight: bold;
font-size: 1.5vw;
text-transform: uppercase;
padding: 3px 5px;
margin: auto;
display: inline;
}
.navbar ul {
padding: 0;
margin-top: 0;
width: auto;
}
.navbar ul:after {
content: "";
display: table;
clear: both;
}
.navbar li {
border-left: solid 2px #000000;
list-style-type: none;
display: inline;
width: 800px;
padding: 0;
/*position: relative;*/
}
/*li a {
display: block;
color: white;
text-align: center;
padding: 5px 94px;
text-decoration: none;
}*/
.navbar a:active {
background-color: #000000;
}
.navbar a:hover {
background-color: #ddd;
color: black;
font-size: 1.5vw;
}
li:first-child {
border-left: none;
}
.dropdown {
display: none;
position: relative;
overflow: hidden;
}
.list {
display: none;
z-index: 100;
min-width: 50px;
max-width: 350px;
box-shadow: 0 8px 16px 0 #e7e7e7;
background: #050243;
position: absolute;
left: 0;
top: 100%;
}
.list a {
color: #000000;
font-size: 1.25vw;
text-decoration: none;
display: block;
text-align: left;
background: #dddddd;
}
.list a:hover {
background-color: #EEEEEE;
font-size: 1.25vw;
}
.dropdown:hover .list {
display: block;
}
.navbar-search {
float: right;
}
<nav class="navbar">
<ul>
<li>Home</li>
<li class="dropdown">Our Lodge
<div class="list">
NEWS
FACILITIES
OFFICERS
GUEST BOOK
</div>
</li>
<li class="dropdown">Events
<div class="list">
CALENDAR
BINGO
</div>
</li>
<li class="dropdown">Contact Us
<div class="list">
WHO ARE WE?
BECOME AN ELK
</div>
</li>
<li>
<form class="navbar-search"action="search.html">
<input class="search" type="text" placeholder="Search.." name="search">
</form>
</li>
</ul>
</nav>
.LinkBar {
cursor: pointer;
width: 140px;
height: 37px;
border: 1px solid #c02c3a;
margin-top: 50px;
margin-left: 300px;
background-color: #c02c3a;
text-align: center;
padding-top: 9px;
color: white;
}
div.SampleMenu ul {
list-style-type: none;
width: 140px;
background-color: Grey;
margin-left: 300.5px;
padding: 0;
margin-top: 2px;
}
div.SampleMenu ul li {
color: White;
padding: 0;
display: none;
}
div.SampleMenu ul li a {
color: white;
display: block;
padding: 10px;
font-size: large;
text-align: center;
}
#HeaderBar:hover+.SampleMenu ul li {
display: block;
}
<div class="CentralHeader">
<div class="LinkBar" id="HeaderBar">All</div>
<div class="SampleMenu">
<ul>
<li>Movies</li>
<li>Events</li>
<li>Sports</li>
<li>Plays</li>
</ul>
</div>
</div>
In the above segment,I try to manipulate a user-drop down while an element
is hovered,but the drop down disappears as the cursor is moved towards
drop down. I want to select an item in drop down which needs drop down to
appear even on moving cursor from the specified element.How can I achieve
this?
Because you have applied display:block code to #HeaderBar hover and when your cursor goes to dropdown the hover code does not run.
So apply display:block on .SampleMenu ul:hover as well
#HeaderBar:hover+.SampleMenu ul,
.SampleMenu ul:hover {
display: block;
}
And also apply display:none to the .SampleMenu ul not each li elements of it.
Stack Snippet
.LinkBar {
cursor: pointer;
width: 140px;
height: 37px;
border: 1px solid #c02c3a;
margin-top: 50px;
margin-left: 300px;
background-color: #c02c3a;
text-align: center;
padding-top: 9px;
color: white;
}
div.SampleMenu ul {
list-style-type: none;
width: 140px;
background-color: Grey;
margin-left: 300.5px;
padding: 0;
margin-top: 0px;
display: none;
border-top: 2px solid #fff;
}
div.SampleMenu ul li {
color: White;
padding: 0;
}
div.SampleMenu ul li a {
color: white;
display: block;
padding: 10px;
font-size: large;
text-align: center;
}
#HeaderBar:hover+.SampleMenu ul,
.SampleMenu ul:hover {
display: block;
}
<div class="CentralHeader">
<div class="LinkBar" id="HeaderBar">All</div>
<div class="SampleMenu">
<ul>
<li>Movies</li>
<li>Events</li>
<li>Sports</li>
<li>Plays</li>
</ul>
</div>
</div>
I have been sitting for 4 hours now trying to make my nav display dropdown-links vetically but it continues to show them horizontally instead. I can´t figure out why this is happening or how to fix it.
I would appreciate it very much if some kind soul could tell me what I am doing wrong. I have a sneaking suspecion this is caused due to my settings for the nav (it changes size at a certain width) but I am not sure...
I have ripped my nav from my website and thrown everything into codepen, but even after several attempts to figure out where the problem starts - nothing! It displays "link1" right below and then just adds "link2" and "link3" to the right of it, instead of under
Please help?
Codepen: https://codepen.io/Pinchofginger/pen/BJJQgZ
If there are any oddities in the CSS it´s because I have a dropdown menu for mobile that display when you press an icon... it is not currently working either, but that a question for another time.
My HTML
<header class="mainheader">
<section id="baggrund">
<div id="mainlogo">
Sønderborg
<p> og omegns</p> Kattelaug<br />
<img class="vector" src="billeder/udklip.png" alt="Kattesilhuet"></div>
<nav>
<input type="checkbox" id="menu-checkbox" role="button" />
<label for="menu-checkbox" id="menu-button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</label>
<div id="nav_wrap">
<ul id="menu">
<li>Forside</li>
<li>Adopter en kat</li>
<li>Tilløber katte</li>
<li> Kattens pleje</li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">
Kontakt</a><div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul></div>
</nav>
</section>
</header>
MY CSS
/* small nav */
#media screen and (max-width: 61em) {
#menu li {
width: 20%;
}
#menu li a {
font-size: 0.9em;
width:100%;
color:red;}
#menu ul {width:100%;}
/*sidebar*/
body#index .sidemenu .sidebar1 {padding: 0 0 0 0;}
body#index #Mega {width: 96%; height:80px;}
body#index .sidemenu .sidebar1 h3 {font-size: 0.9em;}
}
/* stor nav*/
#media screen and (min-width: 61em) {
#menu li {
width: 20%;
}
#menu li a {
font-size: 1.2em;
width:100%;
color: #505050;
}} /*slut, stor*/
#menu li {
display: inline-block;
background: none;
padding: 5px 5px 5px 5px;
}
#menu li a {
text-transform: uppercase;
transition: all .5s ease;
text-decoration: none;
text-align: center;
line-height: 55px;
display: inline-block;}
.sidemenu .pleje {font-size: 0.9em; display:inline-block }
.sidemenu .pleje h3 {color: orange;}
#mainlogo {
display: block;
}
.mainheader {
width: 100%;
}
#bannerkat { display: none;}
#menu-button { display: none;}
#menu {
display: block;
border-radius: 0;
text-align: center;
position: relative;
}
/* Navigations menuen (links osv) */
#nav_wrap {
background: #f9f4ea;
width: 100%;
white-space: nowrap;
float: left;
height: 60px;
position: relative;
margin-top: 144px;
bottom: 0;
/* overflox:hidden; */
z-index: 9999;
opacity: .9;
box-shadow: 0px 1px 4px beige;
padding: 0;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
/* højde for billed-sektion*/
.mainheader section {
min-height: 204px;
}
#mainlogo {
font-size: 37px;
color: white;
border: 7px solid white;
display: inline-block;
padding: 10px;
position: absolute;
height: 123px;
/* hvid boks*/
line-height: 25px;
top: 202px;
margin-top: -180px;
left: 50%;
width: 600px;
text-align: center;
margin-left: -300px;
text-shadow: 1px 2px 1px #000;
box-shadow: 1px 2px 1px #000;
}
/* og omegns */
#mainlogo p {
font-size: 20px;
padding: 5px;
}
.vector {
width: 60px;
margin-left: -450px;
margin-top: -36px;
}
.mainheader {
margin-top: 10px;
}
Change line 42 in css: "menu li a" to Display: block instead of Display: inline-block:
#menu li a {
text-transform: uppercase;
transition: all .5s ease;
text-decoration: none;
text-align: center;
line-height: 55px;
display: block;
}
I am almost done w/ my menu here. However I have two issues.
I can't add a 1px solid border #fff on the last item of the list.
I need to remove the vertical scrollbar on the left.
Here's my CSS:
#nav li ul {
opacity: 0;
height: 0px;
}
#nav li a {
font-style: normal;
font-weight: 400;
position: relative;
display: block;
padding: 16px 25px;
color: #fff;
white-space: nowrap;
z-index: 2;
text-decoration: none
}
#nav li a:hover {
color: #c0392b;
background-color: #ecf0f1;
}
#nav ul li {
background-color: #e74c3c;
color: #fff;
display: block;
list-style: disc;
}
#nav li:first-child {
border-top: 1px solid #fff;
}
#nav ul {
margin: 0;
padding: 0;
}
#nav .fa { margin: 0px 17px 0px 0px; }
.logo {
width: 100%;
padding: 21px;
margin-bottom: 20px;
box-sizing: border-box;
}
#logo{
color: #fff;
font-size: 30px;
font-style: normal;
}
.sidebar-icon {
position: relative;
float: right;
text-align: center;
line-height: 1;
font-size: 25px;
padding: 6px 8px;
color: #fff;
}
.disp {
opacity: 1!important;
height:auto!important;
transition: height 100ms ease-in-out;
transition-delay: 300ms;
}
#nav li span:first-child {
margin-left: 32px;
}
asdasdasdasdasdasdasdassa
Well, first remove this:
#nav li:not(:last-child) {
border-bottom: 1px solid #fff;
}
for add border to all li even last one:
#nav li {
border-bottom: 1px solid #fff;
}
for removing scroll do this:
JS:
$('body, html').toggleClass('OverflowHidden');
CSS:
.OverflowHidden {
overflow: auto;
}
and for removing double border use this:
#nav li ul li:last-child {
border-bottom: none!important;
}
jsFiddle
Hi can anyone help me with this responsive navigational issue, when I resize the browser window say to 50 %, the links are there but wont click. in the bottom left of the browser the link shows but no click event. Tried using different browsers and same issue.
Here's the HTML:
<ul>
<li>Home</li>
<li>Drop
<ul class="hidden">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul></li>
</ul>
Here's the CSS :
ul {
left: 30%;
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
li {
display: inline-block;
float: left;
margin-right: 1px;
}
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
color: #fff;
font-weight: 700;
border: 2px solid #0072C6;
background-color: #000;
}
li:hover a {
background: #0072C6;
}
li:hover ul a {
background: #f3f3f3;
border: none;
color: #000000;
height: 30px;
font-weight: 300;
line-height: 30px;
}
li:hover ul a:hover {
border: 4px solid #f3f3f3;
padding: 4px;
background: #0072C6;
color: #fff;
}
li ul {
display: none;
}
li ul li {
display: block;
float: none;
}
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
a.clickable {
text-decoration: none;
color: #fff;
background: #0072C6;
text-align: center;
padding: 10px 0;
display: none;
font-weight: 900;
}
#media screen and (max-width : 1160px) {
ul {
position: static;
display: none;
cursor: pointer;
}
li {
margin-bottom: 1px;
}
ul li, li a {
width: 100%;
}
a.clickable {
display: block;
}
a.clickable:focus + ul {
display: block;
}
.login {
top: 0;
width: 150px;
}
}
This has been bugging me all day, So does anyone has any ideas how I can get this too work?
thanks.
max-width:1160px is the problem. Delete that and the nav doesn't disappear.
#media screen and (max-width : 1160px) {
Edit: you could do something like this example. I think the code is a little bit less chunky and easy to edit. Hope it helps.