Horizontale und vertikale Bilder gleichmässig skalieren

Es wird ein Container benötigt, in dem ein Pseudo-Objekt mit Padding-Top definiert wird um das Element gleich hoch wie breit zu drücken. Der Bildcontainer darin wird dann mit position: absolute an allen Kanten ausgerichtet.

// HTML
<div class="responsive-container">
    <div class="img-container centerer">
        <img src="http://placehold.it/150x200" alt="" />
    </div>
</div>

 

// CSS
.responsive-container {
    position: relative;
    width: 100%;
    border: 1px solid black;
}

.responsive-container:before {
    content: ' ';
    display: block;
    padding-top: 100%; // force 1:1 ratio
}

.img-container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    text-align:center; /* Align center inline elements */
    font: 0/0 a;       /* Hide the characters like spaces */
}

img {
    vertical-align: middle;
    display: inline-block;
    max-height: 100%;
    max-width: 100%;
}

 

Skalierbare Schrift mit min/max Werten

.rem-solution {
    font-size: calc( {min-size}rem +1
}
.px-solution { /* Not scaleable by user */
    font-size: calc( {min-size}px + ({max-size} - {min-size}) * ( (100vw - {min-width}px) / ( {max-width} - {min-width}) ))
}

 

  1. {max-size} – {min-size}) * {root-size}) * ( (100vw – {min-width}px) / ( {max-width} – {min-width}) []

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *