I'm currently trying to make a website, and I managed to create a navigation bar. However, there is a weird "extra" space between my navigation bar. It was working fine at first but after I referenced a JQuery. However, I doubt the JQuery is the one that caused the problem as the site looks the same even after I took it out. Here's a screenshot of the problem. I'm trying to get rid of the circled part.
My HTML code:
<div id="nav"> <!-- Navigation Bar -->
<nav>
<ul>
<li><a class="selected" href="#">Home</a></li>
<li>About Me</li> <!-- Link to about page -->
<li class="drop">
Games
<div class="drop-content">
Red Faction: Guerrilla <!-- Contains links to the respective pages -->
Way of the Samurai 3
Singularity
</div>
</li>
<li>Reviews</li>
<li>External Store</li> <!-- Link to external site -->
<li>Videos</li> <!-- Contains links to Youtube -->
<li>Feedback</li> <!--Feedback form-->
And here's the stylesheet:
#nav nav{ /* Navigation bar*/
padding-top: 5%;
margin-bottom: 5% }
#nav ul {
list-style-type: none;
margin: 0;
background-color: #1C86EE;
padding: 0;
position: relative;
width: 100%;
bottom: 0;
display: inline-block }
#nav li {
float: left;
width: 14% }
li a, .dropbtn {
display: inline-block;
color: #FFFFFF;
text-align: center;
padding-left: 15%;
padding-right: 15%;
text-decoration: none }
.selected {
background-color: #6CCC0A;
padding-right: 25% }
li a:hover, .drop:hover .dropbtn {
background-color: #BFA810 }
a {
padding-top: 1em;
padding-bottom: 1em }
li.drop {
display: inline-block }
.drop-content {
display: none;
position: absolute;
background-color: #970707;
min-width: 14%;
box-shadow: 0px 8px 16px 0px #000000;
z-index: 100 }
.drop-content a {
color: #FFFFFF;
padding: 15px 20px;
display: block;
text-align: left }
.drop-content a:hover {
background-color: #02BBC4 }
.drop:hover .drop-content {
display: block;
border: 1px solid black;
position: absolute } /*End of navigation*/
* { /* index style */
box-sizing:border-box
}
body {
font-family: Verdana,sans-serif;
margin:0
}
.slideshow-fade {
display:none
}
/* Slideshow container */
.slideshow {
max-width: 100%;
position: relative;
margin: auto;
}
.slideshow img {
opacity: 0.7
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 1em;
margin-top: -1em;
color: #FFFFFF;
font-weight: bold;
font-size: 1.5em;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #000000;
font-size: 1.3em;
padding: 1% 2%;
position: absolute;
bottom: 2%;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.number {
color: #000000;
font-size: 1em;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 1em;
width: 4%;
margin: 0 2px;
background-color: #bbbbbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width : 720px ){
.prev, .next,.text {font-size: 11px}
}
.slideshow-fade a {
color: #FFFFFF
}
.slideshow-fade a:visited {
color: #5115D0
} /*End of style for index*/
footer { /*Footer*/
background: #000000;
width: 100%;
height: 5%;
position: relative;
bottom: 0;
left: 0;
padding-top: 2%;
overflow: hidden;
}
footer p {
font-family: arial, calibri, sans-serif;
color: #FFFFFF;
text-align: center;
padding-bottom: 2%;
} /*End of footer*/
Any help will be much appreciated. Thank you.
Here is the jsfiddle file to make it more convenient to see the problem. https://jsfiddle.net/8xutoea5/
Edit: Added more CSS codes.
Edit: I solved the problem. Thanks everyone for taking the time to solve this problem.
It appears to be a margin somewhere else in your CSS, not provided here, that is causing the issue. You could try setting margin-bottom:0; a few places to see if that solves it.
#nav nav ul li {
margin-bottom: 0;
padding-bottom: 0;
}
#nav nav ul li a {
margin-bottom: 0;
}
Or provide the rest of your style sheet.
It's most likely because you have your ul as inline-block, that will cause some space after elements. Also you have float on your li without a clearfix on nav.
You can solve this in various ways, here is one where you can use display: flex; and remove the float: left; on li. This is a pretty solid base you can build on with changing the justify-content property. You can find a awesome guide to flexbox over at css-tricks.com
UPDATE
I made some updates to the fiddle to solve the problem. Please note the code on top, also I made some other changes. Write if there is something unclear
* {
box-sizing: border-box;
}
jsfiddle
#nav ul {
list-style-type: none;
margin: 0;
background-color: #1C86EE;
padding: 0;
position: relative;
width: 100%;
bottom: 0;
display: flex;
justify-content: space-between;
}
#nav li {
width: 14%;
}
It's caused by the section "External Store", it's too long and it wraps. You can make it shorter or force a "no-wrap".
With the css property white-space with the value nowrap.
You have no classes on your internal tags so I would suggest add a class to the a tags and add the rule to it.
a.listLink{
white-space: nowrap;
}
Or you can just add a style attribute to that specific tag but I don't find that solution cool enough.
Related
I made a navigator on top of my website, I want it to shrink a bit when I hover over it.
.top-container ul>li{
display: inline;
float: left;
margin: 5px 15px;
padding: 0;
scale: 1;
background-color: white;
border: solid 0px #333;
transition: padding ease-out .3s, margin ease-out .3s,
border ease-out .3s, background-color ease-out .3s;
}
.top-container ul>li:hover{
background-color: red;
padding: 5px 15px;
margin: 0;
}
(its not the full code of style sheet!)
okay so when I use this code, my list elements starting to shake when I hover over.
how can I solve this problem?
or is there a more efficient way to do this?
Also i tried scale and Transform: scale(); did not give me what i want because they scaled up the text and border too D:
Here is the Web site the issue is current.
https://akiokiyota.github.io/RemoteWebsite/
You need to separate the text and visual components. The text does not change, so it makes no sense to animate the entire block with text, but will be limited only to decoration when hovering.
Another very bad practice is that the size of the menu item (element a) is smaller than the element li, pointing at which activates the animation. This may confuse the user.
How would I do:
header {
display: flex;
align-items: center;
font-family: sans-serif;
font-stretch: condensed;
}
header a {
text-decoration: none;
color: #333;
}
.logo {
margin-right: auto;
font-size: 300%;
font-weight: 400;
}
.top-container {
white-space: nowrap;
}
.top-container ul,
.top-container li {
list-style: none;
display: inline;
}
.top-container ul>li>a {
font-size: 120%;
padding: 5px 15px;
position: relative;
}
.top-container ul>li>a::after {
content: "";
z-index: -1;
position: absolute;
background-color: red;
transition: ease-out 0.3s;
width: 0;
height: 0;
left: 50%;
top: 50%;
}
.top-container ul>li>a:hover::after {
left: 0;
top: 0;
width: 100%;
height: 100%;
}
<header>
<h1 class="logo">QZEN</h1>
<div class="top-container">
<ul>
<li>HOME</li>
<li>GAMES</li>
<li>ARTS</li>
<li>ASSETS</li>
<li>ABOUT</li>
</ul>
</div>
</header>
I'm following this guide for a responsive navigation bar that works for mobile and for web
https://www.youtube.com/watch?v=D-h8L5hgW-w&t=7225s
Sorry in advance if its a very easy solution.
Im struggling to center my navigation bar. Right now its placed left side.
<body>
<!-- Navigation bar-->
<div class="navbar">
<img id="mobile-cta" class="mobile-menu" src="/images/open.svg" alt="Open Navigation">
<nav>
<img id="mobile-exit" class="mobile-menu-exit" src="../images/close.svg" alt="Close Navigation">
<ul class="primary-nav">
<li class="current">Forside</> </li>
<li>Portfolio</li>
<li>Kontakt</li>
</ul>
</nav>
</div>
<body>
That looks like this
Picture of navbar
Picture of mobile version, this one is totally fine
And this is my whole CSS for the navbar.
/* Code for Navigation bar */
.navbar {
background: white;
padding: 1em;
position: sticky;
top: 0px;
width: 100%;
/* Hides the navigation menu when on mobile */
nav {
display: none;
}
.mobile-menu {
cursor: pointer;
}
/* Defines distance from logo and if the list should have dots etc. */
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
}
nav.menu-btn {
display: block;
}
/* Mobile menu navigation */
nav {
position: fixed;
z-index: 999;
width: 66%;
right: 0;
top: 0;
background: black;
height: 100vh;
padding: 1em;
ul.primary-nav {
margin-top: 5em;
}
li {
// Mobile menu text
a {
color: white;
text-decoration: none;
display: block;
padding: .5em;
font-size: 1.5em;
text-align: right;
&:hover {
color: #1e73be;
}
}
}
}
a {
display: block;
position: relative;
padding: 0em 0;
}
// Controls the text after animation
a::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0.2em;
background-color: #1e73be;
opacity: 0;
transition: opacity 300ms, transform 300ms;
}
li a::after {
opacity: 1;
transform: scale(0);
transform-origin: center;
}
li a:hover::after,
li a:focus::after {
transform:scale(1);
font-weight: bold;
}
.mobile-menu-exit {
float: right;
margin: .5em;
cursor: pointer;
}
// Controls when to switch from mobile to website view.
#media only screen and (min-width: 768px) {
.mobile-menu,
.mobile-menu-exit {
display: none;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
ul {
display: flex;
text-align: center;
}
a {
color: black;
font-size: 1em;
padding: .1em 1em;
}
ul.primary-nav {
margin: 0;
}
// CSS for the current tab in navbar for web
li.current a {
color: #1e73be;
}
li a {
color: black;
border: 3px;
font-weight: bold;
border-radius: 5em;
margin-top: 0;
&:hover {
color: #1e73be;
}
}
}
}
On your min-width media query on .navbar nav use justify-content: center; instead of space-between so that your ul is centered. Then set another media query instructing the same width but max-width and then change it back to justify-content: space-between; to position your logo.
I've added a fiddle since you are using SCSS.
I am currently coding a responsive menu using the checkbox hack and noticed that when my menu appears after clicking the hamburger icon, it is wider than the viewport. The menu has a fixed position and a flex display. I have added red borders around elements to give show this issue. Here is the relevant code:
/* General styles */
html, body { height: 100%; }
body {
font-family: 'Miriam Libre', sans-serif;
}
a {
color: white;
text-decoration: none;
transition: 0.2s;
}
a:hover {
color: #ea3c53;
}
/* Navigation styles */
nav {
position: absolute;
top: 0;
left: 0;
width: 100%;
background: #222222;
}
.donate {
position: absolute;
margin: 21px;
}
nav .brand {
display: block;
height: 70px;
margin: 10px auto;
}
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
nav label {
position: absolute;
top: 0;
right: 0;
padding: 21px;
background: #63E2C6;
cursor: pointer;
z-index: 2;
}
nav > label > span {
display: block;
margin: 4px auto;
height: 4px;
width: 25px;
border-radius: 1px;
background: #ffffff;
transition: 0.5s;
}
.menu {
display: flex;
position: fixed;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0;
top: -100vh;
left: 0;
height: 100vh;
width: 100%;
background: #222;
list-style-type: none;
border: 1px solid red;
transition: top 0.5s cubic-bezier(0.3, 0.1, 0.3, 0.85);
}
.menu li {
font-size: 30px;
border: 1px solid red;
}
input[type=checkbox]:checked ~ .menu {
top: 0;
}
<nav>
<!-- Top bar -->
Donate
<img src="media/logo2.png" alt="Logo" class="brand">
<input type="checkbox" id="nav">
<label for="nav">
<span></span>
<span></span>
<span></span>
</label>
<ul class="menu">
<li>Home.</li>
<li>Mission.</li>
<li>Contact.</li>
</ul>
</nav>
So, my question is, why is this happening? After all, I do have the width set to 100%, not 110%.
You have margin on your body element. Add:
body {
margin: 0;
}
There is also default margin and padding on your ul element that is also being set to width: 100%;
I recommend checking all of your primary containers, looking at them in your browser's inspector will highlight when you have additional spacing on an element that you may not be accounting for.
I've been playing around with some navigation effects for a project and I've hit a few problems I'm afraid.
Firstly, the transition timing seems a bit off. My general desire was to have the "tooltip", or link name/label, to slide out when you hover over, and then slide back in when you hover off. The idea was to have the highlight color of the icon (numbers in this case) to appear as though it's simply extending and revealing the word, and then shrinking until it's all gone. I've tried a number of variations of timing and delays, but no luck.
I'm also having issues with getting the span to fill the available space/same height of the link area. I altered the spans color to highlight this discrepancy in area.
Lastly, I've put a longer name for link 5 to demonstrate the limitation/problem with using a fixed/specific width for the span. I don't think there's anyway to achieve all that I'm hoping to as well as having a variable width that depends on the length of the text.
Here is the code I have (CodePen link below):
HTML:
<body>
<div class="navigation navbar-fixed-top">
<div class="navigation container">
<ul class="navigation nav-left">
<li>1<span class="tooltiptext">Welcome</span></li>
<li>2<span class="tooltiptext">Second</span></li>
<li>3<span class="tooltiptext">Third</span></li>
<li>4<span class="tooltiptext">Fourth</span></li>
<li>5<span class="tooltiptext">ExtraLongOneToExposeProblem</span></li>
<li>6<span class="tooltiptext">Sixth</span></li>
</ul>
</div>
</div>
</body>
CSS:
.navigation::after {
clear: both;
}
.navigation::before, .navigation::after {
display: table;
content: " ";
}
.container::after {
clear: both;
}
.container::before, .container::after {
display: table;
content: " ";
}
.navigation {
min-height: 50px;
padding-left: 0;
padding-right: 0;
list-style: none;
z-index: 1;
}
.navigation > li {
display: block;
position: relative;
}
.nav-right, .nav-right > li {
float: right;
margin: 0;
}
.nav-left, .nav-left > li {
float: left;
margin: 0;
}
.navbar-fixed-top {
position: sticky;
margin-bottom: 20px;
top: 0;
border-bottom: 1px solid black;
}
.navbar-fixed-top::before {
display: block;
content: "";
position: absolute;
z-index: -1;
left: 0;
right: 0;
bottom: 0;
top: -142px;
background-color: #008ed0;
background-image: linear-gradient(to bottom right, rgb(0, 87, 128), rgb(0, 157, 230));
}
.container {
margin-right: auto;
margin-left: auto;
padding-right: 15px;
padding-left: 15px;
}
.tooltiptext {
display: block;
background-color: #008ed0;
opacity: 0;
width: 0;
color: white;
margin-left: 10px;
text-align: center;
z-index: 1001;
transition: width 1s ease-in-out, opacity 0.5s ease-in-out 0.5s;
}
.navigation li:hover .tooltiptext {
width: 150px;
opacity: 1;
}
body {
padding-top: 0px;
padding-bottom: 20px;
margin: 0;
}
ul, ol {
margin: 0;
padding: 0;
}
li > a {
display: inline-flex;
width: 100%;
padding: 15px 20px;
color: #fff;
text-decoration: none;
fill: white;
}
li > a:hover, li > a:focus {
background-color: #d50f67;
color: white;
fill: white;
}
*,
*::before,
*::after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Any and all help is greatly appreciated. Linking to this CodePen in the hopes someone can help.
Kind regards,
Don
You can find the website here.
On Chrome:
The icons jump some pixels randomly when you hover over them,
the languages bar is way too low...
On IE:
Looks and works correctly.
Here's only the most important of the CSS
CSS:
#main
{
position: relative;
overflow: hidden;
}
#varjo {
box-shadow: 5px 5px 10px gray;
}
.panel
{
position: relative;
}
/* Me */
#me
{
}
#me .pic
{
position: relative;
display: block;
border-left: 1px #E1E1E1 solid;
}
/*
The pseudo element below applies a noise pattern to the "me" image. It's
meant to help mask blurriness, but you can remove it if you don't like it.
*/
#me .pic:before
{
content: '';
position: absolute;
top: 0;
left: 0;
background: url('images/overlay.png');
width: 100%;
opacity: 0.5;
height: 100%;
z-index: 1;
}
#lang
{
background: black;
opacity: 0.7;
width: 95%;
font-family: Poiret One;
transition: 0.5s opacity;
cursor: default;
position: fixed:
}
::selection {
color: green;
}
#lang:hover{
opacity: 1;
}
#lang a
{
position: relative;
display: inline-block;
color: #fff;
width: 1em;
width: 10%;
height: 1em;
line-height: 0.9em;
margin-right: 150px;
transition: 0.2s color;
white-space:nowrap;
}
#lang a:hover {
color: lightgreen;
}
#lang a.icon:before
{
padding-right: 0;
}
#nav
{
margin-top: 20px;
}
#nav a
{
position: relative;
display: inline-block;
color: #fff;
width: 1em;
height: 1em;
line-height: 0.9em;
}
#nav a.icon:before
{
padding-right: 0;
}
.fa
{
text-decoration: none;
transition: all 0.5s;
}
.fa.solo
{
}
.fa.solo span
{
display: none;
}
.fa:before
{
display:inline-block;
font-family: FontAwesome;
font-size: 1.25em;
text-decoration: none;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
}
You can see the HTML in the Source Code :)
Chrome:
IE:
I think I'm using the most recent version of both, IE and Chrome.
Please help, thank you :)
Seems that the vertical-align of your content is causing that...
1920 X 1080 Screen - Chrome
1280 X 800 Screen - Chrome
As you can see depending on the screen's size the spacing will change - (take a look for your scroll bar)
You can also add some margin-top: in your #nav element.
Something like:
#nav {
margin-top: 30px;
}
Other important change on your site is that you have set opacity: 0 in your #nav .fa-film span. Opacity 0 allows to show when you're hovering (and I guess that you only need to show that tooltip when user hover the icons). It's more useful set that span as display: none and then change your #nav a:hover span to
#nav a:hover span {
display: inherit;
}
Add body {margin:0px; padding:0px;} to your CSS