Main column appears where sidebar column ends - css

I'm braindead on this and I know it's simple.
There's a header div, appears fine. There's a left-sidebar div, appears fine with top snuggled up to header div.
Then there's a main content div. There is an image and h1 which appear like you would expect up against the header div, but then a large gap appears until the navigation (in a nested div). Navigation is correctly in the main content div, but top of this div always aligns with bottom of sidebar content.
I've tried mixtures of clear:left and both and floating and whatnot. If inside the html I move the sidebar div below the main content div then the main content has no gap but the sidebar has a big top gap and appears flush to the bottom of where the main content nav ends.
What am I missing here, thanks in advance!

Are you setting any widths (or padding, margin, border) which might make your problematic div too wide to fit?
Remember that if you are doing something like :
width: 100%;
border: 1px solid;
Then your element will take up 100% width + 2 pixels.

It sounds like you have your sidebar occuring first in the source order.
If you have the two divs (sidebar, main) floated in different directions, then look at the width avaiable they are sharing. Reduce the width of one div (you should have width set on your floats) until their combine width, including padding, margin, borders fits in available space. (I will only use width in my example for brevity).
When this effect happens, in my experience, the one occurring later in the source order is the one that gets prevent from sliding up into it's spot by too much width.
<div id="container">
<div id="header">head</div>
<div id="sidebar">side</div>
<div id="mainContent">main</div>
</div>
Width of #sidebar & #mainContent too wide (#mainContent gets bumped down):
#container{
**width:950px;**
margin:0 auto;
background:blue;
}
#mainContent{
float:right;
**width:651px;**
background:red;
}
#sidebar{
float:left;
**width:301px;**
background:green;
}
Width of #sidebar & #mainContent fit inside container:
#container{
**width:950px;**
margin:0 auto;
background:blue;
}
#mainContent{
float:right;
**width:650px;**
background:red;
}
#sidebar{
float:left;
**width:300px;**
background:green;
}
btw...if you floated the two elements in the same direction, but their combined width is too wide, the last one in the source order would fit underneath the above floated element.

Does your h1 or img have a top margin? It will stick out of the top of the mainContent div and push it down.

Related

How to position overflown 'divs' side by side

DEMO HERE
I have two divs in a container. Both divs have 100% and 100% height. How do I position those divs side by side?
I tried float:left and display:inline-block but nothing seems to work. Second div is always under first div, not side by side
P.S. I don't want to use absolute position and I want one div overflown.
If both of them has 100% width you can't get the second one side by side. You should use "width: 50%" in those divs (I suppose they didn't have margins or padding), and then "float:left" the first one. The second one should go to the right of the first one.
If you want to add both div side by side you can not set div width 100%, you can set width 50% to check both are side by side without using display:inline-block
.innerDivs{
width:50%; // Change 100% to 50%
height:100%;
float:left;
}
Check this Demo
You should add overflow:hidden; property in outer div to solve this
Check this Demo
HTML
<div style="width:300px;height:100px;border:3px solid black;margin-top:100px;margin-left:100px;overflow:hidden;">
<div class="innerDivs" style="background:orange"></div>
<div class="innerDivs" style="background:red"></div>
</div>
CSS
.innerDivs{
width:100%;
height:100%;
float:left;
}

Making my footer stick to bottom of the page

EDIT: BEFORE YOU ANSWER, READ THIS! I can't set footer like "height: 30px;" because it has to stretch! That's why most solutions don't work!!
Okay so I have a problem. My footer sticks well to the bottom of the page if there's enough content, but when I have only a few lines of content, there's a white space under the footer. Picture:
(source: http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page)
The page which I got that image from offered one solution, but it doesn't work for me. Because my footer needs to be dynamic (I don't know the height in pixels or whatsoever, the div just stretches by the amount of content placed in footer)
All of the solutions I've found need a specified height for the footer... How could I get the footer to stay at the bottom of the page?
My divs look something like this:
<div class="mobile_main">
<div class="header">
Stuff
</div>
<div class="body_main">
Stuff
</div>
<div class="footer_mobile">
Stuff
</div>
</div>
All the 3 divs inside the main divs are stretching by content (no height specified).
Does anyone have a solution?
you could give the footer an absolute position at the bottom left corner of the mobile_main container div. therefore you also should give this container a relative position.
http://jsfiddle.net/kasperfish/FQ6fG/5/
.mobile_main{
position:relative;
}
.body_main{
background:grey;
min-height:300px;
}
.footer_mobile{
width:100%;
position:absolute;
bottom:0px;
left:0px;
background:lightblue;
}
.header{
background:yellow;
}
I think you want footer always fixed in bottom of the screen. If it is here is the solution.
.footer_mobile{
width:100%;
position:fixed;
bottom:0px;
left:0px;
background:lightblue;
}
But if you want footer should stay below the main container until the container height less than window height and footer get fixed on window screen bottom when container height get larger than window screen size. For that condition we have to use the jQuery for solution.
Don't use height in footer.
#body {
padding:10px;
}
#footer {
position:absolute;
bottom:0;
width:100%;
background:#6cf;
}

Footer is not being shown properly on different device heights

I am having a problem with my footer. I have a page with some content and on some devices (like mobile - in zoomed out view), my page content does not fill parent device height while on some devices, it does.
The footer is creating a problem with these different heights. When the content doesn't fill the parent device height, the footer is shown correctly at the bottom of the page but when the content fills the parent device height and overflows, the footer is shown over the content.
Footer with content not filling Parent height (shows correctly)
Footer with overflown content (doesn't show correctly)
Picture quality is not that clear but the issue is clearly visible.
This is the CSS code I have been using till now.
#footer{
display:block;
margin-right:auto;
margin-left:auto;
position:absolute;
bottom:0;
height:100px;
width: 60%;
text-align:center;
color:green;
font-size:18px;
font-family:Times;
}
How can this be fixed? I want to show the footer at the end of the page when content is overflown.
on your #main element right before the footer (assuming you are using id="main" for the item with the green border, do the following:
#main {
margin-bottom: 100px;
}
EDIT:
<div id="wrapper">
<div id="header"></div>
<div id="main"></div>
<div id="footer"></div>
</div>
#wrapper {
position: relative;
padding-bottom: 110px;
}
whenever you position something absolute you take it outside of the DOM, meaning in this case it sits bottom 0 (based on your css) to the the nearest relatively positioned element. I put the footer html after your wrap or content block and just have it centered by saying
margin 0 auto;
If you need the footer to be absolutely positioned, you could always add a margin-bottom or padding-bottom to the body element. Just make it the 100px of your absolutely positioned element and it should force the content above your positioned element.
Alternatively, you could just set the footer to be positioned static, but you'll lose the ability for the footer to be at the bottom of the screen when your content is too short.

Absolute Positioned Div is hiding my other divs below

Have a look at, http://thomaspalumbo.com
I have this CSS for my website's container:
.graybox {
padding: 0 30px 30px 30px;
background: #ededed;
position:absolute;
left:0;
right:0;
}
Then I have a container on top of that to center that info.
The .graybox container spreads the width of the page like I want but now my footer div is hidden, according to firebug is it actually behind? And up on the page?
Is there a fix for this?
While I'm here can anyone explain the white space on the right side of the page. It comes into effect once the page is resized smaller.
You can use the CSS z-index property to make sure your footer is in front of the content. Z-index only works when the element is positioned though. So make sure you add position:relative to your footer
#footer{
position:relative;
z-index:999;
}
Read more: http://www.w3schools.com/cssref/pr_pos_z-index.asp
EDIT
Just checked out the code of your website, and I don't understand why your graybox is positioned absolutely, this will only make things more complex. The same goes for your menu, why position it absolute, why not just add it in the right order in the HTML in the first place?
EDIT
If you want to center your content but with a background that has a 100% width then you can simply add a container div like so:
HTML
<div class="container">
<div>lorem ipsum....</div>
</div>
CSS
.container{
background:red;
}
.container div{
width:400px;
margin:0 auto;
background:yellow;
}
See JSFiddle here: http://jsfiddle.net/HxBnF/
Currently you cannot do this because you have a container which you set at 980px, don't ever do that unless you are sure you don't want anything to wrap over it, like in this case the background of a div in that container.
in the div style, just assign a z-index value greater than any other z-index such as
.divClass{
position: absolute;
z-index: 1 //if other elements are still visible chose a higher value such as 20 or even higher.
}

DIV inside a DIV wrapper does not keep wrapper background

I've been working on a website with a pretty standard layout, header, content, footer, each being a DIV with a 900px width inside of a page-wide DIV, just like the one described in this question:
Full width background, without a wrapper
Now the problem itself is that whenever the browser window becomes less wide than the specified DIV width (900px) the background of the wrapper seems to disappear, showing the background color of the website itself. This also happens while using the code in the aforementioned question.
This is the CSS code:
#headerwrapper {
height: 229px;
background: url(imagenes/header.gif);
background-repeat: repeat;}
#header {
width:900px;
height:229px;
padding:0px;
margin:0 auto;
}
And this one is the HTML code:
<div id="headerwrapper">
<div id="header">
Content goes here.
</div>
</div>
Any suggestions are appreciated.
you probably can't see the background in the scrollarea. You need to set min-width: 900px; or max-width: 900px; so that the background will be shown in the scrollarea.
If you do not specify width for the #headerwrapper, browser makes it 100% of parent container (div or body). So if width of view area is less than 900px - #header becomes wider than #headerwrapper, so background is not showed for overlapped part. You may add overflow:auto; to #headerwrapper so scrollbars will appear, but i do not think that is a solution. So it is better to add background for the #header or add min-width for #headerwrapper.
P.S. Specifying
min-width:900px;
width:auto !important;
for #headerwrapper should do the trick.

Resources