So I managed to make a sidebar in a div that fit to the left side perfectly but unfortunatly it goes under my footer and header enough that I'm attempting to place a second div inside that sidebar div that will serve to hold actual content.
I'm trying to fit the sidebar to be scale-able (change whenever I adjust the height of the browser to whatever) but not overlap my header or footer or go under it. I have the positioning set to absolute and the header/footer set to fixed.
HTML:
<div id=sidebar"></div>
CSS:
#sidebar {
background-color: #1c1c1c;
left: 0;
width: 300px;
height: 100%;
border-right: #212121 5px solid;
border-top: #212121 5px solid;
border-bottom: #212121 5px solid;
position: absolute;
z-index: 1;
}
This will be used to hold page navigation whereas my nav element is being used to hold site navigation. I'm trying to see if this might involve another language (I only really know HTML/CSS) and also trying to place this sidebar div directly in the center of the left side. Don't quite know how to go about doing that. I believe the footer and header are what one might call 'sticky'. They are position: fixed, again.
I agree with Abdulla. We need to see all your code, but based on what you provided I think you may need to set the following css in your style sheet or in the page head:
html, body{
height:100%;
}
I found this article that may help you http://www.mattboldt.com/css-100-percent-height/
But without knowing more this is all I can provide.
Your Question not clear. As i understood answer is bellow.
Remove these
#header {
position: fixed;
}
#pgdirectory {
position: absolute;
}
#footer {
position: fixed;
}
Add these
.clear
{
clear: both
}
.body
{
float: left;
}
in your HTML
<div id="header">
<nav>
<ul>
<li>Home</li>
<li>Web Development</li>
<li>Fursuits and Mascots</li>
<li>Art Customs</li>
<li>Computer Building</li>
<li>Future Plans</li>
</ul>
</nav>
</div>
<div class="clear"> </div> //New
<div class="body"> //New
<div id="pgdirectory">
<div id="links"> TEXT TEXT TEXT</div>
</div>
<div id="content">
<h1>SITE UNDER CONSTRUCTION</h1>
<p></p>
<h2>Contact Info</h2>
<br>
Email: smith#kempt.us<br>
Skype: mcKempt<br>
</div>
</div> //closing of Body Div
<div class="clear"> </div> //New
<div id="footer">
Related
I have the following fiddle https://jsfiddle.net/0vau6psp/ This is the minimum code required to replicated the error. I am assuming it has something to do with position:fixed but I can not figure it out.
The problem is resulting in my header being display directly on top of the main content which is causing the main content to not be seen, I would like the content to display underneath the header.
Any help would be appreciated! Below Is my code as well for reference:
HTML:
<header class="site-header" >
<div class="header-main" id="header-flow">
<div class="container-fluid header-cont-top-nav">
<div class="row">
<div class="col-md-5 text-right hidden-xs hidden-sm">
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
</div><!--/.container-->
</div><!--/.header-main-->
</header>
<main class="site-main-content" id="mainscrollcontent">
<p>
{{ content_for_layout }}
Test
Test Content
Test Content line 4
</p>
</main>
CSS:
#header-flow {
border-bottom: #73b2b2 3px solid;
z-index: 1000;
background-color: #fff;
position: fixed;
width: 100%;
}
#header-flow li{
display:inline-block;
}
.site-main-content {
margin-bottom: 0;
display:block;
}
If you don't want to use margin-top: or padding: or style the next set of HTML elements underneath your fixed header, you can add a blank div to achieve this.
.block {
height: 100px; // customize
width: 100%;
}
Example. & Example.
You can add padding-top or margin-top to your .site-main-content css to bring it down
You are setting the header first in HTML, fixing its position and then main , which is coming under.
So u got these options:
Stop Fixing the position of Header. .remove this line.
change the order
position:relative;
I must start off by saying I'm on a HUGE learning curve with this, and the website project is in my spare time as a present to somebody, so my knowledge is limited, although I think I understand the basics.
ALSO please note that I do have another more basic, less interesting site which is already built as a back-up so I won't be broken-hearted if I'm told all my code is rubbish and I need to start again!
I'm creating a one-page, horizontally-scrolling portfolio site for a make-up artist, which requires me to have a fixed banner with my menu listings on the left hand side, and with javascript, the page scrolls nice and smoothly to the relevant section.
Everything looks great on my screen resolution, with my browser at the right size, but I've noticed that if I shrink the browser window down, the fixed navigation banner starts to scroll out of place, while everything else stays together as it should.
The end result should be that everything stays in its place, with the only 'moving part' being the content on the scrolling section, so when the browser is resized, everything either re-sizes or at least scrolls together.
I've played around with wrapping everything in a content div and I've experimented with different positioning, but nothing seems to be working.
Here's my basic html layout for the sections:
<html>
<body>
<div id="banner"> <!--this is the fixed nav banner-->
<ul>
<li>PORTFOLIO</li>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>CONTACT</li>
</ul>
</div>
<div id="portfolio" class="bigpanel">
<div id="portfolioimages">
<!--IMAGES GO HERE-->
</div>
</div>
<div id="about" class="panel">
</div>
<div id="testimonials" class="bigpanel">
</div>
<div id="contact" class="bigpanel">
</div>
<div id="footer">
</div>
</body>
</html>
...and the CSS:
body {
width: 15000px;
height: 580px;
background-color: #fcf4f1;
position: absolute;
margin: 2% 0 5% 0;
}
#footer {
position: fixed;
left: 935px;
top: 645px;
margin: 10px;
}
#banner {
position: fixed;
height: 580px;
width: 200px;
background-color: #fff;
opacity: 0.8;
line-height: 20px;
margin: 45px 0px 0px 20px;
padding: 0;
z-index: 999;
}
.panel {
width: 930px;
float: left;
padding-left: 242px;
padding-right: 1040px;
margin-top: 45px;
}
.bigpanel {
float: left;
padding-left: 242px;
padding-right: 1040px;
margin-top:45px;
}
Pic of how the site is at the correct size
...and a pic of how it looks when it's squished in height!
I've tried to be as thorough as possible so sorry for the long one!
Any help would be greatly appreciated.
Ok, I don't know whether I have the answer that will work for everyone but it certainly has for me.
I basically had a long look at how I'd defined the widths and heights for basically all elements in my website and worked out that although the widths needed to be fixed for the main body and the banner, the height could be responsive depending on the viewport size.
I wrapped everything in a very wide wrapper div, with a height set to 100%, but set the body height to 84vh, with a max-height of 700px (so my images can have the same max-height and always look good).
This way I could also set the banner to height: 84vh with a max-height of 700px so it never overflows, but always sizes down.
I set the margin for my wrapper to centre it vertically, and now whilst everything fits inside its containers, there's no vertical scroll!
I'm sure a lot of it is an ugly solution, caused by my bad coding but it works now!
I thing you have to play with the top poperty on you #banner div by putting it to 0. This work only with positions like fixed, absolute, relative, etc. What it will do is to fix you div at the top of your browser window, no matter what. It is the "top padding" (disantce) you div will have relativly to the to of the screen.
So you should just add
top: 0;
to
#banner
and it should work!
If you want an exemple of it's efficacity, I recommend you to look at this codepen: http://codepen.io/Symsym/pen/LsjCK
Cheers! and tell me if it works.
<body>
<div class="banner"> <!--this is the fixed nav banner-->
<ul>
<li>PORTFOLIO</li>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>CONTACT</li>
</ul>
</div>
<div class='content'>
<div id="portfolio" class="bigpanel">
<div id="portfolioimages">
<!--IMAGES GO HERE-->
</div>
</div>
<div id="about" class="panel">
about
</div>
<div id="testimonials" class="bigpanel">
testimonials
</div>
<div id="contact" class="bigpanel">
contact
</div>
</div>
<div class="footer">
footer is here!!
</div>
css code:
body {
background-color: '#fcf4f1';
overflow:hidden;
}
a{
text-decoration:none;
}
li{
list-style:none;
}
.banner {
position: fixed;
width: 200px;
background-color: '#ccc';
opacity: 0.8;
padding: 0;
z-index: 999;
top:20px;
left:0;
}
.content{
width:800px;
margin-left:200px;
overflow:auto;
float:left;
}
.panel {
margin-top:10px;
width: 930px;
float: left;
}
.bigpanel {
float: left;
margin-top:20px;
}
.footer {
position: fixed;
bottom: 0;
left:0;
right:0;
background:red;
margin: 10px;
}
you can scroll on content.
I've designed a website as you can see below, which has a FIXED header (white), then a sub-header, main content, sidebar (red) and a footer (grey).
I have created the wireframe for the website in HTML/CSS, but can't get the sidebar to work properly.
I would like the sidebar to start on the sub-header and go all the way to the bottom of the page to end after the footer (see the image below) no matter how much content there is in the main section, but I can't get it to work.
Please help! Here is my current efforts on JSFIDDLE, as you can see the sidebar doesn't go to the bottom of the page: http://goo.gl/EQ7CJh
Remove the position: relative from content div and use margin-top to position the panel, as shown:
#content {
height: 100%;
}
#sidebar {
border: 1px solid skyblue;
width: 100px;
position: absolute;
margin-top:7em;
top: 0px;
right:0px;
bottom: 0px;
}
Updated jsfddle
Can you try this jsFiddle http://jsfiddle.net/2ZhpH/1093/
I have changed the HTML structure and added the #sidebar css to this
#sidebar {
position:absolute;
top:48px;
border: 1px solid skyblue;
width: 100px;
position: absolute;
right: 0;
bottom: 0px;
}
Demo
If you want to have side bar to the side of The div which contains sub-header main and footer the you should have a Grid structure like this
<div id="header" class="...">
</div>
<div class="divide"> <!-- divide class to have like 85% width leaving rest of it for side bar -->
<div class="sub-header">
</div>
<div class="main">
</div>
<div id="footer">
</div>
</div>
<div class="sidebar">
</div>
Problem
When using my phone to view a website i'm creating the site appears and seems to act differently than i expect?
I have a screenshot to demonstrate the problem on said smartphone screen.
Smartphone view
As you can see both the header and footer are not expanding 100% in width as they should, and do when viewed using a desktop browser.
Desktop view
Header CSS
#banner {
background-image: url(images/images/bannersketchBG.jpeg);
float: left;
height: 100px;
width: 100%;
font-size: 36px;
font-style: italic;
}
#banner1 {
float: left;
height: 50px;
font-style: normal;
margin-top: 10px;
padding-left: 10px;
color: #FFF;
font-size: 24pt;
top: 0px;
}
#banner2 {
float: left;
height: 30px;
width: 410px;
font-size: 14pt;
font-style: italic;
padding-left: 30px;
color: #FFF;
}
Footer CSS
.footer {
background-color: #2E2E2E;
word-spacing: normal;
float: left;
color: #FFF;
font-weight: bold;
width: 100%;
height: 100px;
bottom: 0px;
}
HTML
Header
<div align="center">
<div id="banner">
<div id="logo"><img src="images/Joel-Compass-black.png" width="119" height="95" alt="CCFS"></div>
<div id ="banner1">Columbus Car Finder Group</div>
<div id ="banner2">"Exploring your Needs"</div>
</div>
</div>
Footer
<div class="footer">
<div class="footercontainer">
<div id="footerTabsContainer">
<div class='tab one'>
<ul>
<li>Find My Car</li>
</ul>
</div>
<div class='tab two'>
<ul>
<li>About Us</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab five'>
<ul>
<li>Contact Us</li>
</ul>
</div>
<div class='tab six'>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<div class="footerinfo">Web Design - CundyTech Copyright South West Car Finder 2013</div>
</div>
</div>
I notice the background image cuts off at the same point too, so could this be an overflow issue?!
Any help or pointers would be greatly appreciated!
PS i know i haven't quite got the finer points of css like using ID's and Classes properly but i am still learning so please dont hate on me too much!
Do not set div to width 100%, it expands by default. What you can try is to remove width property (from footer and header) and set min-width to be the same as your content's (it is a fixed width right?).
Do you have a link to the website that we can access? It is easy to test what works with Chrome/Firefox developer tools.
This generally happens when your content isn't enough to fill up the screen. I personally use calc() to sort it out. You can try this.
.your_header{
height:100px;
}
.your_content{
min-height:calc(100% - 300px);
}
.your_footer{
height:200px;
}
What it does is that it calculates min-height for your_content to 100% - height of your header - height of your footer;
Don't float your #banner or .footer. Check this cool tutorial on positioning to get a better idea: CSS Learn Positioning
Change the positioning of the footer to be fixed.
positioning: fixed; // will make the footer stick to the base of the viewport.
right: 0; // fill space to right
bottom: 0; // stick to the bottom of page
left: 0; // fill space to left
Notice we left out the top attribute... this is because we want that to be set automatically by the height of the inner elements.
You may also want to try position: absolute; and tweak the bottom padding on the body to give a result that will clear the body content and not stick to the viewport.
This should get you heading in the right direction.
As mentioned by #Linek in his answer, in the comments, adding a min-width style to body will solve this problem. I also had to add a min-width to the header, not sure why body didn't do both though?
Solution
Css
Body
{
min-width:1003px;
}
Firstly, apologies for what appears to be a very common question, looking at the amount of similar questions, you are forgiven for being annoyed at yet another, but regardless of all the others that I have read (and tried to implement), and many other links found on Google, I'm still struggling to solve my problem, so I'm sorry, but here goes..
The footer I have is fine when the main content is longer than the browser window, but when there is very little content, rather than sticking to the bottom of the browser window, it sticks to the bottom of the main content, leaving a horrible blank space below the footer.
I've created a simple(ish) fiddle HERE using a stripped down version of my code.. here is the code for those that are able to see the issue without "fiddling"..
<body>
<!-- Header -->
<div id="header-wrapper">
<header class="5grid-layout" id="site-header">
<div class="row">
<div class="12u">
<div id="logo">
<h1 class="mobileUI-site-name">HEADER</h1>
</div>
</div>
</div>
</header>
</div>
<!-- Main -->
<div id="main-wrapper" class="subpage">
<div class="5grid-layout">
<div class="row">
<div class="12u">MAIN CONTENT </div>
</div>
</div>
</div>
<!-- Footer -->
<div id="footer-wrapper">
<footer class="5grid-layout" id="site-footer">
<div class="row">
<div class="12u">PROBLEM FOOTER</div>
</div>
</footer>
</div>
</body>
and here is the css..
#header-wrapper {
background: #12ff00;
height: 110px;
position: relative;
padding: 0.0em 0 1em 0;
}
#main-wrapper {
border-top: 3px solid #662d91;
border-bottom: 3px solid #662d91;
background: #ff5a00;
position: relative;
padding: 1em 0 2em 0;
}
#footer-wrapper {
background: #ff00fc;
position: relative;
padding: 1em 0 1em 0;
height: 100px;
}
Granted, a lot of the above Divs aren't needed for the sake of this demo, but I have left them in just in case it is one of these thats causing the problem. I'm still new to this, so I honestly have no idea.
so basically, how on earth do I get that footer to behave, previous attempts based on other Stack Overflow answers have left me with either no footer, or a footer that sits in the center of the screen regardless of whether there is a lot or little content.
Any help will be gratefully received.
I have answered this question before
Click Here
Or see this JSFiddle for a working example of a sticky footer.
HTML
<div class="wrapper">
<div class="header"></div>
</div>
<div class="footer"></div>
CSS
* {margin: 0;}
html, body {height: 100%;}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -200px; /* the bottom margin is the negative value of the footer's height */}
.footer { height: 200px;background-color:#000;}
The idea is that the bottom margin is the negative value of the footers height
Have you tried:
html, body {
height: 100%;
min-height: 100%;
}
#main-wrapper {
height:100%;
}
Here's a working DEMO1
UPDATES:
I've changed a few things in your code, but now its working!
Here are the changes:
added a #container for the header and main divs.
I've changed the footer padding from em to px, because I need precise height.
I gave the main-wrapper's background to #container
and the border-bottom to footer as border-top
DEMO2
The way I ussualy do this is using
http://www.cssstickyfooter.com/using-sticky-footer-code.html
If you can, try to stick close to that, it has compatibility with older browsers.
I didn't find better alternatives to this and is well explained