如何创建全角图像网格?

时间:2019-06-19 16:37:37

标签: html css

我已经创建了具有过滤功能的图像网格,如下所示:

Image Grid

我正在尝试使图像的宽度像您在本网站上看到的那样:

https://www.thewholecaboodle.com/meet-us/

我尝试在#portfoliolist上将宽度设置为100%,但没有解决。

这是整个代码:

html {
  overflow-y: scroll;
}

body {
  font-family: Helvetica, Arial, Verdana;
  background: #efefef url('../img/ticks.png') repeat 0 0;
  margin: 15px 0 0 0;
  font-size: 12px;
}

#info {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
  background: #fcf8e3;
  border: 1px solid #fbeed5;
  width: 95%;
  max-width: 900px;
  margin: 0 auto 40px auto;
  font-family: arial;
  font-size: 13px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
}

#info .info-wrapper {
  padding: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
}

#info a {
  color: #c09853;
  text-decoration: none;
}

#info p {
  margin: 5px 0 0 0;
}

.container1 {
  position: relative;
  width: 960px;
  height: 100%;
  margin: 0 auto;
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  transition: all 1s ease;
}

#filters {
  margin: 1%;
  padding: 0;
  list-style: none;
}

#filters li {
  float: center;
  display: inline-block;
}

#filters li span {
  display: block;
  padding: 5px 20px;
  text-decoration: none;
  color: #666;
  cursor: pointer;
  border-radius: 20px;
}

#filters li span.active {
  background: #e95a44;
  color: #fff;
}

#portfoliolist .portfolio {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
  width: 23%;
  margin: 0%;
  display: none;
  float: left;
  overflow: hidden;
}

.portfolio-wrapper {
  overflow: hidden;
  position: relative !important;
  background: transparent;
  cursor: pointer;
}

.portfolio img {
  max-width: 100%;
  position: relative;
  top: 0;
  -webkit-transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
}

.portfolio .label {
  position: absolute;
  width: 100%;
  height: 40px;
  bottom: -40px;
  -webkit-transition: all 300ms cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 300ms cubic-bezier(0.645, 0.045, 0.355, 1);
}

.portfolio .label-bg {
  background: #e95a44;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 5px;
}

.portfolio .label-text {
  color: #fff;
  position: relative;
  z-index: 500;
  padding: 5px 8px;
  font-size: 16px;
}

.portfolio .text-category {
  display: block;
  font-size: 12px;
}

.portfolio:hover .label {
  bottom: 0;
}

.portfolio:hover img {
  top: 0px;
}


/* #Tablet (Portrait) */

@media only screen and (min-width: 768px) and (max-width: 959px) {
  .container1 {
    width: 768px;
  }
}


/*  #Mobile (Portrait) - Note: Design for a width of 320px */

@media only screen and (max-width: 767px) {
  .container1 {
    width: 95%;
  }
  #portfoliolist .portfolio {
    width: 48%;
    margin: 1%;
  }
  #ads {
    display: none;
  }
}


/* #Mobile (Landscape) - Note: Design for a width of 480px */

@media only screen and (min-width: 480px) and (max-width: 767px) {
  .container1 {
    width: 70%;
  }
  #ads {
    display: none;
  }
}


/* #Clearing */


/* Self Clearing Goodness */

.container1:after {
  content: "\0020";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.clearfix:before,
.clearfix:after,
.row:before,
.row:after {
  content: '\0020';
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}

.row:after,
.clearfix:after {
  clear: both;
}

.row,
.clearfix {
  zoom: 1;
}

.clear {
  clear: both;
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}
<div class="container1">
  <h1 class="ae-1">Meet the <strong style="color: #EF4D26;">Team</strong></h1>
  <p class="ae-3">We always begin with the end in mind; it works that out leadership team is the perfect blend of expertise, creativity, and quirk.</p>
  <ul id="filters" class="clearfix">
    <!--<li><span class="filter active" data-filter=".management, .card, .icon, .logo, .web">All</span></li>-->
    <li><span class="filter" data-filter=".leadership">Leadership Team</span></li>
    <li><span class="filter" data-filter=".creatives">Creatives</span></li>
    <li><span class="filter" data-filter=".support">Support</span></li>
  </ul>
  <div id="portfoliolist">
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="assets/management/rebecca.png" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
  </div>

2 个答案:

答案 0 :(得分:1)

尝试

.portfolio img {
  position: absolute;
  top: 0;
  left : 0;
  width : 100%;
  height : 100%;
  -webkit-transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
}

或者您可以将img标签替换为普通的div,然后执行以下操作:

.img-div {
height:100%;
width:100%;
background-image : url('assets/management/rebecca.png');
background-size : cover;
}
<div class="img-div"></div>

答案 1 :(得分:0)

您可以使用flexbox实现此类功能。最好使用响应式来支持扩展。作为示例,我将其设置为25%。

html {
  overflow-y: scroll;
}

body {
  font-family: Helvetica, Arial, Verdana;
  background: #efefef url('');
  background-size: cover;
  margin: 15px 0 0 0;
  font-size: 12px;
}

#info {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
  background: #fcf8e3;
  border: 1px solid #fbeed5;
  width: 95%;
  max-width: 900px;
  margin: 0 auto 40px auto;
  font-family: arial;
  font-size: 13px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
}

#info .info-wrapper {
  padding: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
}

#info a {
  color: #c09853;
  text-decoration: none;
}

#info p {
  margin: 5px 0 0 0;
}

.container1 {
  position: relative;
  width: 960px;
  height: 100%;
  margin: 0 auto;
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  transition: all 1s ease;
}

#filters {
  margin: 1%;
  padding: 0;
  list-style: none;
}

#filters li {
  float: center;
  display: inline-block;
}

#filters li span {
  display: block;
  padding: 5px 20px;
  text-decoration: none;
  color: #666;
  cursor: pointer;
  border-radius: 20px;
}

#filters li span.active {
  background: #e95a44;
  color: #fff;
}

#portfoliolist {
  display: flex;
  align-items: stretch;
  align-content: space-between;
  flex-wrap: wrap;
  width: 100%;
}

#portfoliolist .portfolio {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -o-box-sizing: border-box;
  margin: 0%;
  width: 25%;
  max-width: 25%;
}

#portfoliolist .portfolio img {
  max-width: 100%;
  position: relative;
  top: 0;
  -webkit-transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 600ms cubic-bezier(0.645, 0.045, 0.355, 1);
}

.portfolio-wrapper {
  overflow: hidden;
  position: relative !important;
  background: transparent;
  cursor: pointer;
}

.portfolio .label {
  position: absolute;
  width: 100%;
  height: 40px;
  bottom: -40px;
  -webkit-transition: all 300ms cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 300ms cubic-bezier(0.645, 0.045, 0.355, 1);
}

.portfolio .label-bg {
  background: #e95a44;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 5px;
}

.portfolio .label-text {
  color: #fff;
  position: relative;
  z-index: 500;
  padding: 5px 8px;
  font-size: 16px;
}

.portfolio .text-category {
  display: block;
  font-size: 12px;
}

.portfolio:hover .label {
  bottom: 0;
}

.portfolio:hover img {
  top: 0px;
}


/* #Tablet (Portrait) */

@media only screen and (min-width: 768px) and (max-width: 959px) {
  .container1 {
    width: 768px;
  }
}


/*  #Mobile (Portrait) - Note: Design for a width of 320px */

@media only screen and (max-width: 767px) {
  .container1 {
    width: 95%;
  }
  #portfoliolist .portfolio {
    width: 48%;
    margin: 1%;
  }
  #ads {
    display: none;
  }
}


/* #Mobile (Landscape) - Note: Design for a width of 480px */

@media only screen and (min-width: 480px) and (max-width: 767px) {
  .container1 {
    width: 70%;
  }
  #ads {
    display: none;
  }
}


/* #Clearing */


/* Self Clearing Goodness */

.container1:after {
  content: "\0020";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.clearfix:before,
.clearfix:after,
.row:before,
.row:after {
  content: '\0020';
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}

.row:after,
.clearfix:after {
  clear: both;
}

.row,
.clearfix {
  zoom: 1;
}

.clear {
  clear: both;
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}
<div class="container1">
  <h1 class="ae-1">Meet the <strong style="color: #EF4D26;">Team</strong></h1>
  <p class="ae-3">We always begin with the end in mind; it works that out leadership team is the perfect blend of expertise, creativity, and quirk.</p>
  <ul id="filters" class="clearfix">
    <!--<li><span class="filter active" data-filter=".management, .card, .icon, .logo, .web">All</span></li>-->
    <li><span class="filter" data-filter=".leadership">Leadership Team</span></li>
    <li><span class="filter" data-filter=".creatives">Creatives</span></li>
    <li><span class="filter" data-filter=".support">Support</span></li>
  </ul>
  <div id="portfoliolist">
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
    <div class="portfolio leadership" data-cat="leadership">
      <div class="portfolio-wrapper">
        <img src="https://images.unsplash.com/photo-1560941186-6f5a4428ca49?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1367&q=80" alt="" />
        <div class="label">
          <div class="label-text">
            <a class="text-title">Her name</a>
            <span class="text-category">President</span>
          </div>
          <div class="label-bg"></div>
        </div>
      </div>
    </div>
  </div>