Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 11:58 AM   PM User | #1
plaedien
New Coder

 
Join Date: Nov 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
plaedien is an unknown quantity at this point
Stop background image from sliding horizontally with browser resize

Hi guys,

This is driving me nuts, and after an exhaustive google search, I cant seem to find a solution to this particular problem.

I have background image in the tag,

Code:
html, body {
 background-color: #ffffff; 
background: url(images/background-bamboo.png) top right no-repeat fixed; 
font-family: sans-serif;
 position: relative;
width: 100%; 
height: 100%; 
min-height: 100%; 
display: table; 
behavior: url(PIE.php); }
which works fine when scrolling up and down, but the problem is when the browser is resized horizontally the background image slides across, when I really want it positioned so that it never leaves the side of the div that sits on top of it.

Here is the site at the moment.

http://onthemend.com.au/test/

at a browser width of about 1525px, this is how I would want the background image to sit.

Any ideas? I know it's most likely something simple, but its doing my head in.

thanks
plaedien is offline   Reply With Quote
Old 11-13-2012, 01:04 PM   PM User | #2
plaedien
New Coder

 
Join Date: Nov 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
plaedien is an unknown quantity at this point
ok i got it to stick to the container using:

Code:
<div id="bg-pic-div">	
	<img src="images/background-bamboo.png" class="bg-pic"/>
</div>

<div id="container">
and css:

Code:
#container {
	width: 960px;
	padding: 0;
	margin: auto;
	position: relative;
	z-index: 10;
}

#bg-pic-div {
	width: 960px;
	padding: 0;
	margin: auto;

}

.bg-pic {
	width: 478px;
	height: 970px;
	position: absolute;
	margin-left: 750px;
}


Now the problem is the bamboo image is causing a horizontal scroll bar. Which means at smaller resolutions the whole site is now off centre....

live view: http://onthemend.com.au/test/
plaedien is offline   Reply With Quote
Old 11-13-2012, 04:22 PM   PM User | #3
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello plaedien,
Typically, that absolute positioned image would be positioned into place instead of margined.

Code:
#bg-pic-div {
	width: 960px;
	padding: 0;
	margin: auto;
  position: relative;

}

.bg-pic {
	width: 478px;
	height: 970px;
	position: absolute;
  top: 0;
  right: -300px;
}
I also think it should relative to #container and that #bg-pic-div is not needed at all.

As for your x scrollbar, your site is much wider than your 960px wide container now. The browser has to deal with the overflow somehow...have you tried overflow: hidden; on the body of the document? That's probably not going to work too well on smaller screens though.

Have you looked for a js solution yet?
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Users who have thanked Excavator for this post:
plaedien (11-14-2012)
Old 11-14-2012, 11:44 AM   PM User | #4
plaedien
New Coder

 
Join Date: Nov 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
plaedien is an unknown quantity at this point
Thank you so much Excavator!

I'd tried overflow: hidden on the 2 divs in question - but not the body - the effect is exactly what I was trying to achieve. Now the scroll bar only appears once the browser goes beneath the 960 of the main container, which is fine (at least until i play with it being responsive).

Thumbs up to you sir!
plaedien is offline   Reply With Quote
Old 11-14-2012, 12:27 PM   PM User | #5
plaedien
New Coder

 
Join Date: Nov 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
plaedien is an unknown quantity at this point
whoops - actually the overflow: hidden killed all vertical scrolling too. Not good.

I couldnt deal with the scroll bar horizontally, so i ended up biting the bullet and doing a large background image which is mostly white - turns out it was only 10kb more than the bamboo by itself anyway - so what the hell. Found this code that makes it work perfectly:

Code:
html, body {
    background: #fff url(images/background-bamboo-large.png) no-repeat center top;
    padding: 0;
    margin: 0;
    width: 100%;
    display: table;
    height: 100%;
    min-height: 100%;
	font-family: sans-serif;
	behavior: url(PIE.php);
}
from here: http://webdesignerwall.com/tutorials...rge-background

now works like a charm!

http://onthemend.com.au/test/
plaedien is offline   Reply With Quote
Old 11-14-2012, 02:40 PM   PM User | #6
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Perfect solution, good job!
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:40 AM.


Advertisement
Log in to turn off these ads.