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 .
Related
I have a super simple example with a wrapper div and another div inside this wrapper called header.
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
Is it possible that the inner div called header sticks out of the wrapper on both sides with lets say 20px or even 100viewport wodth?
If I understand you correctly you want the inner header to stick out 20px. You can do that with negative margins:
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
margin-left: -20px;
margin-right: -20px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
if you want it to stretch through the whole viewport, you might have to position the element absolutely and use left: 0; right: 0;, however IMO it would be cleaner to move the div out of the container in that case.
You could give it a negative left/right margin:
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
margin: 0 -20px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
I'm trying to make the background fill the whole page. The only way I figured out how to do it is by setting the height and width of <div id="All"> and putting that div around everything else. I know that if I change the size of the browser, though, it won't auto resize, so it would look weird if I made my browser smaller or bigger.
If I set height and width to auto on #All, it def doesn't fill out the whole webpage. Please advise what I am doing wrong. Plus if I do auto, the sticky #Move doesn't stay at the top of the page.
This code is just stuff I have learned, so not an actual project, but I want to learn how to do it for future projects.
#Move {
position: sticky;
top: 0;
color: red;
}
h1 {
color: red;
}
.Hello {
font-size: 36px;
}
.Hello2 {
font-size: 15px;
}
p {
color: white;
}
.DivClass {
width: 160px;
height: 220px;
padding: 40px;
border: 10px solid black;
border-radius: 60px;
margin: 50px;
background: url("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSqOq9_iT948LTPmS5FuCMlaqlvn2KJQ-0d7Xw5kLMfWz69wwRA&usqp=CAU");
background-repeat: no-repeat;
background-size: cover;
opacity: 80%;
}
.image-whitecat {
width: 500px;
heigth: 500px;
background-color: red;
margin: 50px 50px 90px 250px;
transform: rotate(10deg);
}
.image-cat {
width: 700px;
height: 500px;
border-radius: 300px;
margin-left: 350px;
filter: opacity(70%)
}
.Purple {
color: purple;
}
.PurpleText {
background: teal;
text-align: center;
padding-top: 50px;
width: 150px;
height: 100px;
border: 5px solid red;
border-radius: 100px;
margin: 10px 0 0 1000px;
}
#All {
background-color: lavender;
position: absolute;
top: 10px;
bottom: 10px;
height: 1850px;
width: 1810px;
}
<div id="All">
<div class="DivClass">
<h1>HELLO!!!</h1>
<p class="Hello">Hello</p>
<p class="Hello2">Hello 2</p>
<p>Yes</p>
</div>
<p id="Move">I will stay at the top of the page!</p>
<div>
<img src="https://cdn.pixabay.com/photo/2014/11/30/14/11/kitty-551554__340.jpg" class="image-whitecat" />
</div>
<div>
<img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" class="image-cat" />
</div>
<div class="PurpleText">
<p class="Purple">Purple</p>
</div>
</div>
I think you will need to give both your html and body tags a css height ...
html, body {
height: 100%;
margin: 0;
}
So,
https://jsfiddle.net/z51crou7/
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;
}
My site code is very usual
<div class="header"></div>
<div class="site-inner"></div>
<div class="footer"></div>
How can I make header background like on the image?
Is the whole site content have to be position absolute and margin-top:-500px ?
Is that only case to do it?
I assume you mean the overlap.
Negative margin is one way.
.header {
height: 50px;
background: lightblue;
}
.site-inner {
width: 80%;
margin: auto;
height: 50px;
background: lightgrey;
margin-top: -30px;
box-shadow: 0 -2px 2px black;
}
<div class="header"></div>
<div class="site-inner"></div>
You can use:
.header{
width: 80%;
height: 75px;
margin: 0 auto;
margin-top: -20px;
background:#3A3A3A;
}
Take a look at positioning: Positioning, also z-index might be relevant: Z-index, notice in my example the negative index on .header-bg
A quick example:
.header-bg {
width: 100%;
height: 200px;
z-index: -1;
background: lightblue;
position: absolute;
top: 0;
left: 0;
}
.header {
margin-top: 50px;
height: 50px;
background: grey;
z-index
}
.menu {
height: 80px;
}
.site-inner {
height: 400px;
width: 100%;
background: red;
}
<div class="header-bg"></div>
<div class="header"></div>
<div class="menu">menu</div>
<div class="site-inner">Site inner</div>
<div class="footer"></div>
A negative z-index lets you put elements behind others. The answer is simple enough then.
<div class="color"></div>
<div class="fixed">
<div class="header">
</div>
<div class="nav">
Text
</div>
<div class="body">
</div>
</div>
html, body
{
height: 100;
margin: 0;
}
div.color
{
position: absolute; /*Take out of the flow*/
top: 0; /*Move to top left*/
left: 0;
z-index: -1; /*Place below normal elements in the flow*/
width: 100%; /*Fill whole width*/
height: 300px; /*300px tall*/
background: #c7edfb; /*Color specified*/
}
div.fixed
{
margin: 50px auto 0; /*push whole document down 50px and center*/
width: 600px; /*document is 600px wide*/
}
div.header
{
height: 150px; /*top gray block is 150px tall*/
background: #222; /*dark gray*/
}
div.nav
{
padding: 25px 0; /*Gap between blocks above and below*/
}
div.body
{
min-height: 300px; /*Force a height*/
background: #777; /*Light gray*/
box-shadow: 0 0 8px black; /*Drop shadow*/
}
JSFiddle
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