html - 将图像完全放入框中

标签 html css image

我在这里尝试添加一个图像,使其完全适合 div#image-container。我正在使用 CSS 样式:

background-repeat: no-repeat;
background-size: cover;

这有助于将宽度正确地适合 div,但不是高度。我该如何解决这个问题?

我添加了以下代码段:

#image-container {
  width: 90%;
  height: 350px;
  border: 13px solid gold;
  box-sizing: border-box;
  margin-left: 5%;
  margin-top: 18px;
  box-shadow: 0px 0px 7px 3px #000;
  /*position: relative;*/
  background-image: url(/image/Aixcp.jpg);
  background-repeat: no-repeat;
  background-size: cover;
}
<div id="image-container">
</div>

最佳答案

background-size: 100% 100%; 解决了问题

#image-container {
  width: 90%;
  height: 350px;
  border: 13px solid gold;
  box-sizing: border-box;
  margin-left: 5%;
  margin-top: 18px;
  box-shadow: 0px 0px 7px 3px #000;
  /*position: relative;*/
  background-image: url(/image/Aixcp.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
<div id="image-container">
</div>

关于html - 将图像完全放入框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48997710/

相关文章:

java - 使用SWT的ImageData,如何判断png、gif、bmp文件是否具有透明度?

bash - 如何从 gdalinfo 输出中提取特定信息?

html - 如何通过CSS重定位下拉菜单

javascript - 突变观察者 : detecting visibility changes inherited from a parent element

javascript - Hrefs vs JavaScript onclick(关于 Unobtrusive JavaScript)

html - Mozilla Firefox 不从本地机器加载图像

javascript - HTML/CSS/JS切换不同谷歌日历是同一个框架

css - 响应式 CSS 显示 :none and media queries

css - 如何去除手机网站的背景图片?

php - .htaccess 不包括重写 css 和图像