【问题标题】:Display thumbnail of 100x100 with centered image vertically and horizontally with css keeping the aspect ratio显示 100x100 的缩略图,图像垂直和水平居中,css 保持纵横比
【发布时间】:2013-11-10 23:46:39
【问题描述】:

我想以 100x100 缩略图显示图像,该图像将垂直和水平居中保持纵横比,并且必须填充 100x100 缩略图 div,例如800x600 的图像必须垂直填充并从两侧水平溢出。如何使用 css 做到这一点?

【问题讨论】:

  • 我们愿意提供帮助,但请务必向我们展示您尝试过的内容 —那么我们可以帮助您改进实施。没有代码,我们的双手就束手无策。
  • 我什么都没试过
  • 在您尝试做某事或任何事情之前,我们无能为力。我们避免使用勺子喂食的用户。
  • 类似问题:"How to automatically crop and centre an image。另请参阅 background-size CSS 属性。

标签: image css thumbnails


【解决方案1】:

如果你有一些像 Photoshop 这样的绘画程序,请制作一些照片并展示你想要的方式。也许我们会知道如何帮助因为我不明白你想要什么。 如果您只想在 css 的中心对齐图像,请使用 margin:50% 50%;它为您提供 X - 中心和 Y - 中心 + 这取决于它是否是位置:绝对;或者亲戚... 例如:

<div style="width:400px;hegiht:500px;">
<img src="bla.jpg" width="100px" height="100px" style="margin: 50% 50%;" /> // It only will be centered in this Div only!
</div>

【讨论】:

    猜你喜欢
    • 2015-01-03
    • 2015-08-27
    • 1970-01-01
    • 2018-02-16
    • 2016-05-16
    • 2013-05-18
    • 2011-01-29
    • 1970-01-01
    相关资源
    最近更新 更多