【问题标题】:round div with a img inside width<height height<width HTML / CSS圆形 div 内部带有 img 宽度<高度高度<宽度 HTML / CSS
【发布时间】:2016-10-07 06:26:10
【问题描述】:

所以我有一个圆形 div,里面有一个 img。问题是:

#mydiv
{
width: 50px;
height: 50px;
overflow: hidden;
border-radius: 25px;
}

现在,如果用户上传的图片高度小于宽度 我可以采用高度:50 像素和宽度:自动;

但是如果用户上传的图片宽度小于高度 我需要制作高度:自动;和宽度:50px;

如果错误,则 div 没有填充此 img。

我该如何解决?

对不起,我是德国的学生,所以我写得不好:/

【问题讨论】:

  • 你可以设置#mydiv img {min-height:100%; min-width:100%;}这样当img太小而无法开始时它应该填充div;)

标签: html css image rounding


【解决方案1】:

把图片放到css中:

background: url(img/...) no-repeat center center; 背景尺寸:封面;

就是这样!

【讨论】:

  • 别忘了,还需要:Background-size:cover ..这样才能填满容器而不是碰到边界框并停止缩放。
  • 谢谢,工作!如果有人有这个想法,那就太容易了。 +1
猜你喜欢
  • 1970-01-01
  • 2013-02-07
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 2015-06-19
  • 2016-08-30
  • 1970-01-01
  • 2013-02-16
相关资源
最近更新 更多