Image in header blocking link in nav bar - html

I got an image in the middle of my navbar which is blocking my link, I made a bit of code below to show that. I tried to fix this with z-index's but it keeps blocking my link.
I can't place the image in the nav bar itself because of the rest of my code (which is not in this snippet). I think it should be solved if I get the absolute image behind the <a> but I can't get that done with z-index's
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<img src="http://lorempixel.com/160/90" class="headerlogo">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>

use this
nav{
z-index:9;}
img.headerlogo{
z-index:-1;
opacity:0.5;
}
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
z-index:9;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
z-index:-1;
opacity:0.5;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<ul>
<img src="http://lorempixel.com/160/90" class="headerlogo">
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>

Put img tage outside and change css for class headerlogo
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: relative;
width: 15%;
height: 100%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<img src="http://lorempixel.com/160/90" class="headerlogo">
<article>
</article>

Give z-index:-1 to z-index: 1; and z-index:1; position:relative; to nav.
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
z-index: 1;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
position: relative;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<img src="http://lorempixel.com/160/90" class="headerlogo">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>

Related

Navigation bar shrinks when position is set to fixed

I am currently having an issue where my navigation bar and banner shrink when I set their position to fixed.I have many things like changing z-index,setting its top position to 0,adding auto margin etc, and none of it worked.I hope someone can point me to my mistake.This is my html code:
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
this is how it should look like
this is how it looks like when i put .top{position:fixed}
When you set an element to absolute or fixed position, it will be out of the the normal content flow and trigger the shrink to fit feature. You can apply the offsets and width/height to position and recreate the box size you wish to have.
.top {
position: fixed;
left: 0; /* ADDED */
top: 0; /* ADDED */
width: 100%; /* ADDED */
}
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
left: 0;
top: 0;
width: 100%;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
Because .top has no width. However, when set to fixed it is using the viewport width to calculate the width. You might want to set it to 75%.
You also might want to set .container to position: relative so .top will relate to its borders.
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
position: relative;
}
.top {
position: fixed;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>

Navbar extending too far

My navbar (or something) is extending too far and creating a horizontal scrollbar. I see people asking about this, but I cannot find the answer for my situation. The smaller I make the screen the bigger the space gets. Right now I'm just looking at IE.11.
Can someone please help? Thank you in advance.
Below is the code where I think the problem is. (html, page css and parallax css).
<body>
<div class="wrapper">
<header class="lighthouse">
<nav class="main">
<div class="menu-icon"> <i class="fa fa-bars fa-2x"></i> </div>
<div class="top-nav-logo"> <img src="images/mlc-logo/mlcwhite.png" width="97" height="59" alt="Mission Lighthouse Church Logo"/></div>
<ul>
<li>HOME</li>
<li>WHO JESUS IS</li>
<li>WHO WE ARE</li>
<li>MEDIA</li>
<li>CONNECT</li>
</ul>
</nav>
<div class="logo"><img src="images/mlc-logo/mlc-main-320.png" width="280" height="167" alt="Mission Lighthouse Church Logo" data-enllax-ratio="-.8" data-enllax-type="foreground"/> </div>
<div class="seagull"><img src="images/Parallax/seagull2.png" alt="Seagulls" width="276" height="136" class="seagull" data-enllax-ratio="-3" data-enllax-direction="horizontal" data-enllax-type="foreground"/></div>
<div class="welcome-home" data-enllax-ratio="-1.1" data-enllax-type="foreground">Welcome Home</div>
</header>
CSS:
html, html * {
padding: 0;
margin: 0;
}
body {
font-size: 62.5%;
}
.wrapper {
width: 100%;
background-color: #000000;
position: absolute;
}
.top-nav-logo {
display: block;
width: 100%;
margin: 10px 10px 0 20px;
position: fixed;
z-index: 100;
}
.menu-icon {
width: 50%;
box-sizing: border-box;
background-color: #000;
text-align: right;
padding: 15px 24px;
cursor: pointer;
color: #fff;
display: none;
}
nav.main {
display: inline-block;
position: fixed;
top: 0;
right: 0;
left: 0;
max-width: 1341px;
margin: 0 auto;
overflow: hidden;
width: 100%;
text-align: left;
z-index: 80;
}
nav ul {
list-style: none;
text-align: center;
background-color: rgba(0,0,0,0.0);
overflow: hidden;
color: #fff;
padding: 0;
margin: 0;
transition: 1s;
z-index: 80;
}
nav.blue ul {
background-color: rgba(0,34,73,0.95);
}
nav ul li {
display: inline-block;
padding: 20px;
}
nav ul li a {
display: inline-block;
color: #ffffff;
font-family: 'Montserrat', sans-serif;
font-weight: 500;
font-size: 1.7em;
text-decoration: none;
}
nav ul li a:visited {
color: rgba(240,183,110,1.00);
}
nav a:hover {
color: #F0F694;
text-decoration: none;
font-weight: 700;
transition: 1.7s;
-webkit-transition: 1.7s; /*Safari*/
}
CSS for Parallax:
.lighthouse {
width: 100%;
height: 768px;
position: relative;
background-image: url(../images/Parallax/front-header-4.jpg), url(../images/Parallax/2nd-header-background.jpg);
background-size: auto 768px, cover;
background-position: top center;
background-attachment: fixed;
background-repeat: no-repeat;
will-change: transform;
overflow: hidden;
}
.logo {
height: 140px;
width: 88%;
position: relative;
top: 170px;
margin: 0 auto;
text-align: center;
opacity: 0.65;
z-index: 20;
}
.seagull {
height: 123px;
width: auto;
position: relative;
left: -190px;
opacity: 0.8;
z-index: 10;
}
.welcome-home {
font-family: 'Kaushan Script', cursive;
font-size: 9.0em;
color: #004391;
position: relative;
text-align: center;
width: 98%;
top: 255px;
}
nav.main {
display: inline-block;
position: fixed;
top: 0;
right: 0;
left: 0;
max-width: 100%;
margin: 0 auto;
overflow: hidden;
width: 100%;
text-align: left;
z-index: 80;
}
Replace this code in your style sheet
You entered max-width:1341px; that is the reason it was expanded so far

how can i get drop down nav to go over content?

i'm trying to make the drop down content to get over all the content in the home page but i can't do that, i've tried to change the z-index to higher but didn't work(i believe i'm changing the wrong ones?) also tried to change position of the nav and drop down content to absolute but also didn't work , any help?
this is my HTML and CSS files :
li {
float: left;
border-right: 1px solid #bbb;
}
li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
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: 9999;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
position: absolute;
display: block;
text-align: left;
z-index: 9999;
}
body {
background: url(https://static.wixstatic.com/media/516d2c_c88a595abc2846c5bf03bfa9bfa5182a.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
#Menu-bar ul {
position: fixed;
TOP: 0px;
Left: 0px;
list-style-type: none;
margin: 0px;
overflow: hidden;
background-color: black;
opacity: 0.7;
filter: alpha (opacity=70);
z-index: 2;
}
#fix {
position: relative;
z-index: 9999;
}
nav {
background: #000000;
height: 80px;
width: auto;
margin-left: -10px;
line-height: 0px;
position: fixed;
}
.fixed {
position: fixed;
}
.nav>li>a {
text-decoration: none;
color: #ffffff;
}
.nav>li>a>img {
width: 300px;
height: 300px;
float: left;
padding: 0px;
}
.nav>li>a:hover {
color: #5F0500;
}
#wdt {
resize: none;
height: 80px;
width: 529px;
}
.middlecone {
float: right;
margin-left: 0px;
width: 100%;
height: 72%;
}
.nwsf {
text-align: right;
position: absolute;
height: 100%;
width: 50%;
float: right;
}
.box {
color: white;
border: 2px solid black;
float: left;
background-color: black;
opacity: 0.7;
filter: alpha (opacity=70);
}
#middlec {
position: absolute;
TOP: 130px;
LEFT: 380px;
height: 400px;
width: 590px;
border: 3px white solid;
overflow-x: scroll;
overflow-y: scroll;
background-color: #ffb84d;
text-align: left;
margin-top: 0px;
border-radius: 10px;
}
.jti {
height: 15%;
width: 99%;
border-radius: 3px;
margin-bottom: 1%;
text-align: left;
}
.jtiiii {
position: absolute;
TOP: 80px;
LEFT: 10px;
height: 400px;
width: 365px;
background-color: Orange;
float: right;
overflow: scroll;
}
#myMes {
display: none;
border: 1px solid;
float: right;
position: absolute;
margin-left: 78%;
background-color: #F5F5DC;
z-index: 9999;
}
#myNo {
display: none;
border: 1px solid;
float: right;
position: absolute;
margin-left: 105%;
background-color: #F5F5DC;
}
#jtiy {
text-align: center;
}
a.perss {
font-weight: inherit;
color: blue;
font-size: 13px;
text-decoration: underline;
}
<div id="fix">
<div id="Menu-bar">
<ul class="nav">
<li>
<a href="" id="homes"><img src="img/computer.png" style="position:absolute;
TOP:0px;LEFT:0px;height: 40px;width : 40px;">
</a>
</li>
<li>Profile</li>
<li>My Connections</li>
<li>All Users</li>
<li>All Jobs</li>
<li>Messages</li>
<li>Notifications</li>
<li style="float: right">
Logout</li>
</ul>
</div>
</div>
<br>
<div class="middlecone">
<div class="nwsf">
<div id="coun"></div>
<div class="jti">
<div id="myConn">
<ul id="myConn2">
</ul>
</div>
<div id="myMes">
<ul id="myMes2">
<li>1 </li>
<li>2 </li>
<li>3 </li>
<li>4 </li>
</ul>
</div>
</div>
<form name="newsfeedForm" metho="POST" style="position:absolute;
TOP:50px;LEFT:405px;height: 30px;width : 70px;">
<textarea id="wdt" type="text" name="po" placeholder="What do you think?"></textarea>
<input type="hidden" name="post_type" value="add_post">
<button type="submit" style="position:absolute;
TOP:10px;LEFT:550px;height: 50px;width : 90px;background-color: rgb(255, 165, 0);color: white;border: none;">share</button>
</form>

Space <li> evenly?

I have OCD and the following needs to be fixed (the spacing of word's in my navigation bar).
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: left;
width: 20%;
max-width: 80px;
display: block;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
All I need is the words to be evenly spread out with the image still intact in the middle like the picture dictates.
Notice how the word art is unevenly spread compared to the right side?
I am the first one to say that I am building my own website and I am new to CSS/HTML scripting.
Appreciate the help,
Thanks.
Use display: table / table-cell for the list / list items.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
Removing the float: left and the display: block from the nav ul li CSS selector and then adding
display: flex;
flex-flow: row wrap;
justify-content: space-between;
to the nav ul CSS selector will change the display from block to flexible boxes, allowing for the text to be more evenly spread out throughout the entire element
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
// float: left;
width: 20%;
max-width: 80px;
// display: block;
flex: 1;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>
EDIT:
I added a few characters around the word art in the link to give it some spacing to resemble the other links.
is how you create whitespace in HTML
Something like this (with slightly changed markup)?
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
display: flex;
height: 30px;
}
nav ul {
display: flex;
height: 30px;
margin: 0;
padding: 0;
}
nav ul:nth-child(1), nav ul:nth-child(3) {
flex: 1;
justify-content: space-between;
}
nav ul:nth-child(1)::before, nav ul:nth-child(3)::before,
nav ul:nth-child(1)::after, nav ul:nth-child(3)::after{
content: '';
}
nav ul:nth-child(2) {
width: 18%;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
max-width: 80px;
display: block;
}
nav ul:nth-child(2) li {
width: 100%;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
left: 0%;
}
<div class="navContainer">
<nav>
<ul>
<li> art </li>
<li> download </li>
</ul>
<ul>
<li><img src="http://www.pd4pic.com/images/eye-black-fan-symbol-design-sun-flower-circle.png"></li>
</ul>
<ul>
<li> portfolio </li>
<li> product </li>
</ul>
</nav>
</div>
Try this, just change the nav percentage as per your requirement. Also for more accurate results you can add media query.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 75%;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 0;
left: 0;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>

The hover for my buttons and links won’t work

I’m creating this website and I made this nav bar. It had dummy links in the anchor tags and I had a hover property on my buttons. All of this was working properly. I had made a few changes to the code and now none of it works. I cannot figure out where I went wrong. I was editing properties and things just stopped working.
* {
margin: 0 auto;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
font-family: "Arial";
color: white;
}
html,
body {
margin: 0 auto;
background-color: black;
max-width: 940px;
min-height: 100%;
}
.wrapper {
margin: 0 auto;
width: 92%;
background-image: url("images/backgrounds/wood.jpg");
}
/*********************************************************************************************************************************************
HEADER STYLING
*********************************************************************************************************************************************/
.header {
position: relative;
height: 100px;
background-color: #111111;
}
.header h1 {
position: relative;
margin: 0;
height: 20px;
text-align: center;
font-size: 2.3em;
top: 25%;
}
.header p {
position: relative;
top: 25%;
width: 100%;
font-size: 1em;
text-align: center;
}
/*********************************************************************************************************************************************
NAVIGATION BAR STYLING
*********************************************************************************************************************************************/
nav {
height: 40px;
}
nav ul {}
nav ul li {
background-color: #111111;
text-align: center;
list-style-type: none;
width: 25%;
float: left;
/*margin: 0 1%;
border-radius: 10px;
box-shadow: 5px 5px 5px #000;*/
}
nav ul li a {
text-decoration: none;
line-height: 40px;
display: block;
}
nav ul li a:hover {
background-color: #222222;
}
/*********************************************************************************************************************************************
JUMBOTRON STYLING
*********************************************************************************************************************************************/
.jumbotron {
position: relative;
background-image: url(images/jumbotron/studiopic.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
max-height: 53%;
}
.jumbotext h1 {
display: inline-block;
position: absolute;
bottom: 0px;
text-align: right;
}
/*********************************************************************************************************************************************
FOOTER STYLING
*********************************************************************************************************************************************/
.footer {
height: 100px;
width: 100%;
background-color: #111111;
}
<!DOCTYPE html>
<html>
<head>
<title>CM Sound | Home</title>
<meta charset="UTF-8">
<meta name="description" content="CM Sound's studio webpage">
<meta name="author" content="Ryan Buck | May 2015">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="header">
<h1>CM Sound</h1><br/>
<p>Create with us</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Audio</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</nav>
<div class="jumbotron">
<div class="jumbotext">
</div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
Add this in nav ul li a
:
position: relative;
* {
margin: 0 auto;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
font-family: "Arial";
color: white;
}
html, body {
margin: 0 auto;
background-color: black;
max-width: 940px;
min-height: 100%;
}
.wrapper {
margin: 0 auto;
width: 92%;
background-image: url("images/backgrounds/wood.jpg");
}
/*********************************************************************************************************************************************
HEADER STYLING
*********************************************************************************************************************************************/
.header {
position: relative;
height: 100px;
background-color: #111111;
}
.header h1 {
position: relative;
margin: 0;
height: 20px;
text-align: center;
font-size: 2.3em;
top: 25%;
}
.header p {
position: relative;
top: 25%;
width: 100%;
font-size: 1em;
text-align: center;
}
/*********************************************************************************************************************************************
NAVIGATION BAR STYLING
*********************************************************************************************************************************************/
nav {
height: 40px;
}
nav ul {
}
nav ul li {
background-color: #111111;
text-align: center;
list-style-type: none;
width: 25%;
float: left;
/*margin: 0 1%;
border-radius: 10px;
box-shadow: 5px 5px 5px #000;*/
}
nav ul li a {
text-decoration: none;
line-height: 40px;
display: block;
position: relative;
}
nav ul li a:hover {
background-color: #222222;
}
/*********************************************************************************************************************************************
JUMBOTRON STYLING
*********************************************************************************************************************************************/
.jumbotron {
position: relative;
background-image: url(images/jumbotron/studiopic.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
max-height: 53%;
}
.jumbotext h1 {
display: inline-block;
position: absolute;
bottom: 0px;
text-align: right;
}
/*********************************************************************************************************************************************
FOOTER STYLING
*********************************************************************************************************************************************/
.footer {
height: 100px;
width: 100%;
background-color: #111111;
}
<div class="wrapper">
<div class="header">
<h1>CM Sound</h1><br/>
<p>Create with us</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Audio</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</nav>
<div class="jumbotron">
<div class="jumbotext">
</div>
</div>
<div class="footer">
</div>
</div>
nav {
height: 40px;
position: relative;
}
just add the position relative to nav