ウィンドウ幅(JavaScriptで取得)をPHP変数に設定し、それを使ってdivコンテナの属性を記述したいのですが、以下のコードではうまくいきません...
<?php
header("Content-type: text/css; charset: UTF-8"); // Parsing CSS zu PHP
echo "<script type='text/javascript'>
if(typeof(window.innerWidth) !== 'number') {
if(document.documentElement.clientWidth !== 0) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
}else {
width = window.innerWidth;
height = window.innerHeight;
}
$cwidth = document.write(width);
</script>";
?>
@charset "UTF-8";
#container
{
width: <?php echo $cwidth . 'px'; ?>;
}
あいさつ