Why isn't the vertical-align: middle; not working on my h1? The ul isn't aligning with the h1 and it should.
#logo {
color: white;
display: inline;
vertical-align: middle;
}
ul {
padding: 20px;
background: rgba(0,0,0,.5);
}
#title {
position: absolute;
text-align: center;
color: white;
font-size: 50px;
top: 100px;
}
#navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-image: url('../img/bg.jpg');
background-repeat: no-repeat;
background-size: 100% 100%;
height: 600px;
}
li {
float: right;
display: inline;
}
li a {
display: inline;
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
<h1 id="title">Freelance Web Developer</h1>
</div>
Because vertical-align only applies to inline and table-cell elements, not block-level elements.
In order to have your links line up with your header, you need to assign a line-height equal to the height of the header element (35.33px):
li {
line-height: 35.33px;
}
#logo {
color: white;
display: inline;
vertical-align: middle;
}
ul {
padding: 20px;
background: rgba(0, 0, 0, .5);
}
#title {
position: absolute;
text-align: center;
color: white;
font-size: 50px;
top: 100px;
}
#navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-image: url('../img/bg.jpg');
background-repeat: no-repeat;
background-size: 100% 100%;
height: 600px;
}
li {
float: right;
display: inline;
line-height: 35.33px;
}
li a {
display: inline;
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
<h1 id="title">Freelance Web Developer</h1>
</div>
It's also worth noting that having a <h1> element as a child of <ul> is invalid syntax. Only <li> elements shouold be a child of <ul>. What you should do is bring the title out of the <ul>, and float the entire <ul> element to the right.
Hope this helps! :)
Ready for a bit of a mind flip?
Here comes FLEXBOX! This could be done "better" but I didn't want to change your html structure: https://jsfiddle.net/ohbffjjm/
#navbar {
background-color: pink;
}
#logo {
margin-right: 150px;
align-self: flex-start;
}
ul {
display: flex;
align-items: center;
list-style-type: none;
}
li a {
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
</div>
And a flexbox solution with a few html improvements and improvisations.
body {
margin: 0;
}
header {
color: white;
background: rgba( 0, 0, 0, 0.5 );
}
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
header,
ul {
display: flex;
align-items: center;
justify-content: space-between;
}
h1,
h2 {
margin: 0.5rem 0;
}
h1 {
padding: 0 20px;
}
h2 {
text-align: center;
}
ul {
padding: 0 10px;
}
li {
padding: 10px;
}
li a {
color: white;
text-decoration: none;
transition: color 350ms ease-in-out;
}
li a:hover {
color: gold;
}
<header>
<h1 id="logo">Jordan Baron</h1>
<ul>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
</header>
<main>
<h2>Freelance Web Developer</h2>
</main>
Related
I want to ask you why i get this white gap when i want to do fixed scroll navbar on top ? Do you guys have any sugestion in this situation ? The menu should get on the background image. I have tried to do something with the background but it doesnt help.
Here is the pic of gap:
https://ibb.co/RcvM5nS
And here is the code:
.background {
background-color: #000000;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 650px;
width: 100%;
}
/*menu*/
#siteNav {
margin: 0 auto;
position: fixed;
width: 100%;
height: 50px;
box-sizing: border-box;
top: 0;
left: 0;
transition: 0.3s;
}
#siteNav.scroll {
background: rgba(0, 0, 0, 0.8);
height: 80px;
padding: 10px 80px;
}
#siteNav .logo {
padding: 10px;
height: 40px;
float: left;
transition: 0.3s;
}
#siteNav ul {
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
#siteNav ul li {
list-style: none;
}
#siteNav ul li a {
line-height: 50px;
padding: 6px 30px;
text-decoration: none;
transition: 0.3s;
color: #ffffff;
}
#siteNav.scroll ul li a {
color: #000000;
}
#siteNav ul li a:focus {
outline: none;
}
<nav id="siteNav">
<img class="logo" src="images/img2-logo.png" alt="">
<ul>
<li>MISSION</li>
<li>CLIENTS</li>
<li>PRODUCTS</li>
<li>CONTACT</li>
</ul>
</nav>
<!--header-->
<div class="background">
<header>
<div>
<h1><br><a></a></br>
</h1>
</div>
</header>
</div>
The problem is with h1 margin top. Remove that and it will work.
Also i suggest you use <header> tag as a first level tag which includes the nav.
Anyway, here's the solution.
I added margin:0 to body because here it has a default margin of 8px
.background {
background-color: #000000;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 650px;
width: 100%;
}
/*menu*/
#siteNav {
margin: 0 auto;
position: fixed;
width: 100%;
height: 50px;
box-sizing: border-box;
top: 0;
left: 0;
transition: 0.3s;
}
#siteNav.scroll {
background: rgba(0, 0, 0, 0.8);
height: 80px;
padding: 10px 80px;
}
#siteNav .logo {
padding: 10px;
height: 40px;
float: left;
transition: 0.3s;
}
#siteNav ul {
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
#siteNav ul li {
list-style: none;
}
#siteNav ul li a {
line-height: 50px;
padding: 6px 30px;
text-decoration: none;
transition: 0.3s;
color: #ffffff;
}
#siteNav.scroll ul li a {
color: #000000;
}
#siteNav ul li a:focus {
outline: none;
}
h1 {
margin-top:0;
}
body {
margin:0
}
<nav id="siteNav">
<img class="logo" src="images/img2-logo.png" alt="">
<ul>
<li>MISSION</li>
<li>CLIENTS</li>
<li>PRODUCTS</li>
<li>CONTACT</li>
</ul>
</nav>
<!--header-->
<div class="background">
<header>
<div>
<h1><br /><a></a>
</h1>
</div>
</header>
</div>
Soulution 1 :
Add padding: 6em 0 3em; to <div> below the <nav>
Soulution 2 :
Get rid of <h1>
The code snippet apply the first solution
.background {
background-image: url('https://via.placeholder.com/150');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 650px;
width: 100%;
padding: 6em 0 3em;
}
/*menu*/
#siteNav {
margin: 0 auto;
position: fixed;
width: 100%;
height: 50px;
box-sizing: border-box;
top: 0;
left: 0;
transition: 0.3s;
}
#siteNav.scroll {
background: rgba(0, 0, 0, 0.8);
height: 80px;
padding: 10px 80px;
}
#siteNav .logo {
padding: 10px;
height: 40px;
float: left;
transition: 0.3s;
}
#siteNav ul {
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
#siteNav ul li {
list-style: none;
}
#siteNav ul li a {
line-height: 50px;
padding: 6px 30px;
text-decoration: none;
transition: 0.3s;
color: #000000;
}
#siteNav.scroll ul li a {
color: #000000;
}
#siteNav ul li a:focus {
outline: none;
}
<nav id="siteNav">
<img class="logo" src="images/img2-logo.png" alt="">
<ul>
<li>MISSION</li>
<li>CLIENTS</li>
<li>PRODUCTS</li>
<li>CONTACT</li>
</ul>
</nav>
<!--header-->
<div class="background">
<header>
<div>
<h1><br><a></a></br>
</h1>
</div>
</header>
</div>
I think you have used <h1> tag in your HTML code and that is having default margins set in it. if you just handle that, it will resolve your problem.
I am trying to get my nav bar to display horizontally in a line at the top of my web page below my h1 tag. I tried all sorts of different methods to get it to line up horizontally but it won't change. My nav bar continues to display vertically centered. I want it to be a thin bar up at the top below the h1. As of right now, it displays with each li stacked on top of the other instead of side by side. Any help or ideas are appreciated.
#wrapper{
background-color: #FFFFFF;
color: #000066;
min-width: 700px;
max-width: 1024px;
margin-right: auto;
margin-left: auto;
padding-top: 0px;
}
h1 {
background-color: darkcyan;
color: #74ebd5;
background-position: center;
background-repeat: no-repeat;
text-align: center;
font-size: 3em;
line-height: 80%;
padding: 30px;
text-shadow: #CCCCCC;
margin-bottom: 0;
}
main {
margin-left: 180px;
padding-bottom: 100px;
}
ul {
list-style-type: none;
margin: 0;
padding: 10px;
overflow: hidden;
background-color: #333;
width: 100%;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
nav{ display:inline-block;
width: 100%;
font-weight: bold;
background-color: grey;
}
nav ul {
list-style: none;
width: 100%;
border: 1px solid ;
text-align: right;
display:inline-block;
}
nav a{
text-decoration: none;
border: 1px solid;
width: 100%
}
nav a:link{color:cyan;}
nav a:visited{color:#6699FF;}
nav a:hover{color: gold;}
<div id="wrapper">
<header>
<h1>Polar Bar</h1>
<nav>
<ul>
<li>Home</li>
<li>Menu</li>
<li>About Us</li>
<li>Contact</li>
<li>Social</li>
</ul>
</nav>
Make the li elements inline-block, and add box-sizing:border-box:
CSS: #wrapper {
background-color: #FFFFFF;
color: #000066;
width: 700px;
max-width: 1024px;
margin-right: auto;
margin-left: auto;
padding-top: 0px;
}
h1 {
background-color: darkcyan;
color: #74ebd5;
background-position: center;
background-repeat: no-repeat;
text-align: center;
font-size: 3em;
line-height: 80%;
padding: 30px;
text-shadow: #CCCCCC;
margin-bottom: 0;
}
main {
margin-left: 180px;
padding-bottom: 100px;
}
ul {
list-style-type: none;
margin: 0;
padding: 10px;
overflow: hidden;
background-color: #333;
width: 100%;
box-sizing: border-box;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
box-sizing: border-box;
}
nav {
display: inline-block;
width: 100%;
font-weight: bold;
background-color: grey;
}
nav ul {
list-style: none;
width: 100%;
border: 1px solid;
text-align: right;
display: inline-block;
}
nav a {
text-decoration: none;
border: 1px solid;
width: 100%;
}
nav a:link {
color: cyan;
}
nav a:visited {
color: #6699FF;
}
nav a:hover {
color: gold;
}
<div id="wrapper">
<header>
<h1>Polar Bar</h1>
<nav>
<ul>
<li>Home</li>
<li>Menu</li>
<li>About Us</li>
<li>Contact</li>
<li>Social</li>
</ul>
</nav>
I don't understand your question. what did you want?.But Is this you want?
#wrapper{ background-color: #FFFFFF;
color: #000066;
min-width: 700px;
max-width: 1024px;
margin-right: auto;
margin-left: auto;
padding-top: 0px;
}
h1 {background-color: darkcyan;
color: #74ebd5;
background-position: center;
background-repeat: no-repeat;
text-align: center;
font-size: 3em;
line-height: 80%;
padding: 30px;
text-shadow: #CCCCCC;
margin-bottom: 0;}
main {margin-left: 180px;
padding-bottom: 100px;
}
ul {
list-style-type: none;
margin: 0;
padding: 10px;
overflow: hidden;
background-color: #333;
width: 98% !important;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
nav{ display:inline-block;
width: 100%;
font-weight: bold;
background-color: grey;
}
nav ul {
list-style: none;
width: 100%;
border: 1px solid;
text-align: right;
display: inline-block;
}
nav > ul > li {
float: left;
display: inline-block;
}
nav a{text-decoration: none;
border: 1px solid;
}
nav a:link{color:cyan;
}
nav a:visited{color:#6699FF;}
nav a:hover{color: gold;}
<div id="wrapper">
<header>
<h1>Polar Bar</h1>
<nav>
<ul>
<li>Home</li>
<li>Menu</li>
<li>About Us</li>
<li>Contact</li>
<li>Social</li>
</ul>
</nav>
</header>
</div>
I'm trying to align my h2 to the right side of the header while keeping the same vertical orientation as it is right now, but float right does not seem to work. Any ideas?
<div class="header-bg">
<h1>
Heading
</h1>
<h2>
this is where you write more things
</h2>
</div>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact Me</li>
<li>About</li>
</ul>
Here is the CSS:
body {
margin: 0;
}
.header-bg {
background: lightblue;
}
h1, h2 {
display: inline-block;
margin: 10px 10px;
/* border: solid black 1px; */
}
}
h2 {
/* border: solid black 1px; */
float: right;
}
ul {
clear: both;
list-style: none;
margin: 0;
padding: 0;
background: #333;
overflow: hidden;
}
Here is the link to jsfiddle: https://jsfiddle.net/n8xjk4ax/3/
First, remove the extraneous }, like the comments say.
Now with the h2 floating, it will no longer be on the same baseline as the h1. If you do want them to be, there are several possibilities.
Don't float it, but justify-align the items in the container
body {
margin: 0;
}
.header-bg {
background: lightblue;
padding: 10px;
text-align: justify;
-moz-text-align-last: justify;
text-align-last: justify;
}
h1, h2 {
display: inline-block;
margin: 0;
/* border: solid black 1px; */
}
ul {
clear: both;
list-style: none;
margin: 0;
padding: 0;
background: #333;
overflow: hidden;
}
li a {
display: block;
color: white;
text-decoration: none;
text-align: center;
padding: 14px 16px;
}
li {
float: left;
}
li:last-child {
float: right;
}
li a:hover {
background-color: #111;
color: white;
}
<div class="header-bg">
<h1>
Heading
</h1>
<h2>
this is where you write more things
</h2>
</div>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact Me</li>
<li>About</li>
</ul>
or if you do want to float, the container will also need overflow:hidden to account for narrow screens. And you should give the h1 and the h2 the same metrics. Using line-height is most straightforward.
body {
margin: 0;
}
.header-bg {
background: lightblue;
overflow:hidden;
}
h1, h2 {
display: inline-block;
margin: 0 10px;
line-height: 4rem;
/* border: solid black 1px; */
}
h2 {
/* border: solid black 1px; */
float: right;
}
ul {
clear: both;
list-style: none;
margin: 0;
padding: 0;
background: #333;
overflow: hidden;
}
li a {
display: block;
color: white;
text-decoration: none;
text-align: center;
padding: 14px 16px;
}
li {
float: left;
}
li:last-child {
float: right;
}
li a:hover {
background-color: #111;
color: white;
}
<div class="header-bg">
<h1>
Heading
</h1>
<h2>
this is where you write more things
</h2>
</div>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact Me</li>
<li>About</li>
</ul>
How am I able to center the photo with the text, without minimizing the photo itself?
I've tried; max-height: xx, but that wasn't it.
The photo is centered in height, but not the text. How's this possible?
http://jsfiddle.net/gLpqoamn/
.hoyre{
background-color:#f19f00;
}
.hoyre:hover{
background-color:#d98500;
}
header{
background-color: white;
}
.logo{
width: 57px;
height: 34px;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #fff;
text-transform: uppercase;
width: 100%;
color: black;
}
li {
float: left;
}
li a {
display: block;
text-align: center;
padding: 20px 20px;
text-decoration: none;
color: black;
}
li a:hover {
color: #f19f00;
}
body{
margin:0;
font-family: 'Roboto', sans-serif;
background-color: #333;
}
.container{
max-width:1300px;
margin-left:auto;
margin-right:auto;
}
.active {
position: relative;
}
</style>
<body>
<header>
<div class="container">
<ul>
<li><img src="http://i.imgur.com/QAEzQxp.png" class="logo"></li>
<li>Home</li>
<li>Contact</li>
<li>About</li>
<li class="hoyre" style="float:right;">Donate</li>
</ul>
</div>
</header>
</body>
I would use flex on the ul, then you can use align-items to vertically center or position the children. A margin-left: auto on the last link will push it to the right, then you can move the background color to the link to keep it from stretching the height of the parent
.hoyre {
margin-left: auto;
background-color: #f19f00;
min-height: 100%;
align-self: stretch;
display: flex;
align-items: center;
}
.hoyre:hover {
background-color: #d98500;
}
header {
background-color: white;
}
.logo {
width: 57px;
height: 34px;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #fff;
text-transform: uppercase;
width: 100%;
color: black;
display: flex;
align-items: center;
}
li {}
li a {
display: block;
text-align: center;
padding: 20px 20px;
text-decoration: none;
color: black;
}
li a:hover {
color: #f19f00;
}
body {
margin: 0;
font-family: 'Roboto', sans-serif;
background-color: #333;
}
.container {
max-width: 1300px;
margin-left: auto;
margin-right: auto;
}
.active {
position: relative;
}
</style>
<body>
<header>
<div class="container">
<ul>
<li>
<img src="http://i.imgur.com/QAEzQxp.png" class="logo">
</li>
<li>Home</li>
<li>Contact</li>
<li>About</li>
<li class="hoyre">Donate</li>
</ul>
</div>
</header>
</body>
For using height:100% in your css you should define parent element height first. then you change li element to behave like table and fill 100% height.
Update your styles like this(new styles have comment in front of them):
li {
float: left;
height: 100%; /*fill height */
display: table; /* behave as table*/
}
li a {
display: table-cell; /* behave as table-cell then you can use vertical alignment*/
vertical-align: middle;
text-align: center;
padding: 20px 20px;
text-decoration: none;
color: black;
height: 100% ; /*fill height */
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #fff;
text-transform: uppercase;
width: 100%;
color: black;
height: 80px; /*define height for using height:100% for child elements */
}
I would like a logo to appaear in the center of the navigation bar. At the moment i've made it really small just to ensure I can see it for now but will sort the size out afterwards.
Here is a photoshop design of how I want it to look:
https://gyazo.com/c1b0d25c4fe94a33edf3937576324229
Here is how it looks currently:
https://gyazo.com/4432c9c4874a082a9c4a4c5eb6d7af12
Any help would be greatly appreciated.
HTML:
<body id="chesters">
<header>
<nav>
<ul>
<li>Menu</li>
<li>Burritos</li>
<li><img class="header-image" src="assets/Headerlogo1.png"></li>
<li>Contact Us</li>
<li>About Us</li>
</ul>
</nav>
</header>
<div id="Page">
</div> <!-- Page -->
</body>
CSS:
body {
font-family: 'Open Sans', sans-serif;
background-color: #f3f3f3;
color: #666;
margin: 0px;
padding: 0px;
}
#Page {
padding-top: 100px;
}
header {
background-color: #1c1c1b;
font-family: 'Century gothic';
font-size: 180%;
height: 100px;
width: 100%;
border-bottom: solid;
border-bottom-color: #009641;
border-bottom-width: 5px;
position: fixed;
line-height: 50px;
z-index: 1000;
overflow: hidden;
transition: all 0.8s ease;
}
.header-image {
/*width: 100px;
height: 400px;*/
align-content: center;
margin-top: -30px;
}
#center-column {
background-color: white;
width: 1080px;
height: 100%;
box-shadow: 0px 1px 5px #888888;
margin: 0 auto;
padding-bottom: 10px;
}
nav {
}
nav ul {
text-align: center;
display: table;
}
nav li {
display: table-cell;
vertical-align: middle;
/*display: inline;*/
padding: 0 10px;
}
nav li a {
color: #009641;
text-decoration: none;
}
nav li a:hover {
color: #e2030e;
}
Good morning!
Usually you want to control the nav ul and nav ul li elements appearance together without using floats and heavy padding. take a look at my revisions here. For the logo, you can just put it into an li element:
body {
font-family: 'Open Sans', sans-serif;
background-color: #f3f3f3;
color: #666;
margin: 0px;
padding: 0px;
}
#Page {
padding-top: 100px;
}
header {
background-color: #1c1c1b;
font-family: 'Century gothic';
font-size: 180%;
height: 140px;
width: 100%;
border-bottom: solid;
border-bottom-color: #009641;
border-bottom-width: 5px;
position: fixed;
line-height: 50px;
z-index: 1000;
}
nav {
}
nav ul{
text-align: center;
display: table;
}
nav li {
display: table-cell;
vertical-align: middle;
padding: 0 10px;
}
nav li a {
color: #009641;
text-decoration: none;
}
nav li a:hover {
color: #FFF;
}
<body id="chesters">
<header>
<nav>
<ul>
<li>Menu</li>
<li>Burritos</li>
<li><img class="header-image" src="chesters.png"></li>
<li>Contact Us</li>
<li>About Us</li>
</ul>
</nav>
</header>
<div id="Page">
</div> <!-- Page -->
</body>
Try this revision.
Add this to your CSS:
nav ul {
text-align: center;
}
The li elements shouldn't be affected but the image will be centered.
Add container class before nav and set max-width and margin: 0 auto
<body>
<header>
<div class="container">
<nav>
<ul>
<li>Menu</li>
<li>Takeaway Burritos</li>
<li><img class="header-image" src="assets/Headerlogo1.png"></li>
<li>Contact Us</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div id="Page">
</div>
<!-- Page -->
</body>
body {
font-family: 'Open Sans', sans-serif;
background-color: #f3f3f3;
color: #666;
margin: 0px;
padding: 0px;
}
#Page {
padding-top: 100px;
}
header {
background-color: #1c1c1b;
font-family: 'Century gothic';
font-size: 180%;
height: 140px;
width: 100%;
border-bottom: solid;
border-bottom-color: #009641;
border-bottom-width: 5px;
position: fixed;
line-height: 50px;
z-index: 1000;
}
.container {
max-width: 1282px;
margin: 0 auto;
}
nav {}
nav ul {
text-align: center;
display: table;
}
nav li {
display: table-cell;
vertical-align: middle;
padding: 0 10px;
}
nav li a {
color: #009641;
text-decoration: none;
padding-right: 20px;
}
nav li a:hover {
color: #FFF;
}