Resize Images as viewport resizes without sides being cut off

橙三吉。 提交于 2019-12-03 21:59:05

you use:

max-width: 100%;
height: auto;
width: auto; /* for ie9 */

This will make whatever you assign the css to resize dynamically to fit its container based on the max-width: 100% statement. If you would like it differently, change the max width statement accordingly.

I had the same problem because I'm using the same jquery plugin (ie-slider). I found out that the image is passed additional (inline) styles from the Javascript code and in fact it is just shifted-left and not actually cut off. The code passes dynamic values to the tag which are got from the image itself at the time of re/load in a particular viewport width. The author uses this in the .js file.

var $img = $(this);
imgDim = _self._getImageDim( $img.attr('src'));  //gets the dimensions from the image

He then gives the image a margin-left like so

$img.css({marginLeft: imgDim.left}); //assigns a new margin-left, overrides any value set for this property in the .css file because it's inline

When the viewport width gets smaller this is always a negative value. The work around is to set

$img.css({marginLeft: 0});

It worked fine for me after, with no arising issues from the change. Good luck.

I have a simple solution for that. Just give the width parameter in terms of view-port percentage.

Syntax :

width: <Percentage>vw;

Example :

<img src="Resources/Head.png" alt="" style="width: 100vw; height: 85px">

Here, the height of the image is fixed but the width will be resized to 100% of the view-port, whatever its size may be.

Hope this helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!