1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Centrage image avec légende</title>
<meta name="Author" content="NoSmoking">
<meta name="description" content="Centrage image dans la fenêtre d'affichage, en respectant le ratio largeur/hauter, avec légende en bas à gauche.">
<meta name="DVP-discussion" content="d2097247">
<style>
html,body{margin:0;padding:0;font:1em/1.5 Verdana,sans-serif}
h1,h2,h3{margin:.25em 0;color:#006699}
main{display:block;margin:auto;padding:1px 1em;max-width:60em;background-color:rgba(255,255,255,.6)}
section p{margin:auto 1em 2em;text-align:justify}
time{float:right;margin:.5em;font-size:.9em;color:#888888}
footer p{padding:.5em;background:#FFF;}
body {
margin: auto;
max-width: 97vw;
}
.row {
--max-height-image: 100vh;
display: flex;
align-content: center;
align-items: center;
box-sizing: border-box;
/*height: 100vh; /* pour IE si besoin */
height: var(--max-height-image);
margin-bottom: 1em;
max-height: var(--max-height-image);
border: 1px solid #CCC;
overflow: hidden;
}
figure {
position: relative;
margin: auto;
}
img {
display: block;
/*max-height: 100vh; /* pour IE si besoin */
max-height:var(--max-height-image);
max-width: 100%;
}
figcaption {
position: absolute;
bottom: 0;
left: 0;
padding: .5em;
min-width: 50%;
border: 1px solid #CCC;
font-size: .8em;
background: rgba(255,255,255,.8);
}
</style>
</head>
<body>
<header>
<time datetime="2020-12-01">Déc. 2020</time>
<h1>Centrage image avec légende</h1>
</header>
<section id="cadre-img">
<p>Cliquez sur les images pour les afficher pleine fenêtre et redimensionner la fenêtre du navigateur pour voir le redimensionnement opérer.
<div class="row">
<figure>
<img src="https://dummyimage.com/1200x400/069/ffffff" alt="">
<figcaption>Image 1200 x 400</figcaption>
</figure>
</div>
<div class="row">
<figure>
<img src="https://dummyimage.com/400x1200/069/ffffff" alt="">
<figcaption>Image 400 x 1200</figcaption>
</figure>
</div>
<div class="row">
<figure>
<img src="https://dummyimage.com/600x480/069/ffffff" alt="">
<figcaption>Image 600 x 480</figcaption>
</figure>
</div>
<div class="row">
<figure>
<img src="https://dummyimage.com/480x600/069/ffffff" alt="">
<figcaption>Image 480 x 600</figcaption>
</figure>
</div>
</section>
<footer>
<p>Voir la <a href="https://www.developpez.net/forums/showthread.php?t=2097247">discussion sur Developpez.com</a>
</footer>
<script>
const elements = document.querySelectorAll(".row");
elements.forEach((el) => {
el.addEventListener("click", (e) => {
el.scrollIntoView({
behavior: "smooth"
});
});
});</script>
</body>
</html> |
Partager