Reputation: 285
I am trying to make a similar effect as Voets Design has done with their full width image being pushed down by the navigation.
See here: http://www.voetsdesign.com/
So far the navigation and image is looking good; the only problem is that the image isn't being pushed down since it is `position: absolute.
The mark-up:
<nav class="clearfix">
<div class="nav-wrapper">
<ul class="clearfix">
<li><a href="#">Home</a></li>
<li><a href="#">How-to</a></li>
<li><a href="#">Icons</a></li>
</ul>
<a href="#" id="btn">click</a>
</div>
</nav>
<div class="image"></div>
See this fiddle: https://jsfiddle.net/uvxb53z8/1/
Hope someone has a solution.
Upvotes: 0
Views: 248
Reputation: 1810
Two main problems that prevented your example from working:
nav
had a position: absolute
applied to it (two times, also in a media query). This way it'll never affect layout of other elements as it's been taken out of document flow. You need relative
for that. You'd see on http://www.voetsdesign.com/ that .project-panel-header
(the element that is pushing down the image) also has position: relative
set.
Apart from that, nav
also had a fixed height (40px). It probably would never push down your image anyway because of that, no matter how high its content might be.
$(function() {
var btn = $('#btn');
menu = $('nav ul');
menuHeight = menu.height();
$(btn).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function(){
var w = $(window).width();
if(w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
/* Clearfix */
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
/* Basic Styles */
html {
height: 1500px;
}
body {
background-color: #ece8e5;
margin: 0;
}
/******** NAVIGATION ********/
nav {
width: 100%;
font-size: 11pt;
font-family: Arial, sans-serif;
font-weight: bold;
position: relative;
z-index: 9;
display:block;
}
.nav-wrapper {
width: 100%;
margin: 0px auto;
background-color: #455868;
}
.logo {
width: 150px;
height: 40px;
background: #0CC;
position: absolute;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 300px;
height: 300px;
}
nav li {
display: inline;
float: left;
}
nav a {
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 1px 1px 0px #283744;
}
nav li a {
border-right: 1px solid #576979;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: transparent;
}
nav a#btn {
display: none;
}
/******** FULLSCREEN BCK ********/
.image {
background-image: url(http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg);
background-position: center center;
background-repeat: no-repeat;
position: absolute;
width: 100%;
height: 100%;
background-size: cover;
background-color: #2b6c72;
}
/*Styles for screen 515px and lower*/
@media only screen and (min-width : 320px) {
nav {
border-bottom: 0;
}
nav ul {
display: none;
margin: 0 auto;
width:300px
}
nav a#btn {
display: block;
background-color:#000;
width: 100%;
position: absolute;
height:40px
}
nav a#btn:after {
content:"";
background: url('nav-icon.png') no-repeat;
width: 30px;
height: 30px;
display: inline-block;
position: absolute;
right: 15px;
top: 10px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<nav class="clearfix">
<div class="nav-wrapper">
<ul class="clearfix">
<li><a href="#">Home</a></li>
<li><a href="#">How-to</a></li>
<li><a href="#">Icons</a></li>
</ul>
<a href="#" id="btn">click</a>
</div>
</nav>
<div class="image"></div>
Upvotes: 1
Reputation: 130
Please don't go for a solution where you animate with javascript. Just add a class to the container and give the container an overflow: hidden;
Then you can animate the image's bottom property with a negative margin and the navigation's height property, assuming the navigation also has a hidden overflow.
Upvotes: 0
Reputation: 5919
one solution, just to help out a little (and I'm a little bit busy myself atm):
CSS:
.image.toggled{
top: 300px;
}
jQ:
$(btn).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
$('.image').toggleClass('toggled');
});
https://jsfiddle.net/uvxb53z8/2/
Second solution would be to wrap the content with the element that drops down.
Upvotes: 0