【发布时间】:2018-06-05 22:37:16
【问题描述】:
我正在尝试做一些我认为会简单得多的事情,但我遇到了问题。
我网页上的默认标题大小是 1500x500,而在较低分辨率(笔记本电脑)上,这个 1500 显然是个问题。我有一个宏需要这个标头分辨率,并且该宏运行并以 1600x900 屏幕分辨率编写。
所以思考过程是这样的:
获取屏幕分辨率。 (完成)
为 1600x900 设置 IF 屏幕分辨率,当我具有该分辨率并执行某项操作时,它会识别出来,否则,执行其他操作。 (完成)
在 if 中更改图像宽度/高度。 (问题)
所以实际做的事情我遇到了问题。
<center>
<?php
session_start();
if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height']))
{
echo 'User resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];
}
else
if(isset($_REQUEST['width']) AND isset($_REQUEST['height']))
{
echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&height="+screen.height;</script>';
}
?>
<?php if ($_SESSION['screen_width'] == 1600 && $_SESSION['screen_height'] == 900)
{
//Don't change style, this is a resolution we want precise width on
$width1 = 500 +"px";
$height1 = 50 +"px";
}
else
{
//Change style, any other resolution we go for 100%
$width1 = 100 +"%";
$height1 = 100 +"%";
}
?>
//This is the header/image in question.
src="https://i.imgur.com/rGEjK9e.png" style.width = width, style.height =
height1;>
</center>
//This is the old header image code.
<center>
<img src="https://i.imgur.com/C4KSU7g.png" alt="" style="width:1500px;height:500px;”>
</center>
我让它回显以表明我的 if 有效并且它知道我的屏幕尺寸,但我现在想让它只更改 1 个特定的图像宽度/高度作为该 IF 的结果。
我并没有真正用过这种语言。
【问题讨论】:
-
最好在客户端使用 CSS 媒体查询。是否有一些要求应该在服务器端完成?
-
我们所有的网站都是服务器端的。不知道从客户端从哪里开始,并且想法是一旦它起作用,它将被用于其他站点上的脚本。我不知道这是否适用于许多客户的客户端?