背景封面仍然留下太大的图片

时间:2015-11-16 01:24:20

标签: html css image flexbox

我试图为我的投资组合显示一堆徽标。我有9种不同尺寸的不同徽标,但它们并不适合他们的div盒。我虽然背景大小:封面可以解决它,但有些东西是关闭的。有人能指出我正确的方向,以便正确缩小这些图像,以便不切割徽标吗?

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');
    }

1 个答案:

答案 0 :(得分:1)

只需使用background-size:contain;代替cover contain,根据MDN docs

  

一个关键字,可以尽可能地缩放图像并保持图像宽高比(图像不会被压扁)。图像在容器内是letterboxed。当图像和容器具有不同的尺寸时,空白区域(左/右上/下)用背景颜色填充。除非被其他属性(如background-position)覆盖,否则图像会自动居中。