Background image 100% fixed position issue - html

I've made my website background image stretch 100% width and height of the browser window, by applying a background image to the body, and remain fixed position. Also, I've created borders that will also remain fixed, using this method: http://css-tricks.com/body-border/
It works ok as you can see here: http://br-webdesigner.com/test/
The only problem is, the background image is stretching right to the edges of the browser window, instead of to the bounds of the body element (or the green area), even though I've got 10px padding on the html element.
It seems making background-size 100% makes the size 100% of the browser window, not of the containing element.
Is there a way to get around this?
Thanks,

So I altered your CSS a bit try using this:
html{
}
body{
padding:30px;
background:url(images/bg2.svg) no-repeat fixed;
background-size:100% 100%;
margin:0;
}
.site-border{
background:#352e2e;
z-index:10;
}
#top{
position:fixed;
top:0;
left:0;
width:100%;
height:10px;
}
#bottom{
position:fixed;
bottom:0;
left:0;
width:100%;
height:10px;
}
#left{
padding:10px;
position:fixed;
left:0;
top:0;
width:10px;
height:100%;
}
#right{
padding:10px;
position:fixed;
right:0;
top:0;
width:10px;
height:100%;
}

Related

putting img in div leads to them dissapearing

For some reason when I tried to make a background and add images to it the images just dissapear.
.Background1{
position:relative;
top:0%;
left:0%;
height:100%;
width:100%;
content:url("/assets/backgroundlayer1.jpg")
}
.Background2{
position:absolute;
top:35%;
left:25%;
height:75%;
width:50%;
}
<div class="Background1" name="Background1" id="Background">
<img class="Background2" name="Background2" id="Background" src="/asset/Background2.png">
</div>
Edit: I want background2 to fit on background1.
Use the background-image property instead of the content property. The content property is overiding the content of your div, thus removing the image.
.Background1{
position:relative;
top:0%;
left:0%;
height:100%;
width:100%;
background-image:url('/assets/backgroundlayer1.jpg')
}
You have two things wrong .. You are calling the background image with content when you should be using the background property.
CONTENT PROPORTY
BACKGROUND PROPERTY
The second, you're trying to assign a height percentage where it is not allowed (the element is relative).. You need absolute definition (px or pt for example):
.Background1{
position:relative;
top:0%;
left:0%;
height:600px;
width:100%;
background:url("/assets/backgroundlayer1.jpg") no-repeat;

Show a html page within full screen

This is my html site https://dl.dropboxusercontent.com/u/168659703/kappe/without_sidebar/index.html
Currently it is not fit to the full screen. I could not understand how it is calculate the height of the screen. I want that it will fit to the full screen. That means no horizontal scroll bar. Please tell me how can i do that?
body
{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
width:100%;
height:100%;
}
You can use something like this,
body
{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
}

100% width div with padding showing horizontal scrollbar

I have this CSS Code:
.topBar {
width:100%;
height:70px;
position:absolute;
/*position:fixed;
z-index:999;*/
top:0;
left:0;
padding:10px;
color:#000000;
background-color:#eeeeee;
border-bottom:2px solid #F36F25;
}
but because it is 100% wide and has a 10px padding it shows a horizontal scroll bar.
how can i stop this from happening but keep the padding and 100% width?
I have tried:
overflow-x: none;
in my css but i still want the horizontal scrollbar to show when the screen gets too small
Basically the div.topBar is 100% + 10px (x2). So it's actually more than 100% (hence the scroll box). The general way to do this is the add another div inside the parent div and add the padding:10px to that. Another way is to use box-sizing:border-box which actually honours the 100% rule!
Take a look at this sample.
You can use the box-sizing CSS property. Add this to .topBar : box-sizing:border-box;
.topBar {
width:100%;
height:70px;
position:absolute;
/*position:fixed;
z-index:999;*/
top:0;
left:0;
padding:10px;
color:#000000;
background-color:#eeeeee;
border-bottom:2px solid #F36F25;
box-sizing:border-box; /** <- Add this **/
}
<div class="topBar"></div>
This property includes padding (and borders if you have some) in the width you set to the element. so if you set width: 100%; it won't overflow the parent container anymore.
More info about box-sizing on MDN

Keeping Relative Width/Height Elements

I am I using percentages based grid system to build a page for my personal website which uses a relative positioned banner and an absolute positioned div that falls in the center horizontally and at the bottom of the banner vertically. However, because said div is a screenshot of a webpage it is important to keep its height and its width relative to one another so that the image doesn't distort.
Below is a little code and a jsfiddle -
<div id="aps-group-banner">
<div id="aps-group-banner-wrap">
<div class="screenshot-banner"></div>
</div>
</div>
#banner {
height:100%;
background:red;
}
#banner-wrap {
position:relative;
width:67%; height:100%;
}
.screenshot {
position:absolute;
background:url(/img/case-study/aps-group/screenshot-banner.jpg) top left;
background-size:100% 100%;
width:75%; min-height:496px; bottom:0; margin-left:-37.5%; left:50%;
}
http://jsfiddle.net/sHanf/
Hope you guys can help! Thanks in advance
Liam
Maybe I don't understand the question completely, but is this what you need?
http://jsfiddle.net/RpW4r/
I just changed the background-size to 100% auto;
Give this a try:
.screenshot {
position:absolute;
background: url(http://liamhodnett.com/img/case-study/aps-group/screenshot-banner.jpg) bottom left no-repeat;
background-size:100% auto;
width:75%; min-height:496px; bottom:0; margin-left:-37.5%; left:50%;
}
This will scale the background to 100% width and adjust its height to be proportional, plus move it to the bottom of the .screenshot element.
Fiddle link: http://jsfiddle.net/sHanf/7/

absolute child div doesnt size the relative parent div on scaling

I have a question which is asked over a thousand times, I spent whole morning reading simulair question but just cant get mine fixed so hope anyone can help me out.
this is my demo: http://jsfiddle.net/skunheal/4qx6a/1/
#one{
width:100%;
min-height:100%;
background-image:url('http://www.vloerenmantegels.nl/upload/userfiles/Ariostea_Pietre_Black_Ardesia_wi1.jpg');
background-attachment:fixed;
color:#fff;
}
#two{
width:100%;
min-height:100%;
background-color:transparent;
position:relative
}
#content{
min-height:60%;
position: absolute;
bottom:0px;
background:#ff9900;
}
I have 3 divs, all 100% height the first div (div.one) has a picture which is attached fixed The second div (div.two) has an orange textbox div in it(div.container), which is positioned absolute and bottom:0px so it sticks to the footer of div.two. div.two has a transparant background (its white in the fiddle because I cant seem to set it to transparant)
Now when you start scaling the window you see the orange box (div.content) will start expand ing upwards because the text has les space horizantal, but as soon as its the full height of div 2 is just keeps going and starts overlaping div.one, While I want it tp push itself down against div one and make his prant div.two bigger.
How can I fix this because I cant find a way to do this without using javascript.
http://jsfiddle.net/4qx6a/2/
Positioned with relative.
BTW, setting min-height:100% on your container and more than one on the inside is probably not the desired effect, unless you want each one to take up the entire height of the window.
I've made a similar one which you can use. This is working fine if i understood your question correctly.
the HTML
<div id="one"></div>
<div id="two">
<div id="content"></div>
</div>
<div id="three"></div>
the CSS
* {
margin:0;
padding:0;
}
body, html {
height:100%;
}
#one {
width:100%;
height:100%;
background:pink;
}
#two {
position:relative;
width:100%;
height:100%;
background:transparent;
}
#content {
width:100%;
background:grey;
border-top:3px solid black;
position:absolute;
bottom:0;
min-height:60%;
}
#three {
width:100%;
height:100%;
background:green;
}
working Fiddle Link