Header navigation with background images - html

I am trying to create a header + navigation that should look like this:
However, I found some difficulties completing the task. What I have done so far, is to set a solid background for the header. Then, add the jagged (weave look-alike things) with ::before and ::after elements (also with background pictures) and so far it looks great, except that when I hover over an element, the :before and :after elements don't get colored with the same color as the hovered element (as the example in the picture).
Is my approach, the correct one or am I missing something? I have also thought about creating an Overlay Div on top of the whole header, but then issues will appear on different resolutions and also, I do not think that this fixes the original issue, different color on hover.
Do you guys have any ideas that could help, or materials that did I did not manage to find on the web?
Here is my code: https://jsfiddle.net/nbrLck99/1/
.main-nav::after {
content: '';
position: absolute;
top: 100%;
background-image: url('../images/desktop-header-background.png');
background-repeat: no-repeat;
background-size: cover;
background-position: center bottom;
height: 10px;
display: block;
width: 100%;
}
EDIT: managed to upload and tun the image in jsfiddle.

This won't work.
Your :after element is a background image. This means it isn't affected by by the background-color attribute. You'll have to create an :after element for every menu item and then alter it's background image with the :hover selector. You'll need an image for the default background and one for the hovered one. If you wish to have different "waves" you can create an image for each tab.
A quick preview:
.main-nav {
position: relative;
}
/* magic starts */
.level_1 > li > a::after {
content: '';
position: absolute;
top: 100%;
background-image: url('https://i.imgsafe.org/a58a017b5d.png');
background-repeat: no-repeat;
background-size: cover;
background-position: center bottom;
height: 10px;
display: block;
width: 100%;
}
.level_1 > li:hover > a::after {
background-image: url('http://i.imgsafe.org/a5f53cc8bf.png');
z-index: 10;
}
/* magic ends */
.main-nav .level_1 {
margin: 0;
display: inline-block;
background-color: #0E5780;
width: 100%;
position: relative;
}
.main-nav .level_1 li {
position: relative;
}
.main-nav .level_1 li:hover {
background-color: #f00;
}
.main-nav .level_1 > li {
display: block;
float: left;
padding-top: 15px;
padding-bottom: 15px;
}
.main-nav .level_1 li a {
display: block;
padding: 10px;
}
.main-nav ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
padding-top: 15px;
background-color: #0f0;
}
.main-nav .level_1 > li:hover ul {
display: block;
}
<div class="container">
<nav class="main-nav">
<ul class="level_1">
<li class="dropdown">
home
<ul class="level_2">
<li>something</li>
<li>something</li>
<li>something</li>
<li>something</li>
</ul>
</li>
<li>about</li>
<li>something</li>
<li>something</li>
<li>something</li>
</ul>
</nav>
</div>

Related

Not able to hover over dropdown-menu

I have have made a site which has a dropdown menu. The rest of the web page doesn't change when the dropdown menu is called for because I have given the page position:relative;.
And the dropdown has a higher z-index than the page so it is visible at all times. The only problem I have is that I also want to change the background-color of the dropdown-menu when someone hovers over it.
But unfortunantely, when I hover over the dropddown, the browser thinks that I am hovering over the page and for some reason doesn't understand that I am actually hovering over the dropdown-menu. Can anyone please help me with this.
#page {background-color;
height: 2500px;
width: 1600px;
margin: auto;
position: relative;
}
#dropdown {
margin: 0px;
}
.dropdownitem {
opacity: 0.7;
z-index: 1;
background-color: red;
}
.dropdownitem:hover {
background-color: aqua;
color: white
}
I think I have come to understand what the problem is. The thing is that I have a div with
position:absolute
And inside that div there are a number of list items. Because my parent div has absolute positioning, the element has been taken out of document flow and when I hover over the list items, the :hover pseudo class does not work on those nested list items. So now I have found the reason, but what only rests is the solution, and I haven't yet found that.
This may help
ul,
li {
padding: 0;
margin: 0;
}
li {
list-style: none;
padding: 1em;
}
#page {
margin: auto;
position: relative;
}
.mainmenu,
.submenu {
border: thin solid darkgray;
text-align: center;
}
.submenu {
display: none;
}
.mainmenu:hover>.submenu {
position: absolute;
top: 50px;
left: 0;
display: inline-block;
}
.mainmenu,
.dropdownitem {
width: 4em;
}
.dropdownitem {
opacity: 0.7;
background-color: red;
}
.dropdownitem:hover {
background-color: aqua;
color: white
}
<div id="page">
<nav>
<ul id="dropdown">
<li class="mainmenu">Main
<ul class="submenu">
<li class="dropdownitem">One</li>
<li class="dropdownitem">Two</li>
</ul>
</li>
</ul>
</nav>
</div>

CSS: background image opacity in ul-li menu

I have a menu using ul/li items, and they have a background image.
All over the Internet, and in stackoverflow, there is information on how to hack background image opacity. For example: https://scotch.io/tutorials/how-to-change-a-css-background-images-opacity
But not for my particular use case when using menus. It seems particularly tricky. From everything I have tried, one of the solutions in the aforementioned website seems to work the best.
But still, the image is not vertically aligned. I cannot seem to be able to center the image in the menu...
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {float: left;}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {background-color: #4CAF50;}
.my-container {
position: relative;
overflow: hidden;
}
.my-container a {
position: relative;
z-index: 2;
}
.my-container img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: auto;
opacity: 0.2;
}
<ul>
<li><div class="my-container">Aaaa <img src="http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png"></img></div></li>
<li><div>Bbbb</div></li>
<li><div>Cccc</div></li>
<li><div>Dddd</div></li>
<li><div>Eeee</div></li>
</ul>
Hi,Please try this one.
If we will use top:-14px,It will affecting the modern browser like chrome and safari which is not accepting negative values.So we can use below format for background images.
.my-container {
background-image:url("http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png");
background-size:cover;
background-repeat:no-repeat;
background-position:center;
}

ul based nav not working in iOS Safari / Chrome

Weird problem with a navigation area. It works on all desktop browsers, but not on iOS Safari and Google Chrome. Tapping the links does nothing, although tap-and-hold will show the popup-menu asking to open the link in a new window, so in that case it does get recognised as a link.
Can anyone spot what I'm doing wrong?
Thanks for any help!
HTML:
<div id="nav">
<h1>Site title<span></span></h1>
<ul>
<li id="nav-reserveren">reserveren</li>
<li id="nav-kalender">kalender</li>
<li id="nav-interieur">interieur</li>
<li id="nav-contact">contact</li>
</ul>
</div>
Relevant CSS:
#nav h1 {
text-indent: -9999px;
font-size: 0;
margin: 0;
padding: 0;
width: 451px;
height: 81px; /*same as span height*/
position: relative;
}
#nav h1 span a {
position: absolute;
top: 0;
left: 0;
display: block;
width: 451px;
height: 81px;
}
#nav ul {
position: absolute;
left: 461px;
top: 14px;
list-style-type: none;
}
#nav ul li {
display: inline;
}
#nav ul li a {
float: left;
height: 60px;
text-indent: -9999px;
}
#nav ul li#nav-reserveren a {
width: 203px;
background: transparent url(../img/nav/reserveer.png) top left no-repeat;
}
#nav ul li#nav-kalender a {
width: 109px;
background: transparent url(../img/nav/kalender.png) top left no-repeat;
}
#nav ul li#nav-interieur a {
width: 96px;
background: transparent url(../img/nav/interieur.png) top left no-repeat;
}
#nav ul li#nav-contact a {
width: 90px;
background: transparent url(../img/nav/contact.png) top left no-repeat;
}
Edit: solved.
The problem was setting the opacity of the links in jQuery:
var navLink = $('#nav ul li a');
navLink.css('opacity', '0.8');
navLink.mouseover(function(){
$(this).css('opacity', '1');
});
navLink.mouseout(function(){
$(this).css('opacity', '0.8');
});
$('#nav ul li a.active').css('opacity', '1');
Moving this over into straight CSS did the trick!
As h1 is a block element with relative and ul is absolute. the ul tends to go under the h1 making the links not clickable.
-> add display:inline-block to h1
or
-> add some z-index (above 1) to ul
Either one should fix the issue.

Fill empty div with background and expand dimensions of parent a tag

I have a navigation which holds either text or images for links. I want the image to change on hover, so am using CSS backgrounds inside an empty div. However, I am looking for a way of doing this without using "position: absolute;" as the containing a tag will not expand to fill its dimensions. I would also like to do this without using a transparent placeholder image as I want to find a more elegant solution.
Here's the jsfiddle and the code:
http://jsfiddle.net/urhLs736/1/
<nav id="navigation">
<ul>
<li><a onclick="example1.html">PAGE 1</a></li>
<li><a onclick="example2.html">PAGE 2</a></li>
<li><div id="nav-image"></div></li>
</ul>
</nav>
and for the CSS:
#navigation {
z-index: 1;
background-color: #3A5E90;
color: #FFFFFF;
text-align: center;
width: 100%;
padding-top: 5px;
padding-bottom: 5px;
}
#navigation.fixed {
position: fixed;
top: 0px;
}
#navigation li {
display: inline;
}
#navigation a {
cursor: pointer;
padding-left: 3.5%;
padding-right: 3.5%;
color: #FFFFFF;
text-decoration: none;
}
#navigation a:hover {
background: #FFFFFF;
color: #3A5E90;
padding-top: 2%;
padding-bottom: 2%;
}
#nav-image {
display: inline;
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
margin-bottom: -6px;
height: 24px;
width: 100px;
}
#nav-image:hover {
height: 24px;
width: 100px;
background: url('https://avatars3.githubusercontent.com/u/5278945?v=2&s=96') no-repeat;
background-size: 100%;
}
I think that your layout will work as is with a minor adjustment to the CSS:
#nav-image {
display: inline-block;
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
margin-bottom: -6px;
height: 24px;
width: 100px;
border: 1px dotted yellow;
}
If you use display: inline-block, the div will take up the specified width and height and the background image will be visible, and the hover effect will work as you expect.
See demo: http://jsfiddle.net/audetwebdesign/9fd1dxn4/
In order to achieve this, you have to change both your HTML and your CSS.
First, your HTML should go like this:
<nav id="navigation">
<ul>
<li><a onclick="example1.html">PAGE 1</a>
</li>
<li><a onclick="example2.html">PAGE 2</a>
</li>
<li id="nav-image">PAGE 3
</li>
</ul>
</nav>
Note that I have added some content in your empty div. If you have an empty <li>, you'll have no background at all (just like your example) since you have a 0x0 pixels li element. I have added some content so the li displays as a general rule, which anyways won't be necessary after you see the CSS, which is the following:
#navigation {
z-index: 1;
background-color: #3A5E90;
color: #FFFFFF;
text-align: center;
width: 100%;
padding-top: 5px;
padding-bottom: 5px;
}
#navigation.fixed {
position: fixed;
top: 0px;
}
#navigation li {
display: inline-block;
height: 24px;
width: 100px;
padding-left: 3.5%;
padding-right: 3.5%;
}
#navigation ul li a {
cursor: pointer;
padding:2% 3.5%;
color: #FFFFFF;
text-decoration: none;
display:block;
height: 24px;
width: 100px;
}
#navigation a:hover {
background: #FFFFFF;
color: #3A5E90;
}
#nav-image {
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
}
#nav-image:hover {
background: url('https://avatars3.githubusercontent.com/u/5278945?v=2&s=96') no-repeat;
background-size: 100%;
}
#nav-image:hover a {
background:transparent
}
OK, now you see I have made some changes and added width and height to the li (the same you had in your sample, but you can change it to anything you want). Now, if you delete the content inside the empty DIV, you'll see how the rendering changes. While it's very easy to solve, I'll leave it to you so you can practice and understand how the whole positioning and display thing works. Also, you can add paddings, margins, et
Here you have a fiddle so you can see it in action and play around

Why doesn't this image sprite menu display properly, and why aren't the links working?

The code validates. There should be two more images in the menu on the left, above the visible one of the silo. And each should be a link.
http://www.briligg.com/agnosticism.html
css is: external style sheet:
.menu {
position: relative;
float: left;
margin: 10px;
padding: 0;
width: 150px;
}
.menu li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
left: 0;
top: 260px;
}
.menu li, .menu a {
width: 150px;
height: 150px;
}
internal style sheet:
.menu {
height: 450px;
}
.mirror {
top: 0;
}
.mirror {
background: url(http://www.briligg.com/images/menu-ag.png) 0 0;
}
.wormcan {
top: 151px;
}
.wormcan {
background: url(http://www.briligg.com/images/menu-ag.png) 0 -151px;
}
.wormsilo {
top: 301px;
}
.wormsilo {
background: url(http://www.briligg.com/images/menu-ag.png) 0 -301px;
}
html:
<ul class="menu">
<li class="mirror">
</li>
<li class="wormcan">
</li>
<li class="wormsilo">
</li>
</ul>
In your internal stylesheet, you have to specify better. Because .menu li is very specified, it overruns .wormcan.
Try .menu li.wormcan in the internal stylesheet.
Haven't tested this, but from a quick look, this seems to be the problem.
Hum - maybe you should try setting the links (.menu a) to display: block to have the links working properly. Otherwise the link won't stretch to use the specified size, links are inline elements (correct me if I'm wrong, didn't test it).