Forum Moderators: not2easy
Is it possible with CSS to load a different sized graphic for different screen resolutions?
I know it can be done with javascript, but trying to avoid that if possible.
I am working on some webpages that I want to (more or less) fit any screen width from around 700 to 1280.
I'm not so sure about the logic of trying to do this in the first place--at least if there's a significant amount of text for reading in the site.
Unless you are already limiting the width of the block containing the text somehow, it will likely form unreadably long lines at 1280px, and users will have to resize their windows in any case.
-b
Unless you are already limiting the width of the block containing the text somehow, it will likely form unreadably long lines at 1280px, and users will have to resize their windows in any case.
I am actually designing it to work "best" in 1024x, but I also want to avoid scroll bars, overlapping text/graphics, and similar problems.
The long lines are another issue that I am still working on :D. I may have to come up with some way to resize or limit the column width - still not sure how best to do this.
This is my first time trying to do a "totally css" site, and a few things are still being worked out - fixing one issue at a time.
No, there is no way for CSS to know anything about window width or screen resolution. Without Javascript the only thing you can do is use a relative size (100%) for your graphics instead of px.<div style="width:20%;"><img src="" width="100%" alt="" /></div>
Well.. actually.. I did not know that the "width" would work on graphics ;/
Thanks, will give that a try and see if it does what I want.
Well.. actually.. I did not know that the "width" would work on graphics
I think it will, but it will look awful. Resizing an image this way just stretches/shrinks it in the browser. You really, really, really want to avoid doing this.
If I absolutely had to do what you're attempting, here's how I'd go about it:
document.getElementsByTagName('body')[0].id='res1024'; #res1024 #header { background:transparent url(path/to/image.gif) no-repeat top left; } The thing is, that having spent the effort to do step 4, I'd probably just decide that the js parts were pointless in the first place--especially since, at this date anyway, I'd have accounted for the great majority of screen resolutions/browser window sizes anyway with css alone...
-b
This will cause images to resize if the user has set IE to display a larger text size.
An old WW member (BigBaer) who was a whiz at CSS shared this a couple years ago. It is worth looking for his site to see some of the amazing things he pulled off. Combine his name with css tutorials and you should find it. (Unfortunately, some of his work no longer resides on his server:()
WBF
So I may have to just pick a "best size" for those graphics and live with it, or use the JS method where it just loads a different stylesheet that uses a scaled graphic. (Any idea how many people turn off javascript?).
This is only a real problem with 3 graphics - such as the company logo - but they appear on every page.
especially since, at this date anyway, I'd have accounted for the great majority of screen resolutions/browser window sizes anyway with css alone...