I am planning to use a big banner image in my website(976X450).Now in higher resolution monitors the image should stretch to occupy the space. Is there any way to do this with out using different images for different resolution?
views:
42answers:
3
+1
A:
Just start with the detection of screen dimensions and continue from there:
var width = screen.width;
var height = screen.height;
var img = document.getElementById(image_id);
img.height = img.height * width / img.width;
img.width = width;
Update:
Use CSS:
img#in_question { width: 100% }
Anax
2010-07-15 05:48:00
I thought it was supposed to be without javascript? -- Just making sure!
txwikinger
2010-07-15 06:02:03
It was; but I haven't had my coffee yet. Will update.
Anax
2010-07-15 06:03:58
+1 for the updated answer. Not indicating height will keep original proportions, which is intended by OP.
Felipe Alsacreations
2010-07-15 06:16:40
A:
Have you tried using percentages?
<img src="Images/YourImage.png" style="width:100%; height:20%;" alt="I am an image with %" />
or a bit neater with CSS:
HTML:
<img src="Images/YourImage.png" id="HeaderImage" />
CSS:
#HeaderImage {
height: 20%;
width: 100%;
}
Thqr
2010-07-15 06:14:25
A:
HeaderImage {
height: 20%; width: 100%; background-repeat:repeat-x;
}
Prashant
2010-07-15 06:50:32