logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-16-2011, 10:31 AM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default php choosing css

I am redesigning my site and would like to have decided on a layout, however this layout is going to be around 950-1000 pixels(i know thats considered a it wide but my site is about photo editing so most users should be ok). But i a back up layout which conforms to the usual 800px. What i would like to know, is it possible to write a php script that can work out a users screen size and apply the appropriate css for that screen?
tony09uk is offline   Reply With Quote
Old 09-16-2011, 10:36 AM   #2
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

I don't think it is, or not the whole story anyway. Because PHP is sever side it doesn't know what screen res a user has. You need javascript because that is client side.
Corrosive is offline   Reply With Quote
Old 09-16-2011, 10:37 AM   #3
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

i think its only possible with javascript ( i may be wrong)
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 09-16-2011, 10:40 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

YOU CAN PLAY WITH THIS TO SELECT DIFFERENT STYLE SHEETS . NOT TESTED
Code:
<script language="JavaScript">
var smallStylesheetLink = "small.css";
var normalStylesheetLink = "normal.css";
function setStyle() {
    var width, height;
    if(window.innerWidth) {
        width = window.innerWidth;
        height = window.innerHeight;
    }
    else if(document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    }
    else if(document.body.clientWidth) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    var stylesheetLink = document.getElementById("stylesheetLink");
    var useSmall = (width <= 800 && height <= 600);
    stylesheetLink.setAttribute("href", (useSmall ? smallStylesheetLink : normalStylesheetLink));
}
setStyle();
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 09-16-2011, 03:00 PM   #5
gentleone
gentleone's Avatar
 
Join Date: Nov 2009
Location: Rhodes, Greece
Posts: 2,837
Default

you could also use CSS3 media queries
http://webdesignerwall.com/tutorials/css3-media-queries
__________________
www.gentlemedia.nl
gentleone is offline   Reply With Quote
Old 09-16-2011, 03:18 PM   #6
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

thanks for that i will have a try, see what i can do. While were on the suject of javascript, which is better to create a quiz. I want to make something with nice chunky multiple choice boxes and a circle is drawn round the choosen box when it is seleced. (similar to a pub quiz machiene look)
tony09uk is offline   Reply With Quote
Old 09-16-2011, 05:11 PM   #7
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

Quote:
Originally Posted by tony09uk View Post
thanks for that i will have a try, see what i can do. While were on the suject of javascript, which is better to create a quiz.
My guess is that no JavaScript would be the best option. Use HTML and CSS.
domedia is offline   Reply With Quote
Old 09-16-2011, 05:14 PM   #8
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

And for the change in layout based on screen resolution, I +1 the advice about looking into Responsive Design with CSS3 media queries
domedia is offline   Reply With Quote
Old 09-17-2011, 02:59 AM   #9
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

a much better solution "a new trick fido" woof woof!!
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 09-20-2011, 11:07 AM   #10
kellexDC
 
Join Date: Sep 2011
Posts: 3
Default

Quote:
Originally Posted by tony09uk View Post
I am redesigning my site and would like to have decided on a layout, however this layout is going to be around 950-1000 pixels(i know thats considered a it wide but my site is about photo editing so most users should be ok). But i a back up layout which conforms to the usual 800px. What i would like to know, is it possible to write a php script that can work out a users screen size and apply the appropriate css for that screen?

with a combination of javascript and php, i think you can do it.

something like this:

Code:
<script language="javascript">
if (window.location.search == "") {
window.location.href = window.location + "?width=" + screen.width + "&height=" + screen.height;
} 
</script>

Then create a file called screen.php and use this:

<?php
$width = $_get['width'];
$height = $_get['height'];

echo "You are using a $width x $height screen resolution";
// And set them into cookies as well.
?>

you can also check this: http://www.webmasterworld.com/forum88/4700.htm

Last edited by edbr; 09-21-2011 at 05:24 AM.. Reason: signature link
kellexDC is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com