Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Background Fit Any Resolution


10 replies to this topic

#1 complexity

    Newbie [Level 1]

  • Banned
  • 14 posts

Posted 16 June 2005 - 05:07 AM

Is it possible to do with html. I have found a few solutions but they dont seem to work. I know it is possible in java. But anyone have the code for html? Would really appreciate it.

#2 rvovk

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 378 posts
  • Gender:Male
  • Location:Slovenia

Posted 16 June 2005 - 06:23 AM

Isn't it just: background: url(yourimage.jpg);

#3 guangdian

    Trap Grand Marshal Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,187 posts
  • Interests:Nothing

Posted 16 June 2005 - 08:12 AM

<body bg="url.img">

you need it fit any resolution.your backgroud must be so little then it can expand your screen.

#4 sxyloverboy

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 302 posts
  • Location:Frankfurt, Germany

Posted 17 June 2005 - 02:17 PM

complexity, on Jun 16 2005, 06:07 AM, said:

Is it possible to do with html. I have found a few solutions but they dont seem to work. I know it is possible in java. But anyone have the code for html? Would really appreciate it.

View Post



I dont think its actualy possible with just html but i know that you can do it with javascript. i found it on a site once where you just needed to change the url to the image in this code. Its a code that would resize according to the size of the window. but plain html? dont think so.

#5 bjrn

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 378 posts

Posted 19 June 2005 - 01:00 PM

Background images are just like normal images in HTML documents, you can't set them to resize to whatever the user has.

You could use some PHP GD functions with some browser sniffing to resize the image before sending it to the client. What you'd have to do is this:
  • When the user comes to your page, check what resolution they are using.
  • Have a PHP function that resizes your background image to the resolution
  • Set the generated image as background image
  • Send all data to the user.
I am assuming you have some high-resolution image that scales down very well, because most resizing doesn't work very well when there are big changes. I am also assuming your background image doesn't work when you put the image side-to-side, repeating both left-to-right and up-to-down, if that works all you have to do is add
body {
background-image: url(your-background.image);
background-repeat: repeat;
}


#6 htmlmaster

    Newbie [Level 2]

  • Kontributors
  • PipPip
  • 27 posts

Posted 23 June 2005 - 01:55 PM

No, its not possible, however you are right, it does work in JavaScript, if you require the script then:
var jswidth = screen.width;
if (jswidth==800) document.write("<div class='main' style='width:63%;'>");
else if (jswidth==1024) document.write("<div class='main' style='width:72%;'>");
else if (jswidth==1152) document.write("<div class='main' style='width:75%;'>");
else if (jswidth==1280) document.write("<div class='main' style='width:77%;'>");
else document.write("<div class='main' style='width:63%;'>");
Name that file homepage.js for your convienience. Link to this file by using
<script type="text/javascript"src="/index/homepage.js"></script>
right before your main content in the homepage. Then make this file:
document.write("</div>");
Name it divclose.js. Place the following code after your content:
<script type="text/javascript"src="/index/divclose.js"></script>
This is untested, but I am almost positive it would work.

#7 bjrn

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 378 posts

Posted 24 June 2005 - 12:07 PM

Uhm, what good would that script be? It makes a div which is somewhat smaller than the screen it is viewed in. And depending on the contents of the div you might get a clipped or crunched image inside it...

#8 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 06 September 2009 - 01:02 PM

how to align in center.Background Fit Any Resolution

hai htmlmaster..,

 I developed my site in 1024*768 screen resolution, when I looked it in 1280*800 screen resolution it doesn't look the same, some tables looks expanded. Thanks a lot I used your code and now it looks as the same but aligned to left the problem is I want to align it to center in higher resolution.

please help..,

-question by jananraj

#9 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 06 September 2009 - 01:06 PM

how to align in center.Background Fit Any Resolution

hai htmlmaster..,  I developed my site in 1024*768 screen resolution, when I looked it in 1280*800 screen resolution it doesn't look the same, some tables looks expanded. Thanks a lot I used your code and now it looks as the same but aligned to left the problem is I want to align it to center in higher resolution. 

 please help..,

-reply by jananraj

#10 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 16 October 2009 - 12:26 AM

This Works !!!!!Background Fit Any Resolution

I have struggled with the exact same dilemma, however I have recently figured it out.

Look no further!

Here is the link to the code and CSS:

http://stackoverflow...d/388817#388817

-reply by Brad






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users