I've made a footer section which is placed at the bottom of my webpage. I ran into a problem when the content of my webpage is smaller than the height of the browser viewport, which leaves a blank space between the footer and the end of the page. I tried to solve it by using this piece of css.
.footer {
position: absolute;
bottom: 0;
height: 125px;
}
It worked perfectly on my webpages with little content but for big webpages, the footer had overlapped the content. I followed a few online tutorials but I still can't make it right.
<body class="bg-1">
<div class="container-full">
<div class="container">
...
</div>
</div>
<div class="footer text-center">
...
</div>
</body>
.container-full {
width: 100%;
height: 100%;
padding-top: 70px;
margin: 0 auto 125px;
}
.bg-1 {
background: url(../img/1.png) no-repeat center center fixed;
background-size: cover;
height: 100%;
}
.footer {
position: absolute;
bottom: 0;
height: 125px;
}
I am using Twitter Bootstrap.
You can try following Method:
html,
body {
height: 100%;
}
.container-full {
table-layout: fixed;
background: #ccc;
display: table;
height: 100%;
width: 100%;
}
.footer {
display: table-footer-group;
background: #2f2f2f;
overflow: hidden;
color: #fff;
width: 100%;
height: 1%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<body class="bg-1">
<div class="container-full">
<div class="container">
<p>Main Content goes here</p>
</div>
<div class="footer text-center">
<p>Footer text goes here..</p>
</div>
</div>
</body>
Related
I want my navigation text to be displayed at the bottom right of the header div but no matter what I try it only wants to align at the bottom of the page or some other position I do not want. I don't understand why this is happening, absolute should refer to the header div, correct?
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
font-size: 14px;
font-family: Arial;
scroll: overflow;
}
.header {
margin: auto;
width: 100%;
display: flex;
background: gray;
height: 60px;
}
.header-navigation {
position: absolute;
bottom: 0px;
right: 0px;
}
.container {
margin: auto;
width: 100%;
display: flex;
height: calc(100vh - 60px);
}
.left {
background: #e8edf0;
flex-basis: 45%;
}
.right {
background: grey;
flex-basis: 55%;
}
.content {
margin: 20px;
padding: 20px;
background: white;
}
</style>
</head>
<body>
<div class="header">
<div class="header-navigation">
test
</div>
</div>
<div class="container">
<div class="left">
<div class="content">
</div>
</div>
<div class="right">
<div class="content">
</div>
</div>
</div>
</body>
</html>
You should add position: relative; to header. This will make the .header-navigation consider position from .header when you make it absolute.
.header {
position: relative;
}
.header-navigation {
position: absolute;
}
Now .header-navigation will use position according to .header
absolute should refer to the header div, correct?
Only if header div itself has a position.
When you set the position of one of its children to absolute as you have in this case, the system hunts back up the page to find the first ancestor element that has a position and then it positions the element you are trying to position relative to that.
I'm having some trouble figuring out how to do this. I want to have a wrapper so my site is centered, but one of the header elements needs to stretch all the way to the right edge of the page, but without expanding the width of the page and adding scrollbars.
See here: http://i49.tinypic.com/6rkaxc.jpg (new poster so can't add image)
The blue outline represents the centered wrapper, and the orange box is the header div that I'm trying to get to fit to the right side of the page. I've got it to work using 100% width but it creates a horizontal page scroll since it's making it the same width as it's parent. I want it to expand for users that have higher resolutions so it always fits snug to the right side. I hope this makes sense.
my code looks something like...
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="left">
</div>
<div id="right">
</div>
</div>
</body>
CSS:
div#wrapper {
margin: 0 auto;
width: 1020px;
position: relative;
}
div#header {
height: 150px;
position: absolute;
left: 510px;
width: 100%;
}
div#left {
width: 510px;
float: left;
}
div#right {
width: 100%;
float: left;
}
I'm pretty new to this stuff so if you notice any errors here or bad practices please point them out! Thanks for the help! :)
Since you want your content to be fixed width, a strategy would be to have containers for both left and right contents. This allows you to use width: 100% for the header which will extend to the end without scroll bars. You then make the header relative to the right container. Here is a jsfiddle you can play with.
Note I made the widths smaller so it would fit in my jsfiddle window.
HTML:
<body>
<div id="wrapper">
<div id="leftContainer">
<div id="left">
This is left
</div>
</div>
<div id="rightContainer">
<div id="header">
This is a header
</div>
<div id="right">
This is right
</div>
</div>
</div>
</body>
CSS:
div#wrapper {
text-align: center;
width: 100%;
position: relative;
white-space: nowrap;
overflow-x: scroll;
}
div#header {
z-index: 1000;
height: 150px;
position: absolute;
left: 0;
width: 100%;
background: green;
}
div#leftContainer {
float: left;
width: 50%;
height: 500px;
display: inline-block;
}
div#left {
float: right;
width: 260px;
height: 300px;
background-color: purple;
}
div#rightContainer {
position: relative;
float: right;
width: 50%;
height: 500px;
display: inline-block;
}
div#right {
width: 260px;
height: 300px;
background-color: yellow;
}
Try this one. I changed the wrapper width to 80%. Not sure if that's ok. But I works well when expanding the page. Moved the header outside of wrapper and also added background color for clarity.
Note 1: right DIV's margin-top is same size as header DIV's height.
HTML
<div id="outerWrapper">
<div id="header">
Header
</div>
<div id="wrapper">
<div id="left">
Left
</div>
<div id="right">
Right
</div>
</div>
</div>
CSS
div#wrapper {
margin: 0 auto;
width: 80%;
height: 100%;
position: relative;
background-color: #CCCCCC;
}
div#header {
height: 150px;
float: right;
position: absolute;
left: 50%;
width: 50%;
background-color: yellow;
}
div#left {
width: 50%;
height: 100%;
float: left;
background-color: red;
}
div#right {
width: 50%;
height: 100%;
float: left;
margin-top: 150px;
background-color: blue;
}
Hope this helps.
I've got a question regarding positioning of two objects: image and div. I want bg2.png image to stay under div. I keep encountering problem with image pushing div down by img's height. How do I avoid that?
I tried pushing down image with "top:" value but of course it leaves me with empty area above div. Also I tried adding negative "top:" value and relative position to "maincontent" div but again it left me with empty area, only difference was that this time it was under the div.
HTML:
<body>
<img src="./images/bg2.png" class="bgimg" />
<div id="maincontent">
</div>
</body>
CSS:
body {
width: 100%;
background: #000;
}
.bgimg {
z-index: -1;
overflow: hidden;
left: 70px;
position: relative;
display: block;
}
#maincontent {
height: 520px;
width: 960px;
margin: 20px auto;
display: block;
z-index: 8;
}
Thanks in advance.
edit - what I'm trying to achieve:
Click me!
2 solutions:
Change your HTML structure:
<body>
<div id="maincontent">
</div>
<img src="./images/bg2.png" class="bgimg" alt="some">
</body>
or make it as the background-image:
<body>
<div id="maincontent">
</div>
</body>
#maincontent {
background: url(./images/bg2.png) no-repeat 0 100%;
padding-bottom: height_of_image_in_px;
}
<style>
body {
width: 100%;
background: #000;
}
.bgimg {
z-index: -1;
overflow: hidden;
left: 70px;
position: relative;
display: block;
}
#maincontent {
height: 520px;
width: 960px;
margin: 20px auto;
display: block;
z-index: 8;
}
</style>
<body>
<div id="maincontent">
<img src="./images/bg2.png" class="bgimg" alt="some info about image here">
</div>
</body>
if you want that image inside the div use this code. or if you want make that image background of that div use css background property
I would like to try to build a clean and nice piece of code where I can accomplish the result you see in the image below. It's ok in Firefox, Chrome or Safari, but not in IE.
I created a JSFiddle with the code.
Basically all I want a 100% width of the red bar (edge to edge in the window) but the content (including the navigation) should be limited in width.
So I'm looking for a nice, clean snippet to make this work in all browsers (including IE...)
<style>
body{
background-color: #fff;
margin: 0;
padding: 0;
}
#subtopContainer{
background-color: #f00;
}
#subtop, #header, #content{
width: 980px;
margin-left: auto;
margin-right: auto;
}
#header{
height: 150px;
}
#subtop{
height: 50px;
}
</style>
<div id='container'>
<div id='headerContainer'>
<div id='header'></div>
</div>
<div id='subtopContainer'>
<div id='subtop'></div>
</div>
<div id='contentContainer'>
<div id='content'></div>
</div>
</div>
<style>
body { background-color: #fff; margin: 0; padding: 0; }
div.wrapper { margin: 0 auto; width: 980px; background: lime}
div.header { height: 70px; margin-bottom: 40px;}
div.content { height: 400px; }
div.bar { height: 40px; background: #f00; overflow: hidden; position: absolute; top: 70px; width: 100%;}
</style>
<body>
<div class="bar"></div>
<div class="wrapper">
<div class="header">
Header Stuff
</div>
<div class="content">
In order for this to work,
div.bar 'top' = div.header 'height'
div.header 'margin-bottom' = div.bar 'height'.
</div>
</div>
</body>
I am looking to create a vertically scrolling website. I'll have a set of 5 divs that I want to have a height of 100% that are stacked on one another, basically making the body 1500% in height. Yeah?
Here is my code so far:
CSS
#contentWrapper {
position: relative;
width: 600px;
height: 1500%;
margin: 0 auto;
border: 1px solid red;
}
.panel {
position: relative;
height: 6.66%;
border: 1px solid blue;
}
.panelGuts {
position: relative;
top: 50%;
width: 100%;
height: 600px;
margin: -300px 0 0 0;
border: 1px solid green;
}
HTML:
<div id="contentWrapper">
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
</div>
This seems to work in Safari, Firefox, and Chrome but it doesn't work on an iPad or iPhone, and knowing how IE like's to behave, it probably won't work there either.
What I am wanting to know is 1) Why is won't work on an iPad/iPhone, 2) is there a better way to do this, maybe with jQuery?
I need each panel to have a height of 100% and have the content (panelGuts) be vertically centered. I'll be using jQuery ScrollTo (or some scrollTo plugin) to scroll to each div. I'd like to NOT have to set a specific height to each div...
Can anyone help?
I actually figured this out with HTML5. It was pretty simple. For anyone who wants to see my results
CSS
body, html {
margin: 0px;
padding: 0px;
background: #FFF;
height: 100%;
}
#contentWrapper {
position: relative;
width: 600px;
height: 100%;
margin: 0 auto;
}
.panelContainer { display: inline; }
.panel {
position: relative;
display: table;
height: 100%;
width: 100%;
background:green;
}
article.panel:nth-child(2n+2) {
background:blue;
}
.panelGuts {
position: absolute;
top: 50%;
width: 100%;
height: 600px;
margin: -300px 0 0 0;
border: 1px solid black;
}
And my HTML
<div id="contentWrapper">
<section class="panelContainer">
<article class="panel">
<div class="panelGuts">
text 1
</div>
</article>
<article class="panel">
<div class="panelGuts">
text 2
</div>
</article>
</section>
</div>
And a Fiddle for you: http://jsfiddle.net/ryanjay/dwspJ/