1

我有这个功能PHP,它来自我正在工作的一个项目:

  foreach ($reports["included_reports"] as $index => $report_name ) {
    if (! in_array( $report_name, $reports["excluded_reports"])) {
      $optional_reports .= 
      "<div class=\"large-12 columns\">
         <div class=\"panel\">
           <a href=\"./graph_all_periods.php?$graph_args&amp;g=". $report_name ."&amp;height=???&amp;width=???\">
             <img BORDER=0 style=\"padding:2px;\" $additional_cluster_img_html_args title=\"$cluster_url\" SRC=\"./graph.php?$graph_args&amp;g=". $report_name ."&amp;height=???&amp;width=???\" >
           </a>
         </div>
       </div>";
   }
 }

我想调整图像的大小以填充我的 div,但我不能使用width:100%,因为我必须通知widthheightPHP。但是 PHP 是先执行的,我也不知道用户监视器的分辨率。在谷歌搜索我发现我只能通过 JavaScipt 知道用户显示器的分辨率。所以我想知道是否有可能做一些我可以知道用户监控并通知我width和标签中的heigh参数的事情。img

4

2 回答 2

1

确保图像始终填充 div 以将其设置为背景图像并使用 CSS background-size 拉伸它的最佳方法

于 2013-04-10T20:25:26.187 回答
0

在您的 js 中,对于用户监视器尝试window.screen.widthwindow.screen.height. 对于图像尺寸,您可以在 css 中使用 100%,然后使用 js 以 px 和img.clientWidth.

于 2013-04-09T14:16:35.273 回答