Basically what I'm trying to do is recreate this site with pure HTML, CSS and jQuery.
At present the site is not doing too well in search results, obviously because it's Flash, so that's what I'm trying to fix.
What I'm looking for is quite complex, but I'll gladly take solutions for any of the seperate parts needed and I'll figure out how to put them all together. I've searched high and low all over the internet and call find anything close to what I want.
Here's what I need. It's mainly the image DIV I'm worried about...
Is this over my head or is it easily done?
Thanks for any help you can give.
Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.
Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.
When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.
html
<div id="first">
<img src="http://api.ning.com/files/HX-j3*PqLLSnezU7hpKPxnpTBF6CprX1BsCZ7AQZDuA2gNOgBgOr6md3zvtnmRxULlNmSpzuh49ycB3VNqtSifGoE3TzUAyS/aishwaryaraiface.jpg">
</div>
css
html,body {height:100%}
#first {height:70%;overflow:hidden;}
img {width:100%}
Demo: http://jsfiddle.net/wMvh6/
The idea is to use img
tag, and make its width
100%. It will keep the aspect ratio and will fill the whole width of the parent div
.
You could also use the CSS background-size
and background-position
properties, without having to write a single line of jQuery. Like so:
#first {
background-image: url('URL-to-image');
background-size: cover;
background-position: center;
}
This would ensure the image fills the #first div.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With