Roberts Šensters
Roberts Šensters

Reputation: 605

Content scrolling over fixed header (Responsive)

I need content to start just after my header image. It's working for static page, but the problem is that my website is scaleable, so if someone go to my website from iPhone everything will scale smaller but the option TOP will still stay 300px and will make a bigger gap between header and content. Here is my code. HTML

<div id="container">

    <div id="header"><img src="galvena.jpg"/></div>

    <div id="content">
        <div class="text">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
        </div>
    </div>  
</div>  

CSS

body{font-family: 'Roboto', sans-serif;font-size:3.6vmin;margin:0}
img{max-width:100%;height:auto;margin:0;padding:0}
#container{margin:0 auto;max-width:500px;}

#header {
    position:fixed;
    z-index:100;
    max-width: 500px;
}

#content {
    top:300px;
    position:relative;
    z-index:200;
    width:100%;
    margin:0 auto;
    background-color:white;
}

.text {
    width:90%;
    margin:0 auto;
}

Demo: http://jsfiddle.net/L9quzntt/

Upvotes: 0

Views: 1171

Answers (1)

Huelfe
Huelfe

Reputation: 1836

With using jQuery, we can easily get the height of the image and set this value as top value of our content div. Have a look at this jsfiddle.

HTML:

<div class="flex-container">
    <div class="large-flex-item"></div>
    <div class="flex-container-inner">
        <div class="small-flex-item"></div>
        <div class="small-flex-item"></div>
    </div>
</div>

CSS:

html {height: 100%;}
body{font-family: 'Roboto', sans-serif;font-size:3.6vmin;margin:0; height: 100%;}
img{max-width:100%;height:auto;margin:0;padding:0}
#container{margin:0 auto;max-width:500px; height: 100%; }

#header {
    position:fixed;
    z-index:100;
    max-width: 500px;
}

#header img {
    width: 100%;
}

#content {
    top:60%;
    position:relative;
    z-index:200;
    width:100%;
    margin:0 auto;
    background-color:white;
    height: 90%;
}

.text {
    width:90%;
    margin:0 auto;
}

JS:

(function($) {
    $(window).load(function() {
        $('#content').css('top',$('#header img').height()+'px');
    });
    $(window).resize(function() {
        $('#content').css('top',$('#header img').height()+'px');
    });
})(jQuery);

Upvotes: 1

Related Questions