Few problems. It looks great when it's not re-sized. But when it's re-sized everything plays up.
Main issue is the nav; when it's resized it overlays the main text and collides with it. Also how would I go about sorting out the layout when it's resized? I want the header to always look good regardless of size.
Thank-you.
HTML
<div class="wrapper">
<div class="header">
<div class="company-text"> Kidderminster Electronic Recycling</div>
<nav>
Contact
FAQ
Recycling
Where we collect
Home
</nav>
<div class="clear"></div>
</div>
<div class="main-content">dfgf</div>
<div class="footer">xxzxczxczxcz</div>
</div>
CSS
body, html {
margin: 0 0;
height: 100%;
}
#font-face {
font-family: TCB_____;
src: url('TCB_____.ttf');
}
.wrapper {
width: 100%;
height: 100%;
background-color: yellow;
}
.header {
width: 100%;
background: black;
height: 20%;
}
nav {
background-color: #222;
padding: 0;
padding-right: 5%;
width: 45%;
display: inline-block;
float: right;
position: relative;
top: 50%;
transform: translateY(-50%);
}
nav a { color: #F9F9F9; display: block; float:right; padding: 10px; }
nav a:visited { color: #f9f9f9; }
nav a:hover { text-decoration: none; background: #27B3CF; }
nav a:active { position: relative; top: 0; }
a {
outline: 0;
text-decoration: none;
font-family: TCB_____; /* no .ttf */
text-transform: uppercase;
letter-spacing: 0.3em;
font-size: 1.0037500100376em;
}
.clear {
clear: both;
}
.company-text {
font-family: TCB_____; /* no .ttf */
font-size: 1.5em;
padding-left: 5%;
letter-spacing: 0.3em;
color: white;
text-transform: uppercase;
float: left;
width: 45%;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.main-content {
background:url('all-electronics-recycling-home.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 75%;
}
.footer {
height: 5%;
background: black;
width: 100%;
outline: 0;
text-decoration: none;
font-family: TCB_____; /* no .ttf */
text-transform: uppercase;
letter-spacing: 0.3em;
font-size: 0.8em;
color:white;
text-align: center;
}
LIVE DEMO
http://jsfiddle.net/48ajumza/
The #nav element is floated. So, it does not have a height. In order to give it a height, you'll need to drop something in the bottom of it that will clear floats. I used one of your divs with the class .clear.
<div class="wrapper">
<div class="header">
<div class="company-text"> Kidderminster Electronic Recycling</div>
<nav>
Contact
FAQ
Recycling
Where we collect
Home
<div class="clear"></div>
</nav>
<div class="clear"></div>
</div>
<div class="main-content">dfgf</div>
<div class="footer">xxzxczxczxcz</div>
</div>
Related
This is the html code:
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section>
<img src="/static/sun1.png" id="sun">
<h2 id="text"><span>Help save our</span><br>Planet</h2>
<img src="/static/water1.png" id="water">
</section>
<!-- Page content -->
<div class="w3-content w3-padding" style="max-width:1564px">
And here is the code to the nav bar:
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<div class="w3-top">
<div class="w3-bar w3-white w3-wide w3-padding w3-card">
<b>Taco</b> Project
<!-- Float links to the right. Hide them on small screens -->
<div class="w3-right w3-hide-small">
Home
Upload
Library
Search
Capabilities
Process
About
</div>
</div>
This is the CSS for the parallex section of the website. I believe the problem has something to do with something within the parallex being of higher priority than the navigation bar. A fix I did that stopped the text from going above the nav bar is by changing the z index of the Navbar to 999. I still have the error of not being able to click on the Navbar once I start scrolling as well as it going below the transition between the parallex and the rest of the website :
#header{
position: absolute;
top: 0;
left: 0;
width: 100%;
padding: 10px 10px;
display: flex;
justify-content: space-between;
align-items: center;
z-index: 10000;
}
#header .nav{
color: #fff;
font-weight: 700;
font-size: 2em;
text-decoration: none;
}
#header .logo{
color: #094b65;
font-weight: 700;
font-size: 2em;
text-decoration: none;
padding-right: 400px;
}
#header ul{
display: flex;
justify-content: center;
align-items: center;
}
#header ul li{
list-style: none;
margin-left: 20px;
}
#header ul li a{
text-decoration: none;
padding: 6px 15px;
color: #094b65;
border-radius: 20px;
}
#header ul li a:hover,
#header ul li a.active{
background: #094b65;
color: #fff;
}
body {
background: #01191d;
min-height: 1500px;
}
section {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
section:before {
content: "";
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background: linear-gradient(to top, #01191d, transparent);
z-index: 10000;
}
section:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10000;
mix-blend-mode: color;
}
section img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
}
section #text{
position: relative;
color: #094b65;
font-size: 10vw;
text-align: center;
line-height: 0.55em;
font-family: 'Rancho', cursive;
transform: translateY(-50%);
}
section #text span{
color: #094b65;
font-size: 0.20em;
letter-spacing: 2px;
font-weight: 400;
font-family: 'Poppins', sans-serif;
}
#text {
position: relative;
color: #ffffff;
font-size: 10em;
z-index: 1;
}
#road {
z-index: 2;
}
p, h3{
color: white;
}
.sec {
position: relative;
padding: 100px;
}
.sec h2{
font-size: 3.5em;
color: #fff;
margin-bottom: 10px;
}
.sec p{
font-size: 1em;
color: #fff;
}
It seems like the issue is that the navbar is going below the parallex, but that doesn't really make sense since I can view it the whole time.
video demo of the page
Its probably z-index. Since the banner section has stacked layers it should have z-index set. You need to set a higher z-index for .w3-top. May be add .w3-top{z-index:999} to the css and check.
Try to pass the entire nav bar (all elements supposed to be clickable) in tags and add
The function javascript_function() has to contain everything you want to do after the click.
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.
This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Closed 4 years ago.
I’m trying to move my text to the middle of my header on the image but as soon as I move it the whole header follows. Could someone try to help me solve this issue? As you see I’m trying to make it using margin-top but when I implement this the header follows. I have closed all the divs that affects the image.
html, body {
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
body {
font-family: 'Josefin Sans', sans-serif;
text-align: center;
}
header {
width: 100%;
height: 400px;
background: url(/assets/image/tjanst.jpg) no-repeat 50% 50%;
background-size: cover;
}
.content {
width: 94%;
margin: 4em auto;
font-size: 20px;
line-height: 30px;
text-align: justify;
}
.logo {
line-height: 60px;
position: fixed;
float: left;
margin: 16px 46px;
color: #fff;
font-weight: bold;
font-size: 20px;
letter-spacing: 2px;
}
nav {
position: fixed;
width: 100%;
line-height: 60px;
z-index: 10;
}
nav ul {
line-height: 60px;
list-style: none;
background: rgba(0, 0, 0, 0);
overflow: hidden;
color: #fff;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
nav.black ul {
background: #000;
padding: 16px 40px;
}
nav ul li {
display: inline-block;
padding: 16px 40px;
}
.move-down h3{
margin-top: 200px;
max-width: 400px;
}
nav ul li a {
font-family: 'Josefin Sans', sans-serif;
font-size: 14px;
color: #fff;
font-weight: 600;
text-transform: uppercase;
text-decoration: none;
}
a {
color: #fff;
text-decoration: none;
}
.menu-icon {
line-height: 60px;
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: #fff;
display: none;
}
#media(max-width: 786px) {
.logo {
position: fixed;
top: 0;
margin-top: 16px;
}
nav ul {
max-height: 20px;
background: #000;
}
nav.black ul {
background: #000;
}
.showing {
max-height: 34em;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 24px;
text-align: center;
}
.menu-icon {
display: block;
}
}
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo wow tada">
</div>
<div class="menu">
<ul>
<li>START</li>
<li>TJÄNSTER</li>
<li>OM OSS</li>
<li>KONTAKT</li>
</ul>
</div>
</nav>
<div class="move-down wow fadeInUp"><h3> VILL GÖRA KUNDEN NÖJD</h3>
<h3> tel: 070719763 </h3></div>
</header>
how it looks now
https://i.stack.imgur.com/vOQGa.png
Well remove 'margin-top: 200px;' in the '.move-down h3' and add 'padding: 200px 0px 0px 0px;' or 'padding-top: 200px;'
Yes, Simple solution is.
Add this CSS
h3{
maring:0;
}
Hope this helps.
Instead of adding margin-top add top value to relatively positioned element.
.move-down h3 {
max-width: 400px;
position: relative;
top: 205px;
}
https://jsfiddle.net/6uedrb89/12/
I'm trying to move certain text down from the top of it's container, but it's moving the entire container down.
#import url("https://fonts.googleapis.com/css?family=Open+Sans:400,300");
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body
{
font-family: 'Open Sans';
background-color: lightgray;
}
a
{
text-decoration: none;
color: #fff;
}
div#header
{
background-image: url("header_img.png");
background-size: cover;
background-repeat: no-repeat;
width: 80%;
height: 220px;
margin: 0 auto;
margin-top: 50;
color: #fff;
font-size: 22px;
}
div#header span
{
font-weight: 300;
}
div#header h3
{
text-align: center;
padding-top: 85px;
}
div#header h4
{
text-align: center;
}
/*
#222222 - top nav
#F5F5F5 - sidebar background color
#FFF - sidebar link hover background color
#63B7E8 - sidebar nav link hover text color
#D8D8D8 - sidebar nav text color
50px top margin
50px bottom margin
*/
/* Navigation */
/* Nav Title */
.nav
{
background-color: dimgray;
width: 80%;
height: 40px;
margin: 0 auto;
}
/* Remove bullet points on list */
.nav ul
{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: dimgray;
}
.nav ul li
{
float: left;
}
.nav ul li a
{
display: block;
color: #fff;
text-align: center;
padding: 14px; 16px;
text-decoration: none;
}
.nav ul li a:hover
{
color: #099;
background-color: #fff;
}
.home-content
{
width: 80%;
height: 350px;
margin: 0 auto;
margin-top: 30px;
text-align: center;
font-size: 22px;
background-color: #fff;
}
.home-content span
{
font-weight: 300;
}
/* This is the Text I want to push down from the top of it's container.*/
.title
{
margin-top: 15px;
}
/* I also tried this:
.home-content h3
{
margin-top: 15px;
}
*/
<html>
<head>
<title>Dashboard</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="container">
<div id="header">
<h3>Sample<span> Text</span></h3>
<h4>Sample. Text. Here.</h4>
</div>
</div>
<div class="container">
<!-- Navigation -->
<div class="nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
</ul>
</div>
<div class="home-content">
<div class="title">
<h3>Default<span> Text</span></h3>
</div>
</div>
</div>
</body>
</html>
Any tips to push just the text down? I'd appreciate it. Thanks. I have also tried padding, but it gives me the same result.
Set the position of .title to relative and use the top property instead of margin-top.
Like so:
https://jsfiddle.net/kbgb0qvr/
I was able to do it with padding on your parent container, and no margin on the child. I don't know that this is the best way to do it though.
#import url("https://fonts.googleapis.com/css?family=Open+Sans:400,300");
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body
{
font-family: 'Open Sans';
background-color: lightgray;
}
a
{
text-decoration: none;
color: #fff;
}
div#header
{
background-image: url("header_img.png");
background-size: cover;
background-repeat: no-repeat;
width: 80%;
height: 220px;
margin: 0 auto;
margin-top: 50;
color: #fff;
font-size: 22px;
}
div#header span
{
font-weight: 300;
}
div#header h3
{
text-align: center;
padding-top: 85px;
}
div#header h4
{
text-align: center;
}
/*
#222222 - top nav
#F5F5F5 - sidebar background color
#FFF - sidebar link hover background color
#63B7E8 - sidebar nav link hover text color
#D8D8D8 - sidebar nav text color
50px top margin
50px bottom margin
*/
/* Navigation */
/* Nav Title */
.nav
{
background-color: dimgray;
width: 80%;
height: 40px;
margin: 0 auto;
}
/* Remove bullet points on list */
.nav ul
{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: dimgray;
}
.nav ul li
{
float: left;
}
.nav ul li a
{
display: block;
color: #fff;
text-align: center;
padding: 14px; 16px;
text-decoration: none;
}
.nav ul li a:hover
{
color: #099;
background-color: #fff;
}
.home-content
{
width: 80%;
height: 350px;
margin: 0 auto;
margin-top: 30px;
text-align: center;
font-size: 22px;
background-color: #fff;
padding-top: 15px;
}
.home-content span
{
font-weight: 300;
}
/* This is the Text I want to push down from the top of it's container.*/
.title
{
/*margin-top: 15px;*/
}
/* I also tried this:
.home-content h3
{
margin-top: 15px;
}
<div class="container">
<div id="header">
<h3>Sample<span> Text</span></h3>
<h4>Sample. Text. Here.</h4>
</div>
</div>
<div class="container">
<!-- Navigation -->
<div class="nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
</ul>
</div>
<div class="home-content">
<div class="title">
<h3>Default<span> Text</span></h3>
</div>
</div>
</div>
Try this-
#import url("https://fonts.googleapis.com/css?family=Open+Sans:400,300");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Open Sans';
background-color: lightgray;
}
a {
text-decoration: none;
color: #fff;
}
div#header {
background-image: url("header_img.png");
background-size: cover;
background-repeat: no-repeat;
width: 80%;
height: 220px;
margin: 0 auto;
margin-top: 50;
color: #fff;
font-size: 22px;
}
div#header span {
font-weight: 300;
}
div#header h3 {
text-align: center;
padding-top: 85px;
}
div#header h4 {
text-align: center;
}
/*
#222222 - top nav
#F5F5F5 - sidebar background color
#FFF - sidebar link hover background color
#63B7E8 - sidebar nav link hover text color
#D8D8D8 - sidebar nav text color
50px top margin
50px bottom margin
*/
/* Navigation */
/* Nav Title */
.nav {
background-color: dimgray;
width: 80%;
height: 40px;
margin: 0 auto;
}
/* Remove bullet points on list */
.nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: dimgray;
}
.nav ul li {
float: left;
}
.nav ul li a {
display: block;
color: #fff;
text-align: center;
padding: 14px;
16px;
text-decoration: none;
}
.nav ul li a:hover {
color: #099;
background-color: #fff;
}
.home-content {
width: 80%;
height: 350px;
margin: 0 auto;
margin-top: 30px;
text-align: center;
font-size: 22px;
background-color: #fff;
}
.home-content span {
font-weight: 300;
}
/* This is the Text I want to push down from the top of it's container.*/
.title {
position: relative;
top: 15px;
}
/* I also tried this:
.home-content h3
{
margin-top: 15px;
}
*/
<body>
<div class="container">
<div id="header">
<h3>Sample<span> Text</span></h3>
<h4>Sample. Text. Here.</h4>
</div>
</div>
<div class="container">
<!-- Navigation -->
<div class="nav">
<ul>
<li><a class="active" href="#">Home</a>
</li>
<li>Menu1
</li>
<li>Menu2
</li>
<li>Menu3
</li>
</ul>
</div>
<div class="home-content">
<div class="title">
<h3>Default<span> Text</span></h3>
</div>
</div>
</div>
</body>
Instead of using padding or margin, try using position and top attributes on .title as done in the snippet above.
I am trying to do the following:
Vertically and horizontally center a list within a div.
Vertically center the list items. One item is an image, the others are text.
I've looked at a many solutions but can only manage to get the list horizontally centered. I cannot get the list centered vertically. And I cannot get the list items centered vertically.
How can I achieve this?
$(function() {
$('ul.nav a').bind('click', function(event) {
event.preventDefault();
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500);
event.preventDefault();
});
});
* {
margin: 0;
padding: 0;
}
body {
letter-spacing: -1px;
}
.section {
margin: 0px;
height: 100vh;
width: 100vw;
background: url(../images/white.png) no-repeat center center fixed;
position: relative;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.img-circle {
border-radius: 50%;
height: 100px;
width: 100px;
}
.navbar {
height: 160px;
width: 100%;
position: absolute;
top: 0px;
background: #fff;
color: #000000;
font-family: 'Lato', sans-serif;
}
.navbar:hover {
background-color: #787878;
}
.contents {
top: 160px;
width: 100%;
position: absolute;
font-family: 'Open Sans', sans-serif;
font-size: 16pt;
font-style: none;
letter-spacing: -1px;
}
.section h2 {
font-family: 'Lato', sans-serif;
font-size: 24px;
text-align: center;
}
.section p {
width: 600px;
}
.navbar ul {
list-style: none;
}
.navbar ul li {
float: left;
padding: 15px;
color: #000;
font-size: 14px;
font-weight: bold;
}
.navbar ul li a {
color: #000;
text-decoration: none;
}
.navbar ul li a:hover {
text-decoration: none;
color: #000;
}
span.reference {
position: fixed;
left: 10px;
bottom: 10px;
font-size: 13px;
font-weight: bold;
}
span.reference a {
color: #fff;
text-shadow: 1px 1px 1px #000;
padding-right: 20px;
}
span.reference a:hover {
color: #ddd;
text-decoration: none;
}
.table {
display: table;
/* Allow the centering to work */
margin: 0 auto;
}
<body>
<div class="section" id="sectionAbout">
<div class="navbar">
<div class="table">
<ul class="nav">
<li>ABOUT</li>
<li>SERVICES
</li>
<li>
<a href="#sectionGWA">
<img src="images/yellow.png" class="img-circle">
</a>
</li>
<li>BLOG
</li>
<li>CONTACT
</li>
</ul>
</div>
</div>
<div class="contents">
<h2>ABOUT US</h2>
<div class="table">
<p>
<bold>this</bold>is some text
<br>
<br>this is some more text.
</p>
</div>
</div>
</div>
<!-- The JavaScript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="css/jquery.easing.1.3.js"></script>
</body>
Remove float: left from the .navbar ul li rule, then apply the following CSS.
This works with the vertical-align property, which only applies to inline and inline-block elements. So we have to set all of the list items to display: inline-block and vertical-align:center to center them within the list.
Then to center the nav, we apply a CSS pseudo element to the container and set it to height: 100%, display:inline-block and vertical-align: center
See the demo below to preview this effect.
div.navbar div.table::before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
ul.nav {
font-size: 0;
}
ul.nav li {
display: inline-block;
vertical-align: middle;
}
$(function() {
$('ul.nav a').bind('click', function(event) {
event.preventDefault();
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500);
event.preventDefault();
});
});
div.navbar div.table::before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
ul.nav {
font-size: 0;
}
ul.nav li {
display: inline-block;
vertical-align: middle;
}
* {
margin: 0;
padding: 0;
}
body {
letter-spacing: -1px;
}
.section {
margin: 0px;
height: 100vh;
width: 100vw;
background: url(../images/white.png) no-repeat center center fixed;
position: relative;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.img-circle {
border-radius: 50%;
height: 100px;
width: 100px;
}
.navbar {
height: 160px;
width: 100%;
position: absolute;
top: 0px;
background: #fff;
color: #000000;
font-family: 'Lato', sans-serif;
}
.navbar:hover {
background-color: #787878;
}
.contents {
top: 160px;
width: 100%;
position: absolute;
font-family: 'Open Sans', sans-serif;
font-size: 16pt;
font-style: none;
letter-spacing: -1px;
}
.section h2 {
font-family: 'Lato', sans-serif;
font-size: 24px;
text-align: center;
}
.section p {
width: 600px;
}
.navbar ul {
list-style: none;
}
.navbar ul li {
padding: 15px;
color: #000;
font-size: 14px;
font-weight: bold;
}
.navbar ul li a {
color: #000;
text-decoration: none;
}
.navbar ul li a:hover {
text-decoration: none;
color: #000;
}
span.reference {
position: fixed;
left: 10px;
bottom: 10px;
font-size: 13px;
font-weight: bold;
}
span.reference a {
color: #fff;
text-shadow: 1px 1px 1px #000;
padding-right: 20px;
}
span.reference a:hover {
color: #ddd;
text-decoration: none;
}
.table {
display: table;
/* Allow the centering to work */
margin: 0 auto;
}
<body>
<div class="section" id="sectionAbout">
<div class="navbar">
<div class="table">
<ul class="nav">
<li>ABOUT</li>
<li>SERVICES
</li>
<li>
<a href="#sectionGWA">
<img src="images/yellow.png" class="img-circle">
</a>
</li>
<li>BLOG
</li>
<li>CONTACT
</li>
</ul>
</div>
</div>
<div class="contents">
<h2>ABOUT US</h2>
<div class="table">
<p>
<bold>this</bold>is some text
<br>
<br>this is some more text.
</p>
</div>
</div>
</div>
<!-- The JavaScript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="css/jquery.easing.1.3.js"></script>
</body>
The following code is great for vertically centering items within divs. This article has a few other scenarios that you might find useful -> Centering Items
div {
position: relative;
top: 50%;
transform: translateY(-50%);
-ms-transform: translateY(-50%); /* IE=9*/
}