How to set <div> height without leaks? - html

I'm desiging my page as:
Fixed top and side menus, main page scrollable depending on contents, everything inside a container.
I can't figure out how to stop the container from leaking the background in the bottom. I have tryed min-height: 100%, height: calc(100vh-50px), but none of this will work.
What I have so far
You can see the background leak in https://jsfiddle.net/0afeh6cb/
How can I get rid of that?
html,
body {
margin: 0px;
padding: 0px;
background-color: green;
}
#container {
background-color: #fff;
position: relative;
width: 1000px;
min-height: calc(100vh - 50px);
margin: 0px auto 0px auto;
}
#topMenu {
position: fixed;
top: 0px;
margin: 0px;
padding: 5px 10px 5px 10px;
background-color: #e0e0e0;
width: 980px;
height: 40px;
}
#sideMenu {
position: fixed;
top: 50px;
margin: 0px;
padding: 5px;
background-color: #c0c0c0;
width: 180px;
height: 100%;
}
/* ------------- Container ------------- */
#main {
margin-top: 50px;
margin-left: 190px;
width: 790px;
padding: 10px;
background-color: #f0ffff;
}
#footer {
margin-left: 190px;
width: 790px;
}
<div id="container">
<div id="topMenu">
<p>Top Menu</p>
</div>
<div id="sideMenu">
<h3>Side menu</h3>
</div>
<div id="main">
<h1>My content here</h1>
</div>
<div id="footer">
<p>Footer</p>
</div>
</div>

I hope this will help:
body,
#container {
height: 100vh;
}
#container {
/*height: calc(100vh - 50px);*/ You can remove this line
}

Remove the fixed positioning from your #topMenu.
#topMenu {
// position: fixed; <-- removed
// top: 0px; <-- removed
margin: 0px;
padding: 5px 10px 5px 10px;
background-color: #e0e0e0;
width: 980px;
height: 40px;
}
Remove the positioning from your #container and your calculated height and set a height of 100vh to prevent background bleeding entirely.
#container {
height: 100vh; // <-- added
background-color: #fff;
// position: relative; <-- removed
width: 1000px;
// min-height: calc(100vh - 50px); <-- removed
margin: 0px auto 0px auto;
}
Remove the margin top from your #main container.
#main {
// margin-top: 50px; <-- removed
margin-left: 190px;
width: 790px;
padding: 10px;
background-color: #f0ffff;
}

Please change the container class css as below:
100vh always take the total height of its parent div.
#container {
background-color: #fff;
position: relative;
width: 1000px;
_min-height: calc(100vh - 50px);//remove this line
height: 100vh; //Set this height.
margin: 0px auto 0px auto;
}

Related

Footer above bottom of page, instead of being at the bottom of the page content

I am trying to make the footer stay at the bottom of the page, NOT the bottom of the screen (fixed) but at the bottom of the entire page, so you can only see it after scrolling to bottom. However, for some reason it stays above the bottom, and I can't seem to find the reason...
FIDDLE:
https://jsfiddle.net/okfudezn/
Image:
HTML (the div has no wrappers etc):
<div class="footer">
<a>REGISTERED NAMES AND TRADEMARKS ARE THE PROPERTY OF THEIR RESPECTIVE OWNERS - Copyright © 2017 All rights reserved</a>
</div>
CSS:
.footer {
background-color: #4b4c46;
height: 55px;
line-height: 55px;
width: 100%;
text-align: center;
color: #e1dac5;
font-size: 14px;
}
Just change replace you content div height to auto
updated fiddle
.content {
position: relative;
width: 650px;
height: auto;
background-color: #e6e6e6;
border: 1px solid #bcbcbc;
margin: 0 auto;
margin-bottom: 80px;
top: -100px;
}
I would try with:
.footer {
position: absolute;
bottom: 0;
}
Change this css
.content {
background-color: #e6e6e6;
border: 1px solid #bcbcbc;
/*height: 650px;*/ /*Remove this*/
margin: 0 auto 30px;/*Change this*/
overflow: hidden;/*Add this*/
position: relative;
/*top: -100px;*//*Remove this*/
width: 650px;
}
.grid {
width: 600px;
/*height: 1000px;*/ /*Remove this*/
margin: 0 auto;
padding-top: 30px;
}
https://jsfiddle.net/okfudezn/
Here you go!
html, body {
margin:0;
padding:0;
height: 100%;
}
#container {
position: relative;
height: auto;
min-height: calc(100% - 54px);
padding-top: 54px; /* Header & Footer */
}
#header {
position: fixed;
top: 0;
width: 100%;
height: 54px;
background: red;
}
#content {
background: orange;
height: 100%;
}
#footer {
position: absolut;
bottom: 0;
width: 100%;
height: 54px;
background: yellow;
}
.simulateContent {
height: 1000px;
}
<div id="container">
<div id="header">
HEADER
</div>
<div id="content">
CONTENT START
<div class="simulateContent"></div>
CONTENT END
</div>
<div id="footer">
FOOTER
</div>
</div>

CSS child element producing a margin the full width of parent

building an overlay containing a stylised container for some text, however this container seems to be producing a margin which when combined with the elements normal width takes up the entire parent element width. According to chrome dev tools its the .flipcontainerelement that is causing this.
It's really weird behaviour and I can't figure out why its behaving in this way.
If I wanted to place content to the right of the container for example, I would not be able to because of this margin being produced.
.flipcontainer {
height: 230px;
width: 150px;
}
.flipcalender {
border: 1px solid #dddddd;
border-radius: 25px;
margin: 0 auto;
margin-top: 0.2px;
background: linear-gradient(white, #f4f2f2);
}
.mmouter {
width: 100%;
height: 100%;
border: 1.5px solid #dddddd;
}
.mmmiddle {
width: 98%;
height: 98%;
}
.mminner {
width: 98%;
height: 98%;
background: linear-gradient(white, #f4f2f2);
position: relative;
}
.mmbreaker {
width: 99%;
background-color: white;
height: 2px;
position: absolute;
z-index: 1;
top: 115px;
}
#mmlightbox {
display: block;
width: 400px;
height: auto;
position: fixed;
top: 30%;
left: 40%;
z-index: 999;
background-color: white;
padding: 10px 20px 10px 0px;
/* margin-right: 239px; */
margin-top: -100px;
margin-left: -150px;
border: solid 2px #f21c0a;
}
<div id='mmlightbox'>
<div class='flipcontainer'>
<div class='flipcalender mmouter'>
<div class='flipcalender mmmiddle'>
<div class='flipcalender mminner'>
<p class='daysremaining'></p>
<p>days</p>
<div class='mmbreaker'></div>
</div>
</div>
</div>
</div>
</div>
Add float: right; to .flipcontainer css like so:
.flipcontainer {
height: 230px;
width:150px;
float: right;
}
Here is the JSFiddle demo
The margin you saw was because you specified the width to '150px'.
Adding float: left removes this and you can add content next to it
.flipcontainer {
height: 230px;
width:150px;
float: left;
}
See Fiddle http://jsfiddle.net/epe3bfdw/

Issue with content scrolling over banner and under header

So I have this fixed header which has z-index:10, below that a fixed banner and then below that a relative content container. What I want is that the content scrolls over the banner but under the header. However, when I try to scroll it doesn't work. The strange part to me is that whenever I add box-shadow: 0px 0px 2px rgb(100,100,125); to the content container it does do what I want. I'm using the following code:
* {
padding: 0;
margin: 0 auto;
}
body {
background: rgb(223,227,238);
text-align: center;
}
#body_container {
padding-top: 80px;
}
#banner_container {
position: fixed;
left: 0;
right: 0;
}
#banner {
width: 1024px;
height: 300px;
}
#content_container {
background: rgb(243,247,248);
max-width: 1024px;
height: 100%;
position: relative;
top: 300px;
box-shadow: 0px 0px 2px rgb(100,100,125);
}
header {
min-width: 100%;
background: rgb(50,50,50);
height: 80px;
position: fixed;
z-index: 10;
}
/* Header styling, not relevant */
#header_container {
max-width: 1024px;
height: 100%;
}
#header_container div {
float: left;
display: inline-block;
width: 25%;
}
#logo {
width: 50%;
height: auto;
}
.menuItem {
padding-top: 29px;
height: calc(100% - 29px);
border: 0;
text-align: center;
font-family: Signika;
font-size: 25px;
color: rgb(203,207,218);
}
.menuItem:hover {
border-bottom: 4px solid rgb(59,89,202);
height: calc(100% - 33px);
color: rgb(160,170,218);
}
.menuLogo {
padding-top: 14.5px;
height: calc(100% - 14.5px);
border: 0;
text-align: center;
}
#mobile_menu_button {
display: none;
}
<header>
<div id="header_container">
<div class="menuLogo">
<img id="logo" src="img/desygn%20logo%20website.png">
</div>
<div class="menuItem">Home</div>
<div class="menuItem">Over</div>
<div class="menuItem">Contact</div>
<div id="mobile_menu_button">
</div>
</div>
</header>
<div id="body_container">
<div id="banner_container">
<img id="banner" src="img/banner_website.png">
</div>
<div id="content_container">
</div>
</div>
In your code you've not added any content under content_container. I don't see any issue with your code. It is working fine. Check here with content

Nested block all side spacing

I need a cross browser solution using css without JS or jQuery.
So i have two divs:
<div class="block1">
<div class="block2">
content
</div>
</div>
I need block2 to be full width of block1. I need spacing in every side 15px for block2. It must be responsive layout width and height. block1 must be 100% page width and height.
What i see. Something wrong with block2 margins. I didn't get 15px spacing all side in block2. I have problem with bottom side for now.
block1 = background: red;
block2 = background: black;
First i think that it is an easy task, but for now i didn't find solution.
What i have tried:
Html
<body class="body">
<div class="block1">
<div class="block2">
content
</div>
</div>
</body>
CSS
html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.block1 {
width: 100%;
background:red;
height: 100%;
display: block;
overflow: hidden;
}
.block2 {
background: #000000;
min-height: 100%;
margin: 15px 15px 15px 15px;
color: #ffffff;
}
here are 2 examples for you:
1. if you dont mind it not supporting IE 8 and below, you can use css CALC() to calculate the min-height of the inner block: min-height: calc(100% - 30px); (30 being the top+bottom margins)
html, body {
left:0;
top:0;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.block1 {
width: 100%;
background:red;
height: 100%;
display: block;
overflow: hidden;
}
.block2 {
background: #000000;
min-height: calc(100% - 30px);
margin: 15px 15px 15px 15px;
color: #ffffff;
}
<div class="block1">
<div class="block2">content</div>
</div>
2. a solution that should be supported in IE 8, is this:
html, body {
left:0;
top:0;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.block1 {
width: 100%;
background:red;
height: 100%;
display: block;
overflow: hidden;
}
.block2 {
background: #000000;
margin: 15px 15px 15px 15px;
display:block;
position:absolute;
bottom:0;
top:0;
left:0;
right:0;
color: #ffffff;
}
<div class="block1">
<div class="block2">content</div>
</div>

How to make footer stick to bottom of wrapper with bottom margin?

I´m trying to make a footer that sticks to the bottom of wrapper, but leaving a bottom margin so that the pattern image on the body background can be seen.
I came accross the sticky footer at
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
which worked great, but all my attempts of adding margin/paddings to footer/ wrapper/ body didn´t.
I guess it must be a pretty simple thing, but I´m not finding it. Thanks for any hints/ suggestions!
Here´s the relevant CSS:
*
{
margin: 0;
}
html, body
{
margin-top: 0px;
margin-bottom: 25px;
background-repeat: repeat;
background-image: url(images/modulo-pattern-grey-light.gif);
height: 100%;
}
#wrapper
{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -98px;
background: #fff url(images/footer.gif) left bottom no-repeat;
width: 980px;
box-shadow: 4px 4px 5px #999;
}
.footer, .push
{
height: 98px;
}
.footer
{
margin-left: 490px;
margin-right: 40px;
background-color: #bc4c9b;
}
HTML:
<div id="wraper">
<div class="header"></div>
<div class="logo">
</div>
<div class="menu_container">
<div class="main_menu">
<ul>
<li>Home</li>
<li><a class="selected" >Quiénes Somos</a></li>
<li>Consultoría</li>
<li>Capacitación</li>
<li>Académico / Artículos</li>
<li>Alianzas</li>
<li>Proyectos</li>
<li>Contacto</li>
</ul>
</div>
</div>
<div class="quienes_pic"></div>
<div class="quienes_text"></div>
<div class="push"></div>
</div>
<div class="footer"></div>
Sorry I didn´t mention, but Fixed position won´t work, since I want the same footer to work on different pages with differents heighs. The idea was to have the same wraper and footer through all the pages, and then assigning different body ids to set the different heighs
Pretty much like is done through this site:
http://www.casadelviento.com.ar/
In this case, it´s using different body ids AND different wrappers, I thought may be it could be done with less code and more clear (i.e I don´t understand why is the difference between the wraper heigh #contenido-index and the body heigh)
#contenido-index {
background-color: #FFF;
height: 2040px;
width: 900px;
margin: 0 auto;
}
#contenido-chicos {
background-color: #FFF;
height: 2760px;
width: 900px;
margin: 0 auto;
}
#contenido-adultos {
background-color: #FFF;
height: 2810px;
width: 900px;
margin: 0 auto;
}
#contenido-somos {
background-color: #FFF;
height: 2150px;
width: 900px;
margin: 0 auto;
}
#contenido-historia {
background-color: #FFF;
height: 980px;
width: 900px;
margin: 0 auto;
}
#contenido-horarios {
background-color: #FFF;
height: 967px;
width: 900px;
margin: 0 auto;
}
#contenido-contacto {
background-color: #FFF;
height: 750px;
width: 900px;
margin: 0 auto;
}
#contenido-videos {
background-color: #FFF;
height: 820px;
width: 900px;
margin: 0 auto;
}
#contenido-fotos {
background-color: #FFF;
height: 595px;
width: 900px;
margin: 0 auto;
}
#body-index {
height: 2160px;
}
#body-somos {
height: 2070px;
}
#body-historia {
height: 1150px;
}
#body-horarios {
height: 1060px;
}
#body-chicos {
height: 2700px;
}
#body-adultos {
height: 2800px;
}
#body-videos {
height: 960px;
}
#body-fotos {
height: 740px;
}
#body-contacto {
height: 880px;
}
/*FOOTER}*/
#contenedor_pie {
height: 40px;
width: 500px;
float: left;
margin-left: 20px;
margin-top: 15px;
}
With Reference to http://alt-web.com/DEMOS/CSS2-Sticky-Footer.shtml
You can define your footer HTML as
<div id="Sticky">
<h2>Here is a Sticky Footer</h2>
<p>Test for Sticky Footer</p>
</div>
then your CSS would be like
#Sticky
{
color:#FFF;
text-shadow: 2px 2px 2px #333;
border: 2px solid orange;
position:fixed;
padding: 0 10px 0 10px;
left: 0px;
bottom: 0px;
width: 100%;
}
Hey you can do easily just define in your css some code as like this
Css
body{background:green;}
#wrapper {
background:red;
min-height:700px;
}
.footer {
position:fixed;
bottom:20px;
height:100px;
background:yellow;
left:0;
right:0;
}
HTML
<div id="wrapper">Wraper text </div>
<div class="footer">Sticky footer</div>
Live demo http://jsfiddle.net/6z6Uk/
​
and now adjust according to your design .