screen size detect - select CSS

D

dE|_

I have started looking into scripts for screen size detect with the
intention of using them to pick from a number of CSS style sheets tailored
to the size.

Is there a good reason why this is not so commonly done? IE am I wasting my
time?

---dE|_---
 
E

Evertjan.

dE|_ wrote on 07 nov 2007 in comp.lang.javascript:
I have started looking into scripts for screen size detect with the
intention of using them to pick from a number of CSS style sheets
tailored to the size.

Is there a good reason why this is not so commonly done?

screen size != window size != window display size.

IE am I wasting my time?

Also FF [fery futile].
 
P

Philip Herlihy

dE|_ said:
I have started looking into scripts for screen size detect with the
intention of using them to pick from a number of CSS style sheets tailored
to the size.

Is there a good reason why this is not so commonly done? IE am I wasting my
time?

---dE|_---

Bad idea. I once found a website I needed to get information from which
appeared totally blank. Eventually looked at the source, and found that
the designer had selected (Javascript) different layouts and image sizes
for a range of different viewport sizes, and none matched my 1920x1620
screen. Hence, a blank page.

Instead, google for "fluid css layout".

Phil, London
 
D

dE|_

Philip Herlihy said:
Bad idea. I once found a website I needed to get information from which
appeared totally blank. Eventually looked at the source, and found that
the designer had selected (Javascript) different layouts and image sizes
for a range of different viewport sizes, and none matched my 1920x1620
screen. Hence, a blank page.

Instead, google for "fluid css layout".

Fluid CSS layout isn't a tool I would ditch, the reason I am looking to use
viewport detect for CSS in this circumstance is solely to select the
background image to be able to span the width of the screen without repeats
or borders when maximised, not affect content layout. Whether they have the
window maximised is not an issue here.

Could you not put a part in the script that says; if none of these
viewports, then = 'other style sheet'

I'm no scripter yet.

--dE|_---
 
D

Dylan Parry

dE|_ said:
the reason I am looking to use viewport detect for CSS in this
circumstance is solely to select the background image to be able to
span the width of the screen without repeats or borders when
maximised,

You can solve this issue with CSS alone... Google the
"background-repeat" CSS property.

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

The opinions stated above are not necessarily representative of
those of my cats. All opinions expressed are entirely your own.
 
D

dE|_

Dylan Parry said:
You can solve this issue with CSS alone... Google the
"background-repeat" CSS property.

Well I've found codes on forums I was not aware of for;

background-repeat:stretch
and even
background-repeat: expand stretch-left stretch-middle stretch-right;

W3c give background-size examples for body and div but I can't get anything
from forums or W3c working on IE7 or FF2.

Anybody got a proven CSS method?

I am aware of X, Y, and no-repeats but they do not /Fill/ the page.

---dE|_---
 
D

dE|_

Yes, you are wasting your time. Disable scripting and let us all know how
well it works then.

Correct me if I'm wrong but can't you have a 'no script' alternative?

---dE|_---
 
P

PeterMcC

dE|_ wrote in
Correct me if I'm wrong but can't you have a 'no script' alternative?

This isn't intended to sound as sarcastic as it might at first read but, if
you have a satisfactory 'no script' alternative, why don't you use that
instead?
 
C

Chaddy2222

Well I've found codes on forums I was not aware of for;

background-repeat:stretch
and even
background-repeat: expand stretch-left stretch-middle stretch-right;

W3c give background-size examples for body and div but I can't get anything
from forums or W3c working on IE7 or FF2.

Anybody got a proven CSS method?

I am aware of X, Y, and no-repeats but they do not /Fill/ the page.
Just set your BG image to a width of 100% in your CSS. That should
work.
 
D

dE|_

PeterMcC said:
dE|_ wrote in


This isn't intended to sound as sarcastic as it might at first read but,
if
you have a satisfactory 'no script' alternative, why don't you use that
instead?

It wouldn't be what I'm trying to achieve, it would just be better than the
blank screen I have been told I'll get if JS was disabled etc.

No insult taken my friend.

---dE|_---
 
D

dE|_

"Chaddy2222"
Just set your BG image to a width of 100% in your CSS. That should
work.

This is what's doing my bloody head in. W3c say;

body {
background-size: auto;
background-image: url(atwork.jpg)}

I tried that with auto and various % but got nothing but the usual repeats.
I replaced with
background-width: 100% but still getting nothing on either browser. Does
anybody actually _use_ this styling?

Sick of this, hanging up the mouse for the afternoon- got some strumming to
do.

---dE|_---
 
D

dE|_

PeterMcC said:
dE|_ wrote in


This isn't intended to sound as sarcastic as it might at first read but,
if
you have a satisfactory 'no script' alternative, why don't you use that
instead?

The browser's elasticy stretching of the image wouldn't be as sharp as
photoshop and I'd rather it was cast iron once determined what viewpoint it
was in.

---dE|_---
 
E

Evertjan.

Chaddy2222 wrote on 07 nov 2007 in comp.lang.javascript:
Just set your BG image to a width of 100% in your CSS. That should
work.

How would you do that? Have you ever done that?
 
D

dE|_

...
If you have a non-script solution then a script solution becomes
redundant.

I'll rephrase; A non-script second best. I'm picky like that.

Mind you the second best- stretchy CSS still hasn't come out of the shadows
so non-script 3rd best it is; lost sides on small screens and borders on
large.

Why is everyone so bloody negative around here?

---dE|_---
 
B

Ben Bacarisse

dE|_ said:
This is what's doing my bloody head in. W3c say;

body {
background-size: auto;
background-image: url(atwork.jpg)}

background-size is CSS3. Not widely implemented yet.
 
D

dE|_

There's really no point.

Think about what you want to do and there's probably a CSS way to achieve
it.

What is it that you're actually trying to do?

First considered for selecting a 2nd style sheet with appropriately sized
background image based on viewport detect.
This method rather than CSS stretch to avoid rubbery pixelated jpeg
stretching by the browser as it will be a sharp focused photo.

Principle; Entire picture does not have to show on a shrunk window, just be
able to fill it when maximised, and prime central content visible when
window is at a 'typical' 75%.

After the above concept I just wondered briefly whether viewport detect -
meets - CSS was something done elsewhere.

Told not, thread cut.

---dE|_---
 
V

VK

First considered for selecting a 2nd style sheet with appropriately sized
background image based on viewport detect.
This method rather than CSS stretch to avoid rubbery pixelated jpeg
stretching by the browser as it will be a sharp focused photo.

Principle; Entire picture does not have to show on a shrunk window, just be
able to fill it when maximised, and prime central content visible when
window is at a 'typical' 75%.

After the above concept I just wondered briefly whether viewport detect -
meets - CSS was something done elsewhere.

Told not, thread cut.

There is one value which is too variable: that is the maximized
height. With numerous native and added (say Google bar) toolbars,
where each can be shown or hidden in most different combinations: you
may spend the rest of your life by making pixel-exact pictures for
each possible situation :) I would suggest to go for a small(?)
compromise by making right and bottom sides of your background
smoothly fading to some color. Based on the sample at http://www.websitefoundry.co.uk/
that could be some variation of orange. By setting the background-
color to the same color you will avoid white bars on screen in any
given case. So CSS could be:

<style type="text/css">
body {
/* Default image for the most expected situation.
What is "most expected" is of course up to you
to decide. The image is faded from the right
and from the bottom to the bgcolor:
*/
background-image: url(1024x740.jpg);
background-repeat: no-repeat;
background-position: left top;
background-attachment: fixed; /* or not */
background-color: orange; /* or whatever else */
}
</style>

Now we have something even if JS is disabled. If it is not then you
may make some runtime fine-tune:

<script type="text/javascript">
/* A list of all available bg images
mapped by their width:
*/
var bgrImages = {
'1024' : '1024x740.jpg',
'1100' : 'X1xY1.jpg',
'1500' : 'X2xY2.jpg'
};

if ((window.screen)&&(window.screen.availWidth)) {
var w = window.screen.availWidth;
/* var h = window.screen.availHeight; */
if (bgrImages[w]) {
document.body.style.backgroundImage = 'url(' + bgrImages[w] + ')';
}
}
</script>
 
V

VK

What does
window.screen and/or window.screen.availWidth have to do with the
width/height of the canvas area of the browser?

Why would not check JavaScript/DOM basics for the answer? But to save
your googling time: window.screen.availWidth and
window.screen.availHeight reports the pixel width and height of canvas
area of the browser in the maximized state: thus the area lesser
application window (window border, toolbars, scrollbars etc.)

It doesn't mean that I do fully agree with OP's approach, but if he
really targeted to do what he's asking for then it is one of options.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top