Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stretch image to half size of screen

Posted on 2010-11-18
2
Medium Priority
?
405 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…

715 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