Note that there are some explanatory texts on larger screens.

plurals
  1. POScaling images in HTML using CSS
    primarykey
    data
    text
    <p>I'm trying to create a HTML page that can be re sized to most modern resolutions, I'm using % for all my div containers and they are scaling nicely but I have images in these containers and they are staying the same size.</p> <p>I don't want the images to lose their aspect ratio but I need them to re size to fit in the containers. My example works fine on a 4:3 ratio screen but on a widescreen the images are being cut off. The image I'm using is 213px wide x 300px high. If I have to use js to solve then that's ok.</p> <pre><code>&lt;div style="position:fixed;top:2%;left:2%;overflow:hidden;height:38%;width:12%;text-align:center;border:.15em solid #000;"&gt; &lt;div style="padding:1% 1% 5% 1%;font-size:90%;font-family:'trebuchet MS', verdana, arial, sans-serif;color:#000;"&gt;&lt;b&gt;TEST&lt;/b&gt;&lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;div style="padding:1%;width:44%;display:inline-block;"&gt; &lt;img src="black_card.jpg" style="max-width:100%;" alt="Black" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload