Jump to content
xisto Community
Sign in to follow this  
complexity

Background Fit Any Resolution hmmm

Recommended Posts

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.

151613[/snapback]


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.

Share this post


Link to post
Share on other sites

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;}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Depending upon the amount of traffic your site gets, this could be a very bad idea and could upset your web host. By using GD to generate an image that's displayed every single time a user visits your page, you're putting a lot of unnecessary strain on the server's CPU. Imagine if you have a site that gets even 10,000 total page hits a month - that's 10,000 new graphics your website has to create on the fly.

 

As a better option, just use a very highly optimized, large background image that looks pleasant even when a portion of the image is cut off for smaller displays. (This is how most sites with large background images handle it.)

 

Best of luck!

 

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.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.