I am having an issue where the background color is behaving unexpectedly when the viewport is shrunk to a size smaller than that specified for some of my elements. While the scroll bars appear correctly the background is not what I would expect. When the viewport is as large or larger the backgrounds behave as intended. When inspecting the page elements with Firebug it seems that the body element is not stretching even though content inside of it is. What's causing the backgrounds to behave this way?
I've provided what I believe to be the pertinent html and CSS, but if I've omitted something please let me know.
Shrunk Viewport Example
Enlarged Viewport Example
CSS
html
{
background: #A37C45;
}
body
{
background:
#55688A url("../images/backgrounds/ns_bg.gif") repeat-x scroll 0 0;
}
#container
{
width: 100%;
}
#header
{
width: 730px;
margin-left: auto;
margin-right: auto;
padding: 5px;
overflow: hidden;
}
#main
{
width: 730px;
margin-top: 2px;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
#footer
{
background:
url("../images/backgrounds/grass.png") repeat-x scroll left top;
clear: both;
width: 100%;
overflow: hidden;
padding-top: 30px;
margin-top: 20px;
}
#footercontainer
{
width: 100%;
background-color: #A37C45;
margin-top: -1px;
}
#footercontent
{
width: 730px;
margin-left: auto;
margin-right: auto;
padding-bottom: 25px;
overflow: hidden;
}
HTML
<html>
<body>
<div id="container">
<div id="header">
</div>
<div id="main">
</div>
</div>
<div id="footer">
<div id="footercontainer">
<div id="footercontent">
</div>
</div>
</div>
</body>
</html>
The reason you're seeing this behaviour is because your width: 100% elements are only taking the viewport width as the amount of background they need to render.
You can fix it by adding a min-width declaration to your body element's CSS. Simply set it to the largest nested element's width:
body {
min-width: 730px;
background: #55688A url("../images/backgrounds/ns_bg.gif") repeat-x scroll 0 0;
}
min-width is not supported in IE so use the expression
body {
min-width: 730px;
background: #55688A url("../images/backgrounds/ns_bg.gif") repeat-x scroll 0 0;
/* IE Version */
width:expression(document.body.clientWidth < 730 ? "728px" : "auto" );
}
Related
I am learning how to make an existing site, responsive and something that appears to be so simple, is making me absolutely crazy.
When I apply the max-width-480px style sheet, it is cutting off about 5 px of my left edge. You can tell it is missing because the rounded corners I added in css are cut off abruptly on the left but are nice and smooth on the right. I have spent several hours trying to tweak the wrapper and mainwrapper css and nothing seems to fix it. Any ideas?
Note: that the image for the topwrapper is a set width white background with rounded corners. Since the set sized graphic is not going to be responsive, I have removed it for the smaller screens and just added the border-radius to the mainwrapper div.
NOTE2: I tried to add an image to show you the issue, but because I am a new poster, I was unable to. The site is: www.develdesign.com/WaterWorks Please be sure to view it on your smartphone to see the issue. Thank you.
A snippet of the wrapper related divs in html
<body>
<div id="wrapper">
<div id="topwrapper"></div>
<div id="mainwrapper">
<!-- Header Start -->
<div id="header">
<div class="center">
<!-- Logo Start -->
<div id="logo"><img src="images/wworks/wwlogo239px.png" alt="logo" /></div>
<!-- Logo End -->
<div id="headerright">
<!-- Menu Navigation Start -->
<? require('top-navigation.php'); ?>
<!-- Menu Navigation End -->
</div><!-- end headerright -->
</div><!-- end center -->
</div><!-- end header -->
Regular Desktop Styles (non-responsive css)
#wrapper {
width: 100%;
max-width: 976px;
height: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
margin-bottom: 20px;
}
#topwrapper {
height: 19px;
width: 100%;
max-width: 976px;
background: url(../images/topwrapper.png) no-repeat;
}
#mainwrapper {
width:100%;
max-width: 976px;
background: url(../images/mainwrapper.png) repeat-y;
}
#bottomwrapper {
margin: 0 auto;
height: 55px;
width: 100%;
max-width: 976px;
background: url(../images/bottomwrapper.png) no-repeat;
}
.center {
margin: 0 auto;
width: 900px;
}
/* ----------------------- HEADER -----------------------*/
#header {
width: 960px;
height: 50px;
padding-bottom: 39px;
background: url(../images/bgheader.jpg) bottom center repeat-x;
margin: 0 auto;
}
#headerright {
padding-top: 20px;
width: 670px;
float: right;
position: relative;
}
#logo {
margin-top: 15px;
float: left;
width: 220px;
}
Responsive for max-width-480px
#wrapper {
width: 100%;
}
#topwrapper {
display:none;
}
#mainwrapper { /*white background for all header and maincontent */
border-radius: 5px 5px 25px 25px;
}
#bottomwrapper {
display: none;
}
.maincontent {
width: 60%;
float: left;
}
<!-- HEADER -->
#header {
/*width: 50%;*/
/*height: 50%;*/
/*background-image: none;*/
}
.center {
width: 95%;
}
#headerright{ /* includes phone numbers and full site navmenu */
display:none;
}
#logo {
width: 100%;
}
Can't say for sure but after a quick look, could it not be possible there is padding somewhere knocking it out. If so make sure to set the box-sizing attribute in your css.
Link:
Box Sizing
Also check there is no whitespace between elements, this also effects display: inline-block in such a way that two divs at 50% width won't fit next to each other. You can either set line height to 0 or comment out the whitespace.
I finally figured it out! The mainwrapper had a background image that was also a set width image (like the topwrapper). Once I realized the mainwrapper's background image repeated only y, I removed it and replaced it with a background-color of white instead and it looks great.
#mainwrapper {
width:100%;
max-width: 976px;
background: url(../images/mainwrapper.png) repeat-y;
}
I've been reading a lot of entries to figure out why my content won't force the body and html tags to stretch to 100% of the inner content's height.
My page is here: http://truerenaissance.devmu.com/artisthighlight/
You'll see the background image (set on the body tag) is not stretching to 100% of the page or inner content's height. I am only using position: relative everywhere. I'm also using a 'clearfix' at the bottom of the content.
If anyone has any ideas as to why this is happening, I'd really appreciate it.
html, body { width: 100%; height: 100%; min-height: 100%; padding: 0px; margin: 0px; background: white; font-size: 12pt; font-family: 'Arial'; }
#site-wrapper { width: 775px; height: 100%; min-height: 100%; margin: 0 auto; padding-bottom: 100px; background-color: rgba(255,255,255,.75);
padding: 0px; z-index: 10; }
#site-wrapper .inner { min-height: 100%; padding: 20px 20px 40px 24px; }
.clear:before,
.clear:after {
content:"";
display:table;
}
.clear:after {
clear:both;
}
.fixer { display:block;clear:both;overflow:hidden;width:auto;height:0px;line-height:1px;font-size:1px; }
<html>
<body>
<div id="body-wrapper">
<div id="site-wrapper">
<div class="inner">
</div>
</div>
</div>
</body>
</html>
Thanks!
Well you constrained the body height to the viewport height and you didn't stretch the background vertically.
Remove height: 100% from html and body and use background-size's cover value.
Thanks for the big-ass picture by the way.
Here is the code. I want the DIV.fixed-nav (position:fixed) to completely fit its parent DIV.container of which width may change. Is there a pure CSS solution for this?
CSS:
body {
margin: 0;
padding: 0;
}
.container {
border: 1px solid #000000;
margin: 0 auto;
max-width: 600px;
min-width: 400px;
}
.fixed-nav {
background-color: red;
height: 20px;
position: fixed;
width: 100%;
top: 0;
z-index: 99;
}
.content {
background-color: green;
height: 100px;
margin-top: 20px;
}
HTML:
<div class="container">
<div class="fixed-nav">
</div>
<div class="content">
</div>
</div>
Please check the DEMO.
The problem with fixed is that it will always be relative to the browser window. So if you set 100% height on your fixed container it will be 100% of the browser window.
The only way I could think of to achieve this is to use jQuery. Or if you don't need the menu to be fixed and it could be absolute then height 100% will work.
This is a common question but slightly different from the solutions I found and I've been trying to solve it without success, so if someone could give me a help on this I would appreciate.
I have a #wrapper div that stretches to 100% width and height of browser. So far, so good... Now, inside the #wrapper I need a #content div that auto stretches with the parent div maintaining a 30px margin around it. I (almost) managed to do it but I can't make the #content div stretch in its height.
Here's an example of what I'm trying to do:
This is the CSS code I have:
* {
margin: 0;
padding: 0;
outline: 0;
}
html, body {
height: 100%;
width: 100%;
text-align: center;
cursor: default;
}
#wrapper {
width: 100%;
min-height: 100%;
height: auto !important;
position: absolute;
background: #333;
text-align: center;
}
#content {
/*width: 100%;*/
min-height: 100%;
height: auto !important;
margin: 30px;
overflow: hidden;
background: #ccc;
}
This is the HTML:
<body>
<div id="wrapper">
<div id="content">
This DIV should stretch to 100% height of its parent and body
minus the 30px margin around and resize as the window is resized.<br />
It's working in width but not in height!<br /><br />
Whatever goes in here (a child DIV) no matter its size should not be
visible beyond this DIV boundaries (as the Overflow is set to "hidden")!
</div>
</div>
</body>
And this is what I'm getting in both Chrome and IE:
Any help on this? Is it possible? Am I missing something stupid?
Thanks in advance,
LM
In your .css, replace #content with the following
#content {
overflow: hidden;
background: #ccc;
position: absolute;
top: 30px;
left: 30px;
right: 30px;
bottom: 30px;
}
#content {
min-height:90%;
position:absolute;
margin: 5%;
overflow: hidden;
background: #ccc;
}
I'm trying to stretch the content of a div the height of the page. I've Googled the problem and so far nothing works. The whole thing is starting to give me a headache. Perhaps someone more experienced could take a look at my code? The full stylesheet is >400 lines, so I'm including what is (hopefully) relevant.
"Wrapper" takes up 100% of the page height, whereas "contentShadow" stretches only to the height of the text in the div "content".
Edit: as far as I can tell, every container has its height set to 100%, which whould make "contentShadow" 100% as well. Right...?
Edit 2: I'm starting to see the problem, but don't know how to solve it. While the following code will keep the footer down, it also means that since .wrapper doesn't have height:100%, "contentShadow" will not stretch. The question then is how I keep my footer down while changing this code:
.wrapper {
min-height: 100%;
height: auto !important;
margin: 0 auto -37px;
}
To this:
.wrapper {
height: 100%;
}
Basic structure of the page:
<div id="body">
<div id="headerWrapper"></div>
<div id="wrapper">
<div id="contentShadow">
<div id="#contentWrapper">
<div id="content">
<!-- contentshadow stretches the height of this content and no further, but SHOULD stretch the height of the entire page -->
</div>
</div>
</div>
<div id="push"></div>
</div>
<div id="footer"></div>
Css rules relevant to these divs:
html, body {
height: 100%;
}
#headerWrapper {
height: 314px;
width: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -37px;
}
#contentShadow {
min-height: 100%;
width: 994px;
background-image: url(../images/contentShadow.png);
background-repeat: repeat-y;
margin-right: auto;
margin-left: auto;
}
#contentWrapper {
min-height: 100%;
width: 940px;
margin-right: auto;
margin-left: auto;
padding-right: 16px;
padding-bottom: 16px;
padding-left: 16px;
padding-top: 17px;
background-color: #EDECEC;
overflow: hidden;
}
#content {
min-height: 100%;
}
.footer, .push, {
height: 37px;
}
.footer {
background: white;
clear: both;
height: 37px;
}
You have really wrong code:
.wrapper matched <div class="wrapper"> not <div id="wrapper">.
<div id="#contentWrapper"> is not correct, you should try <div id="contentWrapper">
height: auto; is the problem. The wrapper needs to be 100% height, not auto...
the height: 100% after height: auto !important doesn't make sens, because of the !important keyword.
Maybe it's the default margins and padding, have you tried this?
body {margin: 0px; padding: 0px; }
I had this issue for the better part of my life, but I just solved it for myself, so I'm sharing, just in case somebody else can benefit.
My HTML/BODY selector is set to height:100%.
My container div within the HTML/BODY selector is set to min-height:800px.
My CONTENT div inside of the CONTAINER div didn't have a height, and I had the issue of the div not stretching to the bottom of the page. When I inspected this div, I noticed that for some reason, it was stretching way below its container div, pushing it up and creating that annoying space at the bottom of the page. Once I placed a height on that inside DIV, the issue went away for me.
I hope this helps.
The contentShadow must have overflow: auto. Try this
body, html { height: 100%; margin: 0; padding: 0; }
#container { width: 100%; height: 100%; overflow: auto; display: block; }
<body>
<div id="container">
This should fill the page!
</div>
</body>