So all I'm trying to do here is add a simple footer to my site which works perfectly when open on desktop but when on tablet or mobile whenever the keyboard is open such as they login the footer moves up the page to just above the keyboard. Is there a method of fixing this, any ideas?
CSS
#footer {
width: 100%;
background-color: #4c66a4;
color: #fff;
position: absolute;
left: 0px;
bottom: 0px;
text-align: center;
}
<div id="footer">
<p>© 2018 SulmaxCP. All Rights Reserved.</p>
</div>
Try using a wrapper inside the body tag.
html,body{
height:100%;
}
.wrapper {
min-height: 100%;
position: relative;
padding-bottom:90px; /* footer's height */
}
#footer {
width: 100%;
background-color: #4c66a4;
color: #fff;
position: absolute;
left: 0px;
bottom: 0px;
text-align: center;
}
<div class="wrapper">
<main>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis necessitatibus earum tenetur itaque ducimus atque nam vitae ab non quasi natus quam, cum hic quod possimus quibusdam inventore minima temporibus.</div>
<div>Optio inventore delectus quas rerum mollitia eum, repellendus voluptatum! Quos, quas nobis delectus, ipsa tempore reiciendis dolore numquam sequi tempora, nostrum in mollitia laboriosam odio labore voluptatem sint. Similique, aliquam.</div>
<div>Sapiente quisquam vitae alias in nesciunt numquam id, distinctio! Doloribus error mollitia, optio debitis ratione quaerat maiores odio nostrum autem commodi tempora magnam, quos necessitatibus nobis aperiam consequuntur perspiciatis deserunt.</div>
<div>Hic facere nam aliquam tenetur officiis, ratione, sunt aliquid perspiciatis distinctio laborum perferendis nisi ullam omnis incidunt, quasi illo corrupti, dolores eius vero ipsum tempore. Tempora consequatur necessitatibus, saepe assumenda.</div>
<div>Eveniet, odit deleniti neque voluptates soluta architecto, quae aspernatur aut minima rerum itaque nobis distinctio ex culpa! Dolore sit vel mollitia aspernatur distinctio voluptatibus! Iste perspiciatis, aliquid a doloribus et.</div>
<div>Molestias, ducimus! Magni doloribus fugiat praesentium dolore minus perferendis, reprehenderit voluptatibus fuga, rerum quam eveniet, odit ut eaque, repellat provident aperiam repudiandae. Quos porro eveniet, dignissimos non quibusdam provident eligendi!</div>
<div>Ducimus unde ea iste alias fugiat debitis natus illo eligendi! Nisi dolor esse totam optio, tenetur distinctio, sequi inventore eaque iure earum suscipit quam ipsam qui quae molestias id expedita!</div>
<div>Veritatis delectus, in laudantium. Excepturi, deserunt! Ullam voluptatem aliquid doloribus ab, officia veniam maiores magnam maxime. Vero esse non dicta autem, aliquam eos dolore harum sed incidunt architecto placeat eaque!</div>
<div>Hic veniam porro autem quia, commodi provident sunt, at tempore libero, consequuntur, accusamus. Vero illo molestias nam, velit hic iure, a sequi, explicabo ipsum voluptates numquam modi dolorum rem culpa!</div>
<div>Iusto a cum nihil eos atque, impedit, debitis quis dolor consectetur ratione ipsam nisi recusandae temporibus possimus. Non, natus a, consequuntur provident facilis nemo assumenda dolorum vitae, eligendi et harum.</div>
</main>
<div id="footer">
<p>© 2018 SulmaxCP. All Rights Reserved.</p>
</div>
</div>
The thing is that footer relating his position from body tag and when keyboard appears body's height changes and footer get on keyboard.
In this type of situation, unfortunately, CSS seems to not have a fix. So you must use javascript to first calculate the height of the window in pixels and then set the css property. You could do it in one line! But I did it in two here:
// PUSH FOOTER TO BOTTOM
var innerScreenHeight = window.innerHeight;
document.querySelector("#footer").style.top = innerScreenHeight + "px";
This is a cheap hacky fix, but:
CSS:
#media screen and (max-width: 800px) {
.hide-footer {
display: none;
}
}
jQuery
$('input').focus(function() {
$('footer').addClass('hide-footer');
});
$('input').focusout(function() {
$('footer').removeClass('hide-footer');
});
This adds the class .hide-footer to your footer as soon as you focus on an input tag. In addition, the footer is only hidden when the screen width is less than 800px (you should customize, but this should cover mobile devices).
You can hide the footer when you focus on input filed and show again footer on focus out of input filed using jquery.
$( "#inputID" ).focus(function() {
$("#footer").hide();
});
$( "#inputID" ).focusOut(function() {
$("#footer").show();
});
You can't fix it because there's nothing wrong, your footer is doing exactly what you've told it to do.
Your CSS rule for the footer is telling it to always 'attach' to the bottom of the window, even when the keyboard on a mobile device is visible, the top of the keyboard is now the bottom of the window.
If you want, you can either remove the position:absolute value or just change it to position:fixed
Another solution might be to add event listeners for focusin and focusout events of the input-element. The respective listener callbacks can then implement some logic to show or not to show the footer.
Related
First of all, excuse me for my level of English, I'm French and you know our reputation :)
So here is my problem:
I'm trying to customize my scrollbar but with an image I've tried many things to do it but I don't really know java and the only guide I've seen was only in java...
I don't know how to do it so if you have any advice don't hesitate to send it.
thanks
For this issue, you'd want to use the webkit scrollbar css api. Please keep note that this api isn't available for both Microsoft Edge and Firefox. For more information, please visit this url. Below is an example for your case:
.main {
width: 250px;
height: 300px;
padding: 2px;
overflow-y: scroll;
border: 2.5px solid black;
}
p {
margin: 0;
}
.main::-webkit-scrollbar {
/* this sets the width of the bar, in the div.main (::-webkit-scrollbar is fro the body/html)*/
width: 20px; /* change for scrollbar width */
}
.main::-webkit-scrollbar-track {
/* scrollbar background */
background-color: lightgray;
}
.main::-webkit-scrollbar-thumb {
background-color: red; /* will leave after image loads */
background-image: url("https://picsum.photos/100/400");
background-size: cover;
}
.main::-webkit-scrollbar-thumb:hover {
/* feel free to set this for when the mouse is over the bar */
}
<div class="main">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Non asperiores
quos, suscipit officiis, impedit sapiente unde modi quia voluptatibus, id
cupiditate nesciunt. Officia, in animi distinctio commodi perspiciatis ad
eligendi! Earum ab porro perferendis inventore, asperiores quaerat quis
voluptate ducimus odio officia numquam nobis ipsum consectetur deleniti
natus aspernatur, a temporibus illo culpa quia, similique iste quas sunt.
Architecto, rerum. Qui, nostrum. Molestias, placeat maiores dignissimos id
laboriosam eos error possimus voluptas ipsum aut rerum culpa nesciunt
quaerat ipsam sapiente veniam exercitationem dolorum esse illo explicabo
similique? Labore, ab aperiam. Blanditiis animi qui velit nobis fugit! Eius
laborum necessitatibus aperiam sequi explicabo! Alias, neque. Ad veniam
dolor, doloribus assumenda laboriosam vel necessitatibus minima dolorum fuga
ipsa beatae quos, distinctio debitis? Voluptate, neque. Fugiat accusamus,
excepturi, quam aliquid beatae consectetur laboriosam commodi nesciunt et
dolor delectus illo perferendis sapiente ab voluptatem dicta quod! Laborum
possimus sapiente repellat itaque ex facere recusandae?
</p>
</div>
I am designing a code documentation webpage having a similar design like stackoverflow. I am listing the details below:
fixed header
sticky sidebar.
The sidebar is an anchor menu linking to each section header.
The problem is that when I click on a link, the page jumps to the corresponding section, but the header is hidden behind the fixed header.
* {
margin: 0;
}
header {
position: fixed;
padding: 1em;
width: 100vw;
background-color: #ccc;
}
main {
padding-top: 6em;
width: 700px;
margin: auto;
}
section {
margin-bottom: 3em;
}
<header>
<h1>Title</h1>
</header>
<main>
Click me to visit - Eaque, voluptatum tempore.
<section>
<h2>Lorem, ipsum dolor.</h2>
<br>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Tempore unde animi ratione inventore laudantium architecto nobis voluptates rem sed veritatis eaque eum id ab eligendi, ipsum earum a, fuga impedit consequuntur, iste officia voluptate commodi?
Asperiores illo repellendus earum laboriosam accusamus ex amet delectus quo voluptatibus, temporibus natus dolores praesentium dignissimos. Excepturi optio praesentium corrupti vitae ratione tenetur dolores voluptatem.</p>
</section>
<section>
<h2>Accusamus, saepe nam?</h2>
<br>
<p>Distinctio quo tenetur molestiae asperiores! Ratione tempore recusandae mollitia et maiores, veritatis in animi officiis consectetur, quo reprehenderit possimus porro maxime amet modi deserunt iste. Qui vitae quasi tenetur totam adipisci unde deleniti
commodi iure beatae recusandae esse, explicabo incidunt placeat. Nemo, dolore? Perferendis expedita omnis consectetur facilis enim voluptate ratione ad consequuntur minus, ea debitis, itaque quas fugit minima?</p>
</section>
<section>
<h2>Soluta, at officiis.</h2>
<br>
<p>Eum accusantium, rerum nulla, esse in quas consequuntur earum a culpa voluptates repellendus? In repellendus quasi quam, nesciunt, ullam adipisci autem reiciendis rem laborum eos repudiandae. Dolores quasi ducimus quis, iusto laborum nihil. Temporibus,
ratione iure sequi exercitationem voluptates id expedita ut quo repellat dolorum, officiis mollitia accusantium? Debitis, nobis. Quo exercitationem est impedit aliquam, a expedita saepe totam? Non.</p>
</section>
<section>
<h2>Mollitia, modi deleniti!</h2>
<br>
<p>Earum iusto nesciunt, rerum laboriosam velit, cumque perferendis accusamus laborum officia voluptates enim at quidem beatae. Asperiores soluta ullam aperiam suscipit tenetur officiis blanditiis cumque. Laboriosam ut itaque magni a voluptatibus, tenetur,
consequuntur temporibus rem obcaecati consectetur at laborum, hic perspiciatis aliquid voluptate excepturi minima voluptates eius iste. Possimus culpa sit expedita. Esse quos ipsum recusandae, unde laudantium repudiandae ipsa!</p>
</section>
<section>
<h2 id="link">Eaque, voluptatum tempore.</h2>
<br>
<p>Excepturi, fugit ipsam nesciunt neque harum a magnam adipisci eius velit. Dignissimos praesentium voluptatem laboriosam corporis minus soluta aperiam eius repellendus architecto pariatur vitae dolores ipsam consectetur eligendi optio fugit laborum
ratione aliquam provident tenetur explicabo qui, officiis veniam. Ipsum minima molestias quibusdam quos delectus voluptates. Et rerum quia modi? Corrupti corporis minus necessitatibus quod earum, cupiditate amet porro eveniet.</p>
</section>
</main>
How can I fix this so that the header is visible?
I am answering my own question since I found out a better solution to the problem.
So, to fix this, we can use the pseudo class :before.
.anchor:before {
display: block;
content: "";
height: 5em;
width: 0;
position: relative;
margin-top: -5em;
}
Why shouldn't we use padding?
Adding a padding to the top will solve the problem for some cases, but it may add too much white space. Whereas, using :before, we don't need to think about it.
The answer above is better. Use :Before.
Old answer:
Put this above your header:
<h1><a class="anchor" name="anchor">Bar</a></h1>
with these CSS:
.anchor { padding-top: $your amount of padding$ px; }
I feel like this should be a really simple problem, but I can't seem to figure it out.
HTML:
<div class="outer">
<div class="inner">
<!-- lots of text -->
</div>
<div class="inner-bottom">
This text should be inside the blue background
</div>
</div>
CSS:
.outer {
height: 300px;
background: #99EEFF;
}
.inner {
height: 100%;
overflow: scroll;
}
.inner-bottom {
text-align: center
}
Fiddle
The goal is to have both inner divs display inside their parent, which has a background specified to visually organize them.
If I don't specify height: 100%; on .inner, it overflows, no matter which I set on the display property. In fact, some values of display even cause height: 100% to not work.
Anyway, I'd really like .inner's size to be dictated by .outer's size, rather than vice versa. How do I do this?
You can do this with Flexbox just use flex: 1 on .inner
body {
margin: 0px;
}
.outer {
height: 300px;
flex-direction: column;
display: flex;
background: #99EEFF;
}
.inner {
flex: 1;
overflow-y: scroll;
}
.inner-bottom {
text-align: center
}
<div class="outer">
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis fugiat nulla asperiores rerum sed dignissimos vitae odit consectetur perferendis! Suscipit qui hic iste est tempora blanditiis odit distinctio odio quas amet. Fuga mollitia maxime labore non odio laborum ea facilis distinctio blanditiis exercitationem atque et, facere illo repellat praesentium inventore iure. Minus error expedita veritatis doloribus esse, at cum molestias odit saepe animi harum similique, dolore distinctio est a quidem beatae! Aliquam, similique autem ipsa vitae eligendi iure consectetur. Quasi, odio expedita consequatur, maxime, libero maiores incidunt quia debitis hic provident cum, deleniti? Illo id pariatur, recusandae tenetur! Beatae cum, fuga! Nulla animi deserunt molestiae eum quia dolorum necessitatibus quod eos saepe sint eaque id est cupiditate impedit, doloribus consequuntur ipsum maiores consequatur alias. Magnam accusantium ab quia laudantium iste eum nobis sequi error, atque suscipit repellendus officiis laboriosam alias eos ullam. At inventore quam ullam officia sequi, aliquam. Aperiam dicta eum illo tempora, quas doloribus ducimus sequi placeat, aut id quaerat iure officiis nostrum accusamus atque odio repudiandae saepe autem distinctio. Qui expedita cum animi totam maxime minima labore vitae reprehenderit eligendi porro odio, voluptatem obcaecati sint enim, velit dolores, dolore fugit incidunt sit. Doloremque suscipit, quia libero. Odit nihil beatae eaque suscipit aperiam hic tempore ipsam non quam doloremque, nesciunt voluptate laboriosam a animi assumenda iste velit sunt cumque minima. Quos perferendis, labore. Consectetur quod sequi commodi nesciunt suscipit, molestiae, quia est cum. Beatae nulla, suscipit ducimus nobis voluptas illum enim dicta distinctio similique aliquam sapiente impedit ea non corrupti omnis est obcaecati labore laboriosam quaerat tempora molestias sunt laudantium doloremque? Perspiciatis dolore, excepturi, voluptate nulla nam culpa nostrum dolor, rerum quas iure dolorem incidunt consequatur dolores dolorum laborum ipsam eaque quasi accusamus voluptatum voluptates quisquam. Perspiciatis maxime, assumenda itaque eligendi dolore iste libero debitis ea sint expedita eius illum blanditiis inventore officiis voluptates minima iusto fuga nulla veritatis quo deserunt ad quisquam. Cumque numquam nihil tenetur itaque obcaecati soluta, libero possimus dolore ipsa eum neque amet sunt ad sapiente quos quae deleniti voluptas illo molestiae. Nihil officiis, commodi fugiat architecto blanditiis! Atque neque numquam nobis voluptates accusantium libero tempore veniam fugit officiis alias soluta rem enim, totam aut eos, nam. Fuga labore fugiat, suscipit consequatur ipsum quia praesentium. Reprehenderit praesentium maxime, ea maiores repellat, facere architecto quasi vitae a hic similique impedit commodi dolor, quas necessitatibus saepe ipsum. Nulla distinctio corporis dolor praesentium eum laudantium, asperiores magni minus tempora, iusto veritatis fuga. Totam ratione incidunt, neque blanditiis iure corporis consectetur ea dignissimos nesciunt tenetur ab placeat, harum eaque laboriosam numquam quas ipsum! Earum aperiam, voluptatibus assumenda quisquam dolorem ut eius non provident numquam nostrum rerum, magnam voluptatum beatae quibusdam quasi ad consequuntur perspiciatis fugiat soluta ipsa excepturi! Earum, accusamus quidem! Quos, eaque inventore perferendis quia officiis tempore sequi repellendus incidunt quo, numquam aut mollitia, atque earum architecto. Harum ipsa debitis necessitatibus quos sapiente ad deleniti quod non nihil libero iure voluptatem, omnis possimus tempore eos recusandae! Provident modi nulla dicta, aut possimus dolores nesciunt officiis sunt! Sunt!
</div>
<div class="inner-bottom">
This text should be inside the blue background
</div>
</div>
Flexbox is the way to go here, but if you want a non-flex answer: If you are assigning 300px to the outer div then you can assign fixed pixel values to the inner divs. how big do you want them to be? You can do:
.inner {
height: calc(100% - (insert height of .inner-bottom));
}
Or you can just use percentages that add up to 100 for the height of both elements. Or you can just use pixels that add up to 300. Your call.
You can set the height of the inner element , that is the best way
.inner {
height: 275px;
overflow-y: auto;
}
Use a padding bottom to the parent element, that is 'outer' class.
.outer {
height: 300px;
background: #99EEFF;
padding-bottom: 30px;
}
The text in the inner-bottom is out of the blue background, because the .inner div takes up all available height in the .outer DIV.
If you set the height of the .inner DIV to less than 100%, there will still be some space for the .inner-bottom to fit in the .outer DIV.
So, changing
height: 100%
to for example
height:65%
in the .inner should work.
PS. You can change the 65% to any value less than 100% and it should still work properly.
I figured out a simpler, more dynamic, and more cross-compatible approach using tables.
HTML:
<div class="table">
<div class="tr greedy">
<div class="td">
<div class="scrollable">
<!-- Lots of text -->
</div>
</div>
</div>
<div class="tr">
<div class="td centered">
Text should be inside the blue box
</div>
</div>
</div>
CSS:
.table {
display: table;
height: 300px;
background: #99EEFF;
}
.tr {
display: table-row;
}
.td {
display: table-cell;
}
.scrollable {
max-width: 100%;
max-height: 100%;
overflow: auto;
}
.greedy {
height: 100%;
}
.centered {
text-align: center;
}
I created a container inside another container that has position:absolute and top:100%. This container is used to be some kind of fade-out-container, so it actually has no real content.
Now when this containers height exceeds the browser windows height, a scrollbar appears. And this is exactly what should not happen.
Instead I thought I could apply overflow:hidden on body or the parent container, but either too much gets cut off or the fade-out-container itself becomes invisible.
Please have a look at my fiddle and tell me what I'm missing. Thanks!
HTML
<header>
<h1>Demo</h1>
</header>
<footer>
<p>
The orange container wraps the blue one.<br/>The blue containers' height is meant to be cut off of the browser window meaning it's overflow should get hidden if the browser windows' height is insufficient.
</p>
<p>position: relative;<p>
<div class="append gradient">
<p>position: absolute;<br/>
top: 100%;<br/>
left: 0;<br/>
width: 100%;<br/>
height: 100%;</p>
</div>
</footer>
...
CSS
body {background: 333;}
header, footer, .append {
font-family: consolas, console, courier, arial, helvetica;
margin: 0 auto;
color: #FFF;
padding: 15px 30px;
}
header {
background: #666;
}
footer {
background: #F86;
position: relative;
height: 300px;
/*overflow: hidden;*/
}
.append {
background: #66F;
position: absolute;
top: 100%;
width: 100%;
height: 500px;
left: 0;
}
EDIT: updated fiddle, added inline code, added images
When you give top: 100% with a position: absolute, then you are actually sending it fully to the next page. I guess you are trying to make a modal-window, then you need to set it as:
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
The above code will over everything. The overflow: hidden is not applicable here, but when you are planning to show the modal window, or the overlay, it is best to use overflow: hidden to the <body>, so that the users will not be able to scroll and you can find the modal window.
Explaining the whole concept I said using a snippet here. Click the links to invoke the modal window. Click the opened modal window to hide it back. Scroll and see. Play around with it:
$(function () {
$("body > p").append(' Open Modal');
$("p a").click(function () {
$("body").addClass("modal-open");
return false;
});
$(".mask").click(function () {
$("body").removeClass("modal-open");
});
});
.mask {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: none;
background: rgba(0,0,0,0.5);
z-index: 999;
color: #fff;
font-size: 1.5em;
text-align: center;
}
.mask p:first-child {
padding-top: 5em;
}
.modal-open {
overflow: hidden;
}
.modal-open .mask {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="mask">
<p>Click the links to invoke the modal window.</p>
<p>Click the opened modal window to hide it back.</p>
<p>Scroll and see. Play around with it</p>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda vitae temporibus corporis, quisquam, doloremque excepturi itaque laborum ratione sequi aliquid atque rerum rem minima, aperiam laboriosam blanditiis alias ex quas?</p>
<p>Quam dolor, perspiciatis! Perspiciatis voluptatibus magnam ad hic sint, officia voluptates aut labore, excepturi quasi sed sit modi amet temporibus exercitationem laudantium veniam cumque omnis quo! Esse, quas! Harum, iure!</p>
<p>Illo optio alias amet ex consequuntur est autem itaque reprehenderit odit, laboriosam saepe ipsa harum eligendi sit cumque modi cum perspiciatis! Dolorum, alias nostrum asperiores velit atque perferendis voluptatibus. Maiores!</p>
<p>Cumque perspiciatis laudantium sequi itaque eos facilis illum repellat necessitatibus sunt recusandae rem, tempore blanditiis consectetur distinctio nostrum enim sit corporis non odio deleniti architecto. Corporis, nam assumenda. Quibusdam, perspiciatis!</p>
<p>Illum, quasi nisi animi. Expedita recusandae nam maxime architecto, illo a? Aspernatur numquam eveniet quisquam, inventore fugit amet voluptatem porro odio corporis obcaecati nostrum earum aliquam recusandae, sint necessitatibus rem.</p>
<p>Id praesentium vitae tenetur harum voluptate error adipisci dignissimos vero voluptatibus numquam quibusdam, nemo molestias alias aliquam, est, esse at fugiat quasi ducimus ratione! Inventore, eaque repudiandae sed magnam incidunt!</p>
<p>Aliquid in, veritatis ut! Veritatis, voluptatibus? Fugiat iusto officia repellat quasi dolore eum odio vitae inventore error debitis, doloribus facilis, itaque! Perspiciatis iste, incidunt hic non qui voluptate rem quidem?</p>
<p>Explicabo laudantium quidem, ab aperiam autem tenetur quae voluptatem quam, mollitia recusandae sapiente id, praesentium quasi soluta tempora dolorum, maiores velit. Porro unde doloribus iste, nihil ipsa, pariatur molestias aliquam.</p>
<p>Aut excepturi vitae dicta, quos distinctio, nulla, nostrum architecto, atque veritatis perspiciatis voluptates odio. Similique nobis sed natus illo esse, quod quas ex tenetur dolore deserunt optio voluptate numquam quo.</p>
<p>Repudiandae inventore consequatur nisi ad ut voluptas pariatur ducimus consequuntur, exercitationem tenetur ipsam nesciunt beatae nostrum soluta similique excepturi perspiciatis consectetur illum veniam aut hic, neque eveniet. Nesciunt quas, placeat?</p>
<p>Unde nam, aut placeat. Voluptas, consequatur, quis. Perferendis illum ratione in voluptate consectetur molestias nam hic, reprehenderit similique distinctio. Repellendus veritatis excepturi hic dicta fuga mollitia! Culpa dolores doloribus, ratione.</p>
<p>Vero cupiditate quaerat sit non veritatis harum nesciunt eos suscipit tempore dolorem porro saepe a, iusto vitae, voluptatum debitis consectetur voluptas, corporis. Sequi, sint odio eligendi delectus culpa dignissimos, obcaecati?</p>
<p>Ipsam sequi facilis magnam ad officiis quae, nobis iusto, commodi culpa optio a facere numquam placeat perspiciatis saepe maxime mollitia voluptatem sunt ipsa? Sequi ipsam, nostrum blanditiis dicta repudiandae iste!</p>
<p>Facilis tenetur officia quo delectus eius quam vel minus quas nesciunt ipsa perferendis, explicabo quasi itaque, rem vero accusamus debitis quis pariatur blanditiis illo nostrum eum! Molestiae fuga eius, illum.</p>
<p>Accusantium, repellendus soluta modi animi cumque error, nemo doloremque. Commodi voluptates distinctio nesciunt animi a, odio assumenda exercitationem amet reprehenderit libero expedita fugit. Id minus, corporis quibusdam cupiditate aut harum!</p>
I want to create a div(located at the top) which has its own space and also its position is fixed. The requirement is when it is scrolled down, it has to move and on scrolling up it should go back to its own space.
When position is fixed it is moving up and down. But it loses the space for it. How to achieve the space for it?
Thanks in advance.
Is this what you're after?
http://jsfiddle.net/danhaswings/a1zb6ye9/
HTML
<div class="container">
<div class="navbar"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore itaque doloremque delectus incidunt deleniti, excepturi, saepe nesciunt asperiores quae repellendus quisquam consequatur. Vero tenetur saepe eos ipsum harum culpa velit alias blanditiis maiores libero voluptates autem nostrum dolorem dolorum, beatae ullam. Explicabo tenetur necessitatibus modi illum alias! Eius enim accusantium, totam quibusdam fuga aliquam quod numquam. Consequuntur et ipsum earum voluptatum iure soluta necessitatibus minima unde nesciunt repellendus excepturi quod, exercitationem voluptates. Veniam temporibus aliquam amet maxime ex, voluptatibus ipsum consequatur quibusdam laborum, itaque reprehenderit. Optio dignissimos, maiores, debitis accusamus itaque corporis laboriosam nisi fuga! Quas porro eos qui, numquam.</p>
</div>
CSS
.container {
min-height: 2000px;
padding-top: 100px;
}
.navbar {
height: 100px;
width: 100%;
background-color: #999;
position: fixed;
top: 0;
}