http://codepen.io/basickarl/pen/Wrwdam?editors=110
html:
<div class="back">
</div>
css:
html,
body {
height: 100%;
}
div.back {
margin-top: 50px;
display: absolute;
width: 30px;
height: 30px;
background-image: url('http://simpleicon.com/wp-content/uploads/arrow-35.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
The scrollbar on the right displays. I have to have html, body at 100% because of a sticky footer I'm using. Any ideas?
Try setting the height of the html element to 100% as well. Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have its height set as well. However the content of body will probably need to change dynamically. Setting min-height to 100% will accomplish this goal.
The easy fix is to use width: 100% instead. Percentages don't include the width of the scrollbar, so will automatically fit. If you can't do that, or you're setting the width on another element, add overflow-x: hidden or overflow: hidden to the surrounding element to prevent the scrollbar.
To show the scrollbars always on the webpage, use overflow: scroll Property. It will add both horizontal and vertical scrollbars to the webpage. To add only horizontal scrollbar use overflow-x: scroll property and for vertical scrollbar use overflow-y: scroll property.
the body
element has a default margin: 8px;
in most major browsers so first you have to remove that by resetting the margin
property on the body
element
body {
margin: 0;
}
Then, instead of using height: 100%;
on the body use min-height: 100%;
so that the body can also grow beyond 100% height when used in conjunction with overflow: hidden;
Since min-height
doesn't work if the parent height isn't explicitly set, a height
attribute has to be added to the html
element as well.
html {
height: 100%;
}
body {
margin: 0;
min-height: 100%;
overflow: hidden;
}
Also, your div.back
selector has an invalid value on the display
property. the display
property accepts inline
, inline-block
, block
, none
, flex
, inline-flex
, grid
etc... whereas the position
property accepts static
(default for every element), absolute
, relative
or fixed
. This is not a problem but rather something the browser just ignores as it doesn't understand it.
div.back {
display: absolute; // <------ remove this line
//... snipped ...
}
It's partially because the default browser style sheets add some margins
and/or padding
. Resetting them to 0
will fix part of it (JSFiddle).
However you've also got a div
with some margins applied (50px
). The way the box-model works will mean you'll need to minus that from your 100%. You can use calc
if you really need to (or just change it to padding
):
height: calc(100% - 50px);
Example using the above code: http://codepen.io/anon/pen/mVPpYK
Example using padding: http://codepen.io/anon/pen/OMNzqB?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With