html - 背景封面仍然使图像太大

标签 html css image flexbox

我正在尝试为我的投资组合显示一堆 Logo 。我有 9 个不同大小的不同 Logo ,它们只是不适合它们的 div 框。我虽然 background-size: cover 可以修复它,但有些东西刚刚关闭。有人能给我指出正确的方向,让这些图像适当缩小,这样就不会剪掉 Logo 吗?

html:

<div class="page-wrapper__content">
  <h2 class="page-wrapper__heading">Projects and Skills</h2>
  <p class="page-wrapper__description">hey</p>
  <div class="imagebox">
    <div class="logorow">
      <div class="logo html"></div>
      <div class="logo css"></div>
      <div class="logo javascript"></div>
    </div>
    <div class="logorow">
      <div class="logo jquery"></div>
      <div class="logo bootstrap"></div>
      <div class="logo sass"></div>
    </div>
    <div class="logorow">
      <div class="logo python"></div>
      <div class="logo django"></div>
      <div class="logo github"></div>
    </div>
  </div>
</div>

CSS:

  .page-wrapper__content {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    flex-wrap: wrap;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    padding: 0 30%;
    color: #fff; //white
    transform: skewX(18deg);
    transition: transform 1s, opacity 1s;
    background-size: cover;
}


  .imagebox {
    border: 3px solid red;
    width: 100%;
    height: 33%;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: space-around;
    .logorow {
      display: flex;
      flex-wrap: nowrap;
      border: 1px solid yellow;
      height: 33%;
      width: 100%;
    }
      .logo {
        background-size: cover;
        border: 1px solid purple;
        height: 100%;
        width: 100%;
      }
    .html {
      background-image: url('../images/html5.png');
    }

最佳答案

只需使用 background-size:contain; 而不是 cover
包含,根据MDN docs :

A keyword that scales the image as large as possible and maintains image aspect ratio (image doesn't get squished). Image is letterboxed within the container. When the image and container have different dimensions, the empty areas (either top/bottom of left/right) are filled with the background-color. The image is automatically centered unless over-ridden by another property such as background-position.

关于html - 背景封面仍然使图像太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33727193/

相关文章:

html - 一个带有垂直文本的 Bootstrap 列

php - 数据 :image/gif;base64 Images Not Animated

javascript - 如何强制进入表单中的下一个输入字段

html - 如何在播放时测量html5视频中的实时FPS

html - 选择选项填充在 chrome 中不起作用

javascript - 我想用 ajax 帖子返回的值更新 html 表单中数字字段的最小值,而不刷新页面

javascript - 使用 JQuery 进行弹出窗口/对话框的最佳方式?

javascript - 通过 mmenu 在 jQuery 插件中选择的菜单永远不会激活

ios - iCarousel 间距不平滑

css - 无法在 Heroku 上加载自定义 CSS