View Full Version : Aligning background image problem!!
rluka
04-22-2006, 07:22 PM
Currently I am aligning a background image using frames and in some browsers
the image is displayed in a diffrernt part of the page. Is there another way to keep this image in the lower right hand corner?
The page is: http://www.troyka.ca
Thanks..RonL
VIPStephan
04-22-2006, 08:36 PM
Yes, through the magic of CSS (http://www.w3schools.com/css/default.asp). :)
Write this into your <head></head> section:
<style type="text/css">
body {background: url(pictures/3HorsesBySusanKerr.jpg) bottom right fixed no-repeat;}
</style>
You should make more use of CSS anyway as this is the future of styling websites.
rluka
04-23-2006, 08:20 AM
Thanks for the code..Wroks great but the left hand border dissapears when I enter that code. The alignment is perfect. What can I do to keep the left hand border?
Thanks again..your help is greatly appreciated..Ron L
rluka
04-23-2006, 09:07 AM
This is the problem code:
<body background="design/background.gif" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('design/TroykaAlbumBack300x300.jpg')">
The "background.gif" supplies the left margin and page color and its code is in the <body> </body>. It seems that only one "body background" can be used.
Is this correct? Can I include them both together in the <head> </head>.
Or am I totally missing the point?
VIPStephan
04-23-2006, 09:59 PM
Aah, I see!
Yes, you're right, you can only have one background image in one element, but don't worry, we'll get this straight and working. :)
You know what? As I read the term "page color" in your post I got the idea that you actually could specify your page color through CSS too. With the current HTML code (which is too inflexible and makes maintenance a PITA - as we can see now that we're talking ;) ) this wouldn't change too much, though, 'cause you still need a background image for the blue border on the left but it leaves us one more option. :)
... Wow, I had a hard time to figure out how we can solve this without recoding the entire page but in the end I got it. We don't even need a left border background image. :)
You have to follow my instructions carefully now. If you work with me we'll have this done by midnight... nah, just kiddin'. :P OK, now seriously:
At first add a <div></div> with ID to surround (hence contain) all the content. So the opening tag goes directly after the opening <body> tag like so:
<body ...>
<div id="container">
<table ...>
And the closing tag of the div goes right before the closing body tag:
</div>
</body>
Then remove the background attribute from the body tag and the width attributes from the first two tables (ah and as we're already removing... remove the height attributes too, they aren't working properly anyway):
<table width="100%" height="59" border="0" cellpadding="0" cellspacing="0" background="design/topbg.gif">
...
<table width="100%" height="36" border="0" cellpadding="0" cellspacing="0">
And now to the same table tags we removed the width and height from add a class attribute with value... let's say "header" since this is the case:
<table class="header" border="0" cellpadding="0" cellspacing="0" background="design/topbg.gif">
...
<table class="header" border="0" cellpadding="0" cellspacing="0">
Ok, you still with me? :) The basic and most challenging changes are done, now to the fun part. We do all the styling of the left border with CSS. No background image needed.
Remember those <style></style> tags with the long line of code in it I told you? Add this before the line you already have:
body {
padding-left: 56px;
background-color: #52739C;
}
And change the long line of CSS from this:
body {background: url(pictures/3HorsesBySusanKerr.jpg) bottom right fixed no-repeat;}
to this:
#container {
background: #E7EFFF url(pictures/3HorsesBySusanKerr.jpg) bottom right fixed no-repeat;
height: 100%;
border-left: 1px solid #214A6B;
}
And after these lines you simply add
.header {
position: relative;
margin-left: -57px;
}
And preview the result in a browser of your choice. :)
TADAA! We're all done... and even before midnight. :D
rluka
04-24-2006, 03:22 AM
That is so cool....Thank you very much!!
I tried applying the same code to the next page but it didn't work out because of the menu icons on the left..I'll work on it..wont be as fast as you though..Your right CSS seems to be the way to go.
Would I have to creat new menu icons?
Ron L
VIPStephan
04-24-2006, 03:18 PM
You don't have to create new button images. It's easy to apply the same CSS to this page too. The links just have to be "drawn" to the left like the header tables.
For this reason you assign a class to the links too - let's say the class is called "navigation". So you add class="navigation" to each anchor tag:
<a class="navigation" href="" onMouseOver="window.status='home'; return true;" onMouseOut="window.status=''; return true;"><img src="nav/home.gif"...
And in the CSS you add the class name to the .header selector, separated by a comma:
.header, .navigation {
position: relative;
margin-left: -57px;
}
I can't test it myself at the moment, though, so don't hate me if it doesn't work right now. :) If not be patient and we'll get this working later on.
VIPStephan
04-24-2006, 09:07 PM
Ok, I had the chance to try it out and it gave me a hard time again... but in the end I got it. The thing is that if we try to apply new code to a page created by any WYSIWYG editor it will lead to more problems in the process. I'd recommend to recode the website and bring it up to date (HTML wise) if you have the chance.
Now to the soultion of your problem:
It isn't as easy as I thought in the beginning because we have to change more code.
So at first you add the container div again and do the changes from the first page (add classes to header tables etc.).
Then put another div (with ID) around those two paragraphs at the bottom (the copyright and stuff) like this:
<div id="footer">
<p>This site is © Copyright Troyka 2005-2006, All Rights Reserved.</p>
<p><a href="http://www.steves-templates.com" title="Steves free web templates" target="_blank">Free web templates</a></p>
</div>
You'll see why we need this. And note that I removed the align="center" from both paragraphs. We will do this with CSS too.
Ok, this <td> that contains the links... assign the class "navigation" to it. That's easier than assigning this class to every link. So it should look like this:
<td class="navigation" width="140" height="385">
<!-----------navigational buttons go here-------------------------->
<a href="" ... ><img src="nav/home.gif" ... ></a><BR>
... etc. ...
And the thing that gave me the biggest headache was a height="100%" attribute because it made the content go over the edge of the page in Firefox. So delete that. It's the third table in the code, the one that reads like this:
<table width="100%" height="36" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="design/topleft2.gif" width="93" height="36" border="0" alt=""></td></tr></table>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
So now we get to the fun part again, the application of CSS. :) Basically it's the same as on the first page. We only add a little more now, namely this:
.navigation a {
position: relative;
left: -57px;
}
#footer {
position: absolute;
bottom: 0;
width: 90%;
text-align: center;
}
The first rule takes the links and puts them to the left by 57 pixels that it aligns with the blue border.
The second one we needed that the copyright explanation stays at the bottom of the page. As we took out that height="100%" it would come up until it abutts to the bottom of the content (which isn't very much, so it will be pretty much in the center of the page). However, this is only a fix and if there is more content than the screen can view the copyright will still be at the bottom of the screen and overlap the content. For this case we need a different solution.
rluka
04-24-2006, 11:31 PM
:thumbsup: Thanks again for all of your help. I think Im going to redesign the page using CSS. This was just a free template to get things rolling.
The copyright info isnt centered with the rest of the text, but I dont really think it matters. Great job and again, Thank you
Ron Lukawitski
VIPStephan
04-24-2006, 11:48 PM
The copyright info isnt centered with the rest of the text [..]
Well, it's pretty much centered with the screen itself. The text that says "..under construction" isn't really centered because you have that embedded object left of it...
But I don't think that it matters either. :)
rluka
04-25-2006, 02:50 AM
I shouldnt have even brought that up...The pages seem to load faster..Is that possible? Thanks again..Ron L:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.