I'm about to code a responsive layout which will probably contain three different "states".
The quirky part is that much of the text, for example menu items will be images – not my idea and that's nothing i can change i'm afraid.
Since the images will differ slightly, other than size, for each state (for example in the smallest state the menu becomes floating buttons instead of a regular header), i will need to switch images instead of just scaling the same ones.
If it weren't for that i'd probably go with "adaptive-images.com".
So, i need some input on a best practice solution for this.
What i could think of:
Loading the images as backgrounds – feels a little bit filthy.
Insert both versions and toggle css display property – very filthy!
Write a javascript that sets all img links – feels a bit overkill?
Anyone sitting on a good solution? :)
To make an image responsive, you need to give a new value to its width property. Then the height of the image will adjust itself automatically. The important thing to know is that you should always use relative units for the width property like percentage, rather than absolute ones like pixels.
Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.
Create responsive images by adding an . img-responsive class to the <img> tag. The image will then scale nicely to the parent element.
You can make image responsive by using '%' like 100% or etc. But you can't do same with text to make it responsive. You need to use units like 'em' or 'rem' instead of '%' or 'px' to make text responsive. And btw 16px = 1em or 1rem.
Other option. Not need scripts, only CSS.
HTML
<div id="mydiv"> <img src="picture.png" class="image_full"> <img src="picture_mobile.png" class="image_mobile"> </div>
CSS
.image_full{ display:block; } .image_mobile{ display:none; } @media (max-width: 640px) and (min-width: 320px){ .image_full{ display:none; } .image_mobile{ display:block; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With