Solved

Stretch image to half size of screen

Posted on 2010-11-18
2
394 Views
Last Modified: 2012-05-10
Hopefully quite a simple one...

I have an image (radial gradient) which is absolutely positioned top left and is 300px x 300px

I'd like to stretch the image to half the browser window (keeping aspect ratio if poss).

Something as simple as <img src=gradient.jpg width=150%> works in IE but not in mozilla. It also doesn't size to exactly half.

What's the best way to implement something like this?  (if i need to use js that's fine)
0
Comment
Question by:Type25
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
Perhaps something like the following:
<html>
<head>
   <script language="javascript" type="text/javascript">

      function resizeImage()
      {
          var img = document.getElementById('myImage');
	  img.width = document.body.offsetWidth / 2;
      }

   </script>
</head>
<body onload="resizeImage();">
   <img id="myImage" src="logo.gif" />
</body>
</html>

Open in new window

0
 
LVL 9

Author Closing Comment

by:Type25
Comment Utility
That did it. Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now