PDA

View Full Version : Responsive image problem


mampwamp2
11-17-2012, 06:44 AM
I creating 2 page for testing responsive image, the first is working fine, but the second have some problem.


The script below is perfect, it was responsive for browser.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title><br />
<style>
body{
margin:0;
padding:0;
}
#royalSlider img{
width:2000px;
max-width:100%;
}

</style>
</head>

<body>
<div id="royalSlider"><img src="http://www.deviantart.com/download/338096076/viking_by_greev-d5laklo.jpg"/></img></div>
</body>
</html>

The script below have some problem, the image can't be show if use max-width:100%. Image can't be responsive for browser. How to change the css below to make it responsive image? (html not changing) PLEASE HELP ME TAKE A LOOK FOR PROBLEM BELOW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title><br />
<style>
body{
margin:0;
padding:0;
}
ul.royalSlidesContainer li{
display:block;
margin:0;
padding:0;
list-style:none;
width:2000px;
max-width:100%;
}
</style>
</head>

<body>

<ul class="royalSlidesContainer">
<li class="royalSlide" style="background-image:url(http://www.deviantart.com/download/338096076/viking_by_greev-d5laklo.jpg); "> </li>
</ul>
</body>
</html>

gentleone
11-17-2012, 02:19 PM
the max-width: 100% works only for images that are in the HTML with the img tag.

If you want background-images to be responsive then you can use the CSS3 background-size property. For example:

background-size: cover;

but there are more variants.
http://www.css3.info/preview/background-size/

This is not going to work in older browsers such as IE8 and below, so you will need to create a fallback solution for those.