Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How fill IMG src with JavaScript?

How fill IMG src with JavaScript?

Problem

I have this function in PHP, which came in a project that I' working:

  foreach ($reports["included_reports"] as $index => $report_name ) {
    if (! in_array( $report_name, $reports["excluded_reports"])) {
      $optional_reports .= 
      "
"; } }

I would like to resize the image to fill my div, but I cannot use width:100% 'cause I have to inform the width and height to PHP. But PHP is executed first and I can't know the resolution of user monitor either. Searching in Google I found out I only can know the user monitor resolution via JavaScipt. So I wonder if is possible to do something that I can know the user monitor and inform to my width and heigh parameters in img tag.

Problem courtesy of: Valter Henrique

Solution

best way to ensure that an image will always fill a div to set it as a background image and use CSS background-size to stretch it

Solution courtesy of: MrGlass

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

How fill IMG src with JavaScript?

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×