【问题标题】:How can I get this grid not to resize?我怎样才能让这个网格不调整大小?
【发布时间】:2017-02-21 18:37:24
【问题描述】:

我在下面找到了我正在使用的图像网格(链接),但是目前当网格调整正方形的大小时,我希望它可以使正方形彼此下方而不是调整大小。这怎么可能?我试过添加浮动和调整宽度,但我显然错过了一些愚蠢的东西?

link

CSS

.container {
 border: 1px solid #fff;

ul {
   display: block;
   float: left;
   width: 100%;
}

li {
   box-sizing: border-box;
   display: block;
   float: left;
   overflow: hidden;
   position: relative;
   padding-bottom: 33.3%;
   width: 33.3%;

   background-color: #000;
   border: 2px solid #fff;

&:hover {
  h3 {
    opacity: 1;
    transition: all .3s ease-in-out .1s;
  }
  img {
    opacity: 1;
    transform: scale(1);
  }
}

h3 {
  position: absolute;
  left: 0px;
  min-height: 3em;
  padding: 15px;
  right: 0px;
  top: 0px;
  z-index: 10;

  background: linear-gradient(180deg, rgba(0, 0, 0, .65), rgba(0, 0, 0, 0));
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  line-height: 1.5em;
  opacity: 0;
  transition: all .3s ease-in-out;
 }

img {
  position: absolute;
  bottom: 0;
  left: 0;
  max-height: 110%;
  max-width: 110%;
  opacity: .7;
  right: 0;
  top: 0;
  transform: scale(1.1);
  transition: all .3s ease-in-out;
  z-index: 0;
}
}
}

【问题讨论】:

    标签: html css image grid gallery


    【解决方案1】:

    px 中使用heightwidth 并将display:inline-block 设置为.container li

    .container {
      border: 1px solid #fff;
    }
    .container ul {
      display: block;
      float: left;
      width: 100%;
    }
    .container li {
      box-sizing: border-box;
      display: inline-block;
      overflow: hidden;
      position: relative;
      height:300px;
      width:300px;
      background-color: #000;
      border: 2px solid #fff;
    }
    .container li:hover h3 {
      opacity: 1;
      transition: all .3s ease-in-out .1s;
    }
    .container li:hover img {
      opacity: 1;
      transform: scale(1);
    }
    .container li h3 {
      position: absolute;
      left: 0px;
      min-height: 3em;
      padding: 15px;
      right: 0px;
      top: 0px;
      z-index: 10;
      background: linear-gradient(180deg, rgba(0, 0, 0, 0.65), transparent);
      color: #fff;
      font-size: 16px;
      font-weight: bold;
      line-height: 1.5em;
      opacity: 0;
      transition: all .3s ease-in-out;
      margin: 0;
    }
    .container li img {
      position: absolute;
      bottom: 0;
      left: 0;
      max-height: 110%;
      max-width: 110%;
      opacity: .7;
      right: 0;
      top: 0;
      transform: scale(1.1);
      transition: all .3s ease-in-out;
      z-index: 0;
    }
    <div class="container">
      <ul>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/7/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/1/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/3/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/5/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/6/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/8/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/9/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/abstract/10/" />
        </li>
        <li>
          <h3>Item Number One</h3>
          <img src="http://lorempixel.com/g/650/650/fashion/2/" />
        </li>
      </ul>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      相关资源
      最近更新 更多