Forum Moderators: phranque
<style>
#container {
position: relative;
max-width: 600px;
width: 100%;
border: 1px solid #333;
border-radius: 10px;
overflow: hidden
}
.abs { position: absolute }
</style>
<div id="container">
<img src="foo.jpg" alt=""
style="width: 100%">
<img src="bar.gif" alt=""
class="abs" style="top: 0; left: 0; z-index: 1; width: 100%">
<img src="example.gif" alt=""
class="abs" style="top: 0; left: 0; z-index: 2; width: 100%">
</div>
<script>
$('#container').height($('#container img').height());
</script>
img {max-width: 100%;} to ensure they resize to the container without distortion. It would apply to all images on the page, but that is likely to be a better UX. If it means a lot of rework you could use the #container.img tag instead.
Don't have a "code" answer, but my shortcut get'er done method is a transparent image loaded from MY system BEFORE the others are loaded... being local that will set the div height.
element.style {
width: 100%;
}
section img {
max-width: 100%;
height: auto;
}
img {
border: 0;
vertical-align: top;
}
Style Attribute {
font-size: 100%;
}
section, p, .arialSmall {
font-size: 12px;
}
html, body {
font-family: Arial, Tahoma, Helvetica, sans-serif;
color: #000;
background: #313943;
height: 100%;
margin: 0;
} var ratio = $('#container').width() / 600;
$('#container').height($('#container').height() * ratio); header("Refresh: 1000;"); // this is a function I've had in my variables.php script for awhile,
// so it's just here for reference
function getFile($url, $getInfo=false) {
$t = false;
if (strpos($url, 'http') === 0) {
$ch = curl_init(filter_var($url, FILTER_VALIDATE_URL));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$t = curl_exec($ch);
if ($getInfo && $t) {
$arr = curl_getinfo($ch);
$t = $arr['http_code'] === 200 ? $arr[$getInfo] : false;
}
curl_close($ch);
}
return $t;
}
// and then in this script
$img = [
'list of image paths',
'to be shown'
];
$i = 0;
foreach ($img as $src) {
$headers = getFile($src, 'content_type');
if (strpos($headers, 'image/') === 0) {
$thisClass = $i === 0 ? false : "top: 0; left: 0; z-index: $i' class='abs";
$i++;
echo <<<EOF
<img src="$src" alt=""
style='width: 100%; $thisClass'>
EOF;
}
}