jquery - 如何将整个图像放入具有他尺寸的div

标签 jquery css image image-resizing

<div class = "container">
  <div class = "row">
    <small>Original picture size is 876x493, I resize it to:</small>
    <div class = "property">
      <img src = "http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Leisure/2009/876/493/big-house-small-house.png?ve=1&tl=1"/>
    </div>
    <small>Result I want to get (in another way):</small>
    <div class = "property">
      <img style = "max-width: 147%" src = "http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Leisure/2009/876/493/big-house-small-house.png?ve=1&tl=1"/>
    </div>
  </div>
</div>

https://jsfiddle.net/40ay7uco/

我想缩小图像以适应 div。 我如何使用 jquery 或 css 做到这一点,而无需像以前那样手动编写。

附注我想保持宽高比

最佳答案

<div id="img" style="width:50px;height:50px">
  <img src="https://via.placeholder.com/150" alt="image" style="width:100%" />
</div>

首先,根据需要给那个 div 适当的大小,然后给你的图像 100% 宽度。

关于jquery - 如何将整个图像放入具有他尺寸的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34694794/

相关文章:

java - 我正在 java 中旋转图像,但想保存旋转图像

image - 在 Matlab 中计算中值图像

javascript - 事件时如何制作不同颜色的 Accordion 标签

javascript - 使用 Javascript/Jquery/PHP 实现菜单栏

javascript - 弹出窗口的位置( View 中心!,而不是页面中心?)

css - Twitter Bootstrap 轮播组件控制 Firefox 中的定位故障

c# - OpenCV 直方图掩码

jquery - 如何创建带有百分比计数器的 jQuery 预加载器?

javascript - 提交后文本消失 jQuery

css - 检查 Sass Map 中的值是否存在