I have a Navbar with logo and links spaced out appropriately, in the hero section I use an image with full width and height but if leaves a white space between the nav and hero section. I have searched for how to address this but cannot seem to figure it out.
How can I remove the space between the Nav and next section?
Example Image: https://ibb.co/7YcTg4p
*Solved - After adding overflow: auto; inside the #container-bg {} class the white space collapsed and now the nav follows the next section with any space issues.
<header>
<img
src="https://cdn.pixabay.com/photo/2017/09/26/21/45/spiral-
2790215__480.png"/>
<nav class="nav-container">
<ul>
<li>Home
</li>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div id="container-bg">
<div class="content-wrapper">
<h1>Sample text</h1>
<p>More sample text</p>
Contact
</div>
CSS
header img {
width: 40px;
position: relative;
left: 120px;
top: 15px;
}
.nav-container {
float: right;
}
.nav-container ul {
margin: 0;
}
.nav-container ul li {
display: inline-block;
}
.nav-container ul li a {
text-decoration: none;
padding-right: 60px;
position: relative;
font-size: large;
color: black;
top: 22px;
right: 120px;
margin: 0px 0px 0px 20px;
padding: 0px 4px 6px 4px;
}
#container-bg {
background: url(img/img-bg.jpg) no-repeat center center fixed;
background-size: cover;
background-attachment: fixed;
width: 100%;
height: 100%;
}
.content-wrapper {
margin: 0 auto;
width: 80%;
text-align: center;
position: relative;
top: 30%;
}
.content-wrapper a {
background-color: blue;
color: white;
border-radius: 15px;
text-decoration: none;
text-transform: uppercase;
border: 1px solid #ffffff;
padding: 12px 18px;
font-size: 22px;
cursor: pointer;
I think I did not understand the question but it may help
.content-wrapper {
margin: 0 auto;
width: 80%;
text-align: center;
position: relative;
top: 0%; // here is the trick
}
After adding overflow: auto; inside the #container-bg {} class the white space collapsed and now the nav follows the next section without any spacing or gap issues.
Related
I followed a tutorial about sticky navbar with pure css without javascript. The problem is that the sticky navigation bar is not fixed at the top of the page when i scroll down. Under this sticky navbar I have 3 other sections. Every time I scroll down the page that the navbar goes under sections and does not work anymore. In the header I have a full-width image and I have some text and a button on it.
Here is my code of navbar in HTML:
header {
margin: auto;
position: relative;
width: 100%;
height: 100vh;
background: linear-gradient(black, transparent, black), url(images/architecture2.jpg);
background-size: cover;
background-position: center;
display: table;
top: 0;
}
nav {
position: absolute;
width: 100%;
height: 50px;
background: rgba(0, 0, 0, .1);
position: sticky;
top: 0;
}
nav ul {
display: flex;
margin: 0;
padding: 0 100px;
float: right;
}
nav ul li {
list-style: none;
}
nav ul li a {
display: block;
color: #fff;
padding: 0 15px;
text-decoration: none;
text-transform: capitalize;
font-weight: bold;
line-height: 90px;
}
.intro .inner {
margin-top: 200px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
z-index: 10;
color: #fff;
}
.content h1 {
font-weight: 800;
color: #fff;
text-transform: uppercase;
font-size: 3.5rem;
}
.content p {
padding: 0;
margin-top: -35px;
margin-left: -1px;
color: #fff;
font-size: 2.2rem;
padding-bottom: 35px;
}
.btnD1 {
border: 2px solid #fff;
color: #000;
background: #fff;
border-radius: 50px;
padding: 16.5px 50px;
font-size: 1.15rem;
font-weight: 500;
text-decoration: none;
}
<html>
<head>
</head>
<body>
<div class="wrapper">
<header>
<nav>
<div class="menu">
<ul>
<li>Acasa</li>
<li>Despre Noi</li>
<li>Calatorii</li>
<li>Contact</li>
<li>SignIn</li>
</ul>
</div>
</nav>
<div class="intro">
<div class="inner">
<div class="content">
<h1>Călătoreşte cu noi în jurul lumii</h1>
<p>Destinaţia visată este la un click distanţă!</p>
<a class="btnD1" href="#">Rezervă acum</a>
</div>
</div>
</div>
</header>
</div>
</body>
</html>
Sorry for my bad english.
Thanks!
The reason why it behave is the use of z-index in the .intro .inner class. You will need to set the z-index: 11; on the .nav class for it to appear on top of everything.
header {
margin: auto;
position: relative;
width: 100%;
height: 100vh;
background: linear-gradient(black, transparent, black), url(images/architecture2.jpg);
background-size: cover;
background-position: center;
display: table;
top: 0;
}
nav {
position: absolute;
width: 100%;
height: 50px;
background: rgba(0, 0, 0, .8);
position: sticky;
top: 0;
z-index: 11;
}
nav ul {
display: flex;
margin: 0;
padding: 0 100px;
float: right;
}
nav ul li {
list-style: none;
}
nav ul li a {
display: block;
color: #fff;
padding: 0 15px;
text-decoration: none;
text-transform: capitalize;
font-weight: bold;
line-height: 90px;
}
.intro .inner {
margin-top: 200px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
z-index: 10;
color: #fff;
}
.content h1 {
font-weight: 800;
color: #fff;
text-transform: uppercase;
font-size: 3.5rem;
}
.content p {
padding: 0;
margin-top: -35px;
margin-left: -1px;
color: #fff;
font-size: 2.2rem;
padding-bottom: 35px;
}
.btnD1 {
border: 2px solid #fff;
color: #000;
background: #fff;
border-radius: 50px;
padding: 16.5px 50px;
font-size: 1.15rem;
font-weight: 500;
text-decoration: none;
}
<html>
<head>
</head>
<body>
<div class="wrapper">
<header>
<nav>
<div class="menu">
<ul>
<li>Acasa</li>
<li>Despre Noi</li>
<li>Calatorii</li>
<li>Contact</li>
<li>SignIn</li>
</ul>
</div>
</nav>
<div class="intro">
<div class="inner">
<div class="content">
<h1>Călătoreşte cu noi în jurul lumii</h1>
<p>Destinaţia visată este la un click distanţă!</p>
<a class="btnD1" href="#">Rezervă acum</a>
</div>
</div>
</div>
</header>
</div>
</body>
</html>
If you're not sure what other z-index values you gonna use. Most people set it to 999 for things that supposed to appear on top of everything at all times.
The nav is sticky, but only within it's parent (which is the .header). To fix this, simply make the .header sticky - this way it will be sticky as long as it's parent (which is .wrapper) is being scrolled.
And also give it a higher z-index than it's siblings (.intro inner has z-index: 10), or it will come underneath the intro inner when scrolled pass it :
header {
position: sticky;
top: 0;
z-index: 11;
}
The problem was that sticky propriety. i removed that from the nav and i added a transition and z-index as well.
nav{
position: fixed;
width: 100%;
height: 50px;
background: rgba(0,0,0,.2);
top: 0;
z-index:999;
transition: 0.5s;
}
nav ul{
display: flex;
margin: 0;
padding: 0 100px;
float:right;
}
nav ul li{
list-style: none;
}
nav ul li a{
display: block;
color: #fff;
padding: 0 15px;
text-decoration: none;
text-transform: capitalize;
font-weight: bold;
line-height: 90px;
}
Thank you all!
Make your wrapper's Height auto. this will fix your issue.
enter image description here
body{
margin: 0;
height: 100%;
// background-color:black;
background-image: url("3.jpg");
background-repeat: no-repeat;
background-size: cover;
// background-position: center;
background-attachment: fixed;
cursor: url("cursor.png"), auto;
}
.header {
margin: 0;
padding: 0;
}
ul {
list-style: none;
margin: 0;
padding: 0;
text-align:center;
width: 100%;
position: absolute;
background: transparent;
background: linear-gradient(rgba(195,162,94,.4), rgba(0,0,0,0.3));
overflow: hidden;
z-index: 1;
}
li {
display: inline-block;
// margin-left: 100px;
}
.logo img{
width: 135px;
height: auto;
position: absolute;
margin-top: 0px;
margin-left: 40px;
z-index: 2;
cursor: url("cursor.png"), auto;
}
li a{
width: 100px;
display: block;
// padding-left: 500px;
padding: 35px 15px;
font-size: 20px;
font-family: Sylfaen;
color: white;
text-align: center;
text-decoration: none;
cursor: url("cursor.png"), auto;
}
li a:hover{
color: rgba(96,49,18);
}
<div class="header">
<div class="logo">
<a href="#">
<img src="logo.gif">
</a>
</div>
<div class="navs">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
How not to make them collide in nav bar?
they collide when i zoom in..
I cant seem to understand how it works
and I cant seem to know what to do..
How not to make them collide when zooming in like there is a wall in there..
How not to make them collide in nav bar?
they collide when i zoom in..
I cant seem to understand how it works
and I cant seem to know what to do..
How not to make them collide when zooming in like there is a wall in there..
Add Padding to Your UL
Adding padding-left: 135px; to your ul which is the same width as your logo width. This will prevent the nav area content occupying the same space.
You could add a little more padding so that it does touch fully!
Make it Responsive
Ideally, you would want to make it responsive, so that when it reaches a certain width, the logo goes above the nav or whatever you feel looks best.
#media only screen and (max-width: 600px) {
.logo {
/*Your styles on small screen - example only*/
display:block
position:releative;
}
}
See Responsive Web Design - Media Queries
body{
margin: 0;
height: 100%;
// background-color:black;
background-image: url("3.jpg");
background-repeat: no-repeat;
background-size: cover;
// background-position: center;
background-attachment: fixed;
cursor: url("cursor.png"), auto;
}
.header {
margin: 0;
padding: 0;
}
ul {
list-style: none;
margin: 0;
padding-left: 135px;
text-align:center;
width: 100%;
position: absolute;
background: transparent;
background: linear-gradient(rgba(195,162,94,.4), rgba(0,0,0,0.3));
overflow: hidden;
z-index: 1;
}
li {
display: inline-block;
// margin-left: 100px;
}
.logo img{
width: 135px;
height: 135px;
height: auto;
position: absolute;
margin-top: 0px;
margin-left: 40px;
z-index: 2;
cursor: url("cursor.png"), auto;
}
li a{
width: 100px;
display: block;
// padding-left: 500px;
padding: 35px 15px;
font-size: 20px;
font-family: Sylfaen;
color: white;
text-align: center;
text-decoration: none;
cursor: url("cursor.png"), auto;
}
li a:hover{
color: rgba(96,49,18);
}
<div class="header">
<div class="logo">
<a href="#">
<img src="https://otherthings.files.wordpress.com/2016/02/emoji-books.jpg?w=135&h=135" width="135px" height="135px">
</a>
</div>
<div class="navs">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
When I put my cursor right on top of the link text, the link is not clickable, but if I put my cursor a little bit below the text, it becomes clickable. I'm learning right now so please explain to me why it's doing that and how to fix it.
HTML
<!DOCTYPE html>
<html Lang="en">
<head>
<meta charset="utf-8">
<title>Welcome!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
*{
margin: 0;
padding: 0;
}
header{
width: 1024px;
margin: 0 auto;
background-color: #81D4FA;
height: 50px;
}
header h1{
color: white;
position: relative;
left: 100px;
top: 5px;
}
nav{
margin-top: -20px;
margin-right: 100px;
}
nav ul{
float: right;
margin: 0;
padding: 0;
}
nav ul li{
list-style-type: none;
display: inline-block;
}
nav ul li a{
text-decoration: none;
color: white;
padding: 16px 20px;
}
a:hover{
background-color: #84FFFF;
}
.main{
width: 1024px;
margin-left: auto;
margin-right: auto;
}
.laptop{
width: 1024px;
}
.title{
background-color: #0D23FD;
height: 50px;
width: 300px;
position: relative;
top: -650px;
left: -10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
}
.title h3{
color: white;
text-align: center;
position: relative;
top: 13px;
}
<header>
<h1>Jack Smith</h1>
<nav>
<ul>
<li>About</li>
<li>My Work</li>
<li>Contact Me</li>
</ul>
</nav>
</header>
<div class="main">
<img class="laptop" src="images/laptop.jpg">
<div class="title">
<h3>Front-End Web developer</h3>
</div>
</div>
It's because your <h1> is a block-level element, which will lay over the menu elements. If you give it display: inline-block, it will work as supposed.
A block-level element always starts on a new line and takes up the
full width available (stretches out to the left and right as far as it
can).
See my example below.
* {
margin: 0;
padding: 0;
}
header {
width: 1024px;
margin: 0 auto;
background-color: #81D4FA;
height: 50px;
}
header h1 {
color: white;
position: relative;
left: 100px;
top: 5px;
display: inline-block;
/* Added */
}
nav {
margin-top: -20px;
margin-right: 100px;
}
nav ul {
float: right;
margin: 0;
padding: 0;
}
nav ul li {
list-style-type: none;
display: inline-block;
}
nav ul li a {
text-decoration: none;
color: white;
padding: 16px 20px;
}
a:hover {
background-color: #84FFFF;
}
.main {
width: 1024px;
margin-left: auto;
margin-right: auto;
}
.laptop {
width: 1024px;
}
.title {
background-color: #0D23FD;
height: 50px;
width: 300px;
position: relative;
top: -650px;
left: -10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
}
.title h3 {
color: white;
text-align: center;
position: relative;
top: 13px;
}
<header>
<h1>Jack Smith</h1>
<nav>
<ul>
<li>About
</li>
<li>My Work
</li>
<li>Contact Me
</li>
</ul>
</nav>
</header>
<div class="main">
<img class="laptop" src="images/laptop.jpg">
<div class="title">
<h3>Front-End Web developer</h3>
</div>
</div>
The problem is occurring because of the interaction between some of your styles. You're floating the nav ul element to the right, but you're also setting the nav ul li display to inline-block which is also doing an implicit float (try replacing it with float: left and you'll see the same behavior).
If you set the position:relative on your nav ul, it willforce the elements to float correctly within the ul container.
nav ul{
float: right;
margin: 0;
padding: 0;
position:relative; /*ADD THIS*/
}
I was having trouble centering my sticky nav. After I got it centered it stopped scrolling with the page.Any help would be greatly appreciated I have been looking at this for a while and I am not sure what the problem is.
.navContainter {
width: 960px;
}
.nav {
height: 60px;
background-color: rgba(0, 0, 0, 0.7);
position: -webkit-sticky;
list-style-type: none;
text-align: center;
}
.nav ul {
margin: 0 auto;
padding-left: 0px;
padding-top: 10px;
display: inline-block;
}
ul {
display: inline;
padding: 0;
}
li {
display: inline;
padding: 5px;
font-size: 1.5em;
float: left;
margin-right: 50px;
margin-left: 100px;
position: relative;
font-family: "Josefin Slab", serif;
}
a {
width: 60px;
color: #fff;
}
.sticky {
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 100;
border-top: 0;
}
<head class="navContainer">
<nav class="nav">
<ul>
<li>WEB</li>
<li>PHOTOGRAPHY</li>
<li><img src="img/demo/_small/logo.png"></li>
<li>DESIGN</li>
<li>VIDEO</li>
</ul>
</nav>
</head>
In my experience with sticky navs, I would wrap the nav in a container with these elements:
position: fixed;
z-index: 9999;
The content would look something like this:
.content_main{
margin: 0px 0px 0px 0px;
background: url(../images/concrete_seamless.png) repeat 0 0;
padding: 105px 0px 0px 0px;
z-index:5;
overflow: hidden;
display: inline-block;
position: relative;
}
The z-index differences and the relative position of the conent, set the content to hide under the nav while the page is scrolled, while the fixed position makes the nav stick to the browser.
I never use webkit: sticky;
I have horizontal navigation bar like this.
I need to make this navigation bar vertical left. This is my html
<div ng-controller="PortalController">
<header>
<h1>E_Zuite</h1>
<nav role='navigation'>
<ul>
<li><a class="link-1 entypo-home active" href="#home"></a></li>
<li><a class="link-2 entypo-picture" href="#clients"></a></li>
<li><a class="link-3 entypo-user" href="#about"></a></li>
<li><a class="link-4 entypo-mail" href="#contact-us"></a></li>
</ul>
</nav>
</header>
</div>
and this is my css
header {
width: 100%;
height: 70px;
box-sizing: border-box;
background-color: #373948;
position: fixed;
top: 0px;
left: 0px;
padding: 0px 0px 0px 30px;
}
header h1 {
float: left;
margin: 5px 0px;
color: white;
font-family: 'Meddon', cursive;
}
header nav ul {
height: 70px;
float: right;
}
header nav ul li {
height: 70px;
display: inline-block;
}
I exactly need this navigation bar and icons from top.I'm not much familiar with css.
Change your css to this:
header {
width: 200px;
height: 100%;
box-sizing: border-box;
background-color: #373948;
position: fixed;
top: 0px;
left: 0px;
padding: 0px 0px 0px 30px;
}
header h1 {
float: left;
margin: 5px 0px;
color: white;
font-family: 'Meddon', cursive;
}
header nav ul {
height: 70px;
float: right;
}
header nav ul li {
width: 200px;
height: 70px;
float: left;
display: block;
}
What I have done is simple, changed the width of the header and set the height to be 100%, then I have set the width and float attribute for your li menu.
It should work as you expect, BUT have a look through it to make it exactly how you want it.
header h1{
float:none;
}
header nav ul {
float:none;
}
header nav ul li{
display:block;
width:100%
}
just add css in your css file.
In case you want to fix your vertical nav to the left, the code below will help.
nav{
position: fixed;//fixes the navigation bar to left
top: 100px;
left: 0px;
}
header {
width: 100%;
height: 70px;
box-sizing: border-box;
background-color: #373948;
position: fixed;
top: 0px;
left: 0px;
padding: 0px 0px 0px 30px;
}
header h1 {
float: left;
margin: 5px 0px;
color: white;
font-family: 'Meddon', cursive;
}
header nav ul {
height: 70px;
width: 30px;
margin: 0;
padding: 0;
}
header nav ul li {
display: inline-block;
width: 30px;
}