CSS - Adjust height to bottom of screen - html

I have a div with a big list, I only want to see (with a scroll) the number of elements that fits in the screen. So I cannot figure how can I adjust the height of the div to the bottom border of screen.
Do I have to use JS?

Based on screen size apply media query styles.
for example Footer want to be bottom we use this for all the browsers
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0; /* Always make footer in bottom at any screen */
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>

If you got a fixed size above. You can fill the rest by using css calc.
.test {
height:300px;
width: 100%
background-color:yellow;
}
.full-height {
height: calc(100vh - 300px);
background-color:red;
}
<div class="test"></div>
<div class="full-height">
</div>
A better solution is to use a wrapper. Like this:
.wrapper {
background-color:red;
height: 100vh;
}
.list {
background-color: white;
width: 100%
}
<div class="wrapper">
<div class="list">
<ul>
<li>This</li>
<li>is</li>
<li>a</li>
<li>list</li>
<ul>
</div>
</div>

Related

How to set a DIV on the right side of the browser with percentage margin that make it get closer to the edge when resizing the browser?

I will try to explain it better here
An element placed on the page and have 10% from the left
when the page size changes the size of the margin to the left getting smaller
10% from 1400px - 140px , 10% from 1000px - 100px (pretty basic)
Now how do I make it happen to an element to the right
so when browser 1400px the margin to the right will be 140px
and when changing the width of the browser to 1000px the margin to the right will be 100px
sorry I don't have an example to show
You can use viewport width to accomplish this.
.element {
margin-left:10vw;
}
I think your question doesn't provide enough information. But I will give you several possible answers.Hope they help you.
First solution
body
{
position:relative;
}
.element
{
position:absolute;
right: 10%
}
Second solution
body
{
position:relative;
}
.element
{
position:absolute;
margin-right:10vw;
}
Third solution
body
{
padding-right:10%;
}
body
{
background-color:#FEFEFE;
height:650px;
direction:rtl;
position:relative;
}
.container
{
width:100%;
padding-right:10%;
height:100%;
}
.element
{
width:200px;
height:100px;
}
.first
{
background-color:red;
}
.second
{
position: absolute;
background-color: blue;
margin-right: 10%;
top: 120px;
right: 0;
}
.third
{
position:absolute;
background-color:green;
right:10%;
top:240px;
}
<body>
<div class="container">
<div class="element first">
<h3>first div</h3>
</div>
<div class="element second">
<h3>second div</h3>
</div>
<div class="element third">
<h3>third div</h3>
</div>
</div>
</body>

Why is div outside of parent div when i use height:100%

I have problems placing a div within another div which has a defined height of lets say 400px.
When i set the inner div to 100% then its overlapping the outer div and goes over the outer one. Why isnt 100% height sizing the inner div to the outer divs height?
body {
min-width:300px;
}
.header {
background-color:pink;
width:100%;
height:400px;
}
.menu {
background-color: red;
}
.header-container {
color:white;
background-color:gray;
height:100%;
max-width:400px;
margin:auto;
}
.headline {
padding-right:36px;
padding-left:36px;
padding-top:54px;
padding-bottom:54px;
}
.clearfix {
clear:both;
}
<div class="header">
<div class="menu">
menu
</div>
<div class="header-container clearfix">
<div class="headline">
<span>das ist mein blog</span>
<span>this is the underline</span>
</div>
</div>
</div>
<div class="blog">
y
</div>
<div class="footer">
x
</div>
https://jsfiddle.net/g9ec4nw8/
Because the the padding on the .header-container is causing an overflow.
Adding box-sizing: border-box; to your .header-container, will fix the box-sizing issue.
But not only that, you haven't taken into account the 18px of height by your .menu.
In full, by changing your .header-container to the following code:
.header-container {
color:white;
background-color:gray;
height:calc(100% - 18px);
max-width:400px;
box-sizing: border-box;
margin:auto;
top:0;
bottom:0;
padding-right:36px;
padding-left:36px;
padding-top:54px;
padding-bottom:54px;
}
Will fix the issue.
Fiddle Here.

full height content with scrolling footer

I've got the following setup:
header,
content - which needs to be full height of the browser,
and footer
The current setup below is how I want it (when the browser is opened fully). Basically the content div should have 100% height and you simply scroll to view the footer. The amount you scroll is based on the height of the footer. The content will be a simple login form. I've added in a div with a fixed height to demo my issue (The login div could be any height). However the problem is when the browser is resized vertically. This is the tricky bit to explain:
My question is how do I prevent the footer from overlapping the content div? I'd like the footer to snap to the bottom of the content div. As the browser window gets shorter, i'd like the content div to still remain 100% in height. The browser will cut the content div as it gets vertically shorter (which is fine) but I'd like the footer underneath the content div and still want to only be able to scroll to the height of the footer.
I think i'm missing margin-bottom somewhere but not quite sure where. Could someone please help with this issue. Thanks in advance.
the html:
<body>
<div class="wrapper">
<div class="content">
<div class="loginPanel">
</div>
</div>
</div>
<div class="footer">
footer, hidden until scrolled
</div>
</body>
the css:
html, body {
height:100%;
padding:0;
margin:0;
}
.wrapper {
height:100%;
background:orange;
}
.content {
background:grey;
width:100%;
height:100%;
}
.footer {
background:purple;
height:200px;
width:100%;
color:#fff;
}
.loginPanel {
width:600px;
height:300px;
background:green;
margin:0 auto;
}
You should be able to achieve what you want with the following:
html, body {
height:100%;
padding:0;
margin:0;
position:relative;
}
.wrapper {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.content {
background:grey;
width:100%;
min-height:100%;
}
.footer {
height:200px;
width:100%;
}
.loginPanel {
width:600px;
height:300px;
background:green;
margin:0 auto;
}
<div class="wrapper">
<div class="content">
<div class="loginPanel"></div>
</div>
<div class="footer">footer, hidden until scrolled</div>
</div>
You can try adding a margin-bottom to the <body> or <html> element; that should fix your issue.
<div class="page-wrap">
Content!
</div>
<footer class="site-footer">
I'm the Sticky Footer.
</footer>
CSS
* {
margin: 0;
}
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
height: 142px;
}
.site-footer {
background: orange;
}

Content container to fit screensize?

If got a very basic layout, with a header, content container and a footer.
What i need done, is to make my content container size up, so that the whole layout will fit on the screen. (unless the text in the content container extends this of course).
I've tried assigning a height 100% value to my body, and from there assigning my content containers height to 100% aswell, but that results in making my content container size up to the height of the full screen.
Before that i had the height on the content container set to auto, which of course resulted in the page not being long enough, if a visitor with a bigger screen size than the layout, viewed the page.
Here is a part of my code:
HTML:
<body>
<div class="background"></div>
<div class="page">
<div class="header">
</div>
<div class="content">
</div>
<div class="footer">
</div>
</div>
</body>
CSS:
html, body {
height:100%;
margin:0;
padding:0;
}
.page {
position:relative;
height:100%;
z-index:1;
}
.content {
position:relative;
width:850px;
height: 100%;
margin: 0 auto;
background: url(images/content.png) 0 0 repeat-y;
}
I think this what you need (the footer will be always sticked to the bottom)
CSS
html, body {
margin:0;
padding:0;
height:100%;
}
.page {
min-height:100%;
position:relative;
}
.header {
background:#00ff0f;
padding:30px;
}
.content{
padding:10px;
padding-bottom:45px; /* Height+padding(top and botton) of the footer */
text-align:justify;
}
.footer {
position:absolute;
bottom:0;
width:100%;
height:15px; /* Height of the footer */
background:#00ff0f;
padding:10px 0; /*paddingtop+bottom 20*/
}
.content {
height:100%; // IE HACK
}
HTML
<div class="page">
<div class="header">Header</div>
<div class="content">
Some Content Here...
</div>
<div class="footer">Footer</div>
</div>​
Tested in all major browsers.
DEMO.
​
What you really want is a sticky footer, no? You can style the other elements to give the illusion that the #content element is bigger than it really is.
http://ryanfait.com/sticky-footer/

How to fix height 100% in content page ? CSS and Div

How to fix height 100% in content page ? CSS and Div
Header=72px
Content Height=100%
footer=72px
I would like to fix expend Content height 100% full screen.
Best Regards
If I understand correctly, I think you want the header and footer to each be 72px high, and the content to take up 100% of the remaining space. So the footer is pushed to the bottom of the page.
Markup, place this so #container is the only direct child of body. In other words place all of your content is inside the #header, #body, and #footer.
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>
Style
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
padding:10px;
height:72px;
}
#body {
padding:10px;
padding-bottom:72px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:72px; /* Height of the footer */
}
If your content is in a div, give it a height as follows
<div id="container">
<div id="header">
</div>
<div id="content">
</div>
<div id="footer">
</div>
</div>
div#container
{
height: 100%;
}
div#header
{
height: 72px;
}
div#content
{
height: 100%;
}
div#footer
{
height: 72px;
}