Solved

Stretch image to half size of screen

Posted on 2010-11-18
2
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34162336
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
ID: 34162364
That did it. Thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

635 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