PDA

View Full Version : php choosing css


tony09uk
09-16-2011, 09:31 AM
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?

Corrosive
09-16-2011, 09:36 AM
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.

edbr
09-16-2011, 09:37 AM
i think its only possible with javascript ( i may be wrong)

edbr
09-16-2011, 09:40 AM
YOU CAN PLAY WITH THIS TO SELECT DIFFERENT STYLE SHEETS . NOT TESTED <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();

gentleone
09-16-2011, 02:00 PM
you could also use CSS3 media queries
http://webdesignerwall.com/tutorials/css3-media-queries

tony09uk
09-16-2011, 02:18 PM
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)

domedia
09-16-2011, 04:11 PM
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
09-16-2011, 04:14 PM
And for the change in layout based on screen resolution, I +1 the advice about looking into Responsive Design with CSS3 media queries

edbr
09-17-2011, 01:59 AM
a much better solution "a new trick fido" woof woof!!

kellexDC
09-20-2011, 10:07 AM
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:

<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

tony09uk
09-21-2011, 04:34 PM
thanks for your advice