CSS Grid在Firefox和Safari中不起作用

时间:2018-04-21 10:03:35

标签: css css3 flexbox css-grid

我正在构建一种在CSS网格中显示4个框的帖子网格滑块。我建立了一切,它按预期工作,除了它在Firefox中不起作用。

Firefox和Safari都有显示网格高度的问题。它们导致0或1px。为了解决这个问题,我使用了display:flex和flex-flow设置为row wrap。这适用于Safari,但在Firefox中不起作用。当我从容器中删除flex时它可以在Firefox中运行但是它在Safari中不起作用。

Edge和Chrome两种方式都很好。我迷失在寻找解决方案并试图解决它但仍然有相同的结果。

我使用填充顶部和绝对位置按比例排列'响应网格及其项目。

感谢您的回复。 https://codepen.io/Mariopa/pen/ELjqYr

HTML

<div class="post-grid-slider">
  <div class="post-grid-wrapper">
    <div class="post-grid">
      <div class="post-grid__item">
        <a href="#" target="_self" rel="nofollow" class="post-grid__link">  
         <div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/Inoutic-1024x683)"></div>          
          <div class="subcategory"><span >Category</span></div>
          <h2 class="post-grid__title">Title</h2>
        </a>
      </div>
      <div class="post-grid__item">
        <a href="#" target="_self" rel="nofollow" class="post-grid__link">  
          <div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/kinds-of-food-3320746_1920-1024x683)"></div>         
          <div class="subcategory"><span>Category</span></div>
          <h2 class="post-grid__title">Title</h2>
        </a>
      </div>
      <div class="post-grid__item">
        <a href="#" target="_self" rel="nofollow" class="post-grid__link">  
          <div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/leaf-397870_1920-1024x768)"></div>  
          <div class="subcategory"><span>Category</span></div>
          <h2 class="post-grid__title">Title</h2>
        </a>
      </div>
      <div class="post-grid__item">
         <a href="#" target="_self" rel="nofollow" class="post-grid__link">  
           <div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/grape-hyacinth-1024x679)"></div>          
          <div class="subcategory"><span>Category</span></div>
          <h2 class="post-grid__title">Title</h2>
        </a>
      </div>
    </div>
  </div>
</div>

CSS

.post-grid-slider {
  display:-webkit-box;
  display:-ms-flexbox;
  display:flex;
  -webkit-box-orient:horizontal;
  -webkit-box-direction:normal;
  -ms-flex-flow:row nowrap;
  flex-flow:row nowrap;
  height:100%;
  padding: 0 15px;
}

.post-grid-wrapper {
  -webkit-box-flex: 1;  
  -ms-flex: 1 0 100%;  
  flex: 1 0 100%;
  position: relative;
  width:100%;
  padding-top: 25%;
}

.post-grid {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: auto;
  grid-template-columns: auto;
  -ms-grid-rows: 50% 50%;
  grid-template-rows: 50% 50%;
  grid-column-gap: 0.0625rem;
  grid-row-gap: 0.0625rem;
  width: 100%;
  height: 100%;
}
.post-grid__item {
  position: relative;
  overflow: hidden;
}

.post-grid__item:nth-child(1) {
  -ms-grid-column: 1;
  -ms-grid-column-span: 6;
  grid-column: 1/7;
  -ms-grid-row: 1;
  -ms-grid-row-span: 2;
  grid-row: 1/3;
}

.post-grid__item:nth-child(2) {
  -ms-grid-column: 7;
  -ms-grid-column-span: 4;
  grid-column: 7/11;
  -ms-grid-row: 1;
  -ms-grid-row-span: 1;
  grid-row: 1/2;
}
.post-grid__item:nth-child(3) {
  -ms-grid-column: 7;
  -ms-grid-column-span: 2;
  grid-column: 7/9;
  -ms-grid-row: 2;
  -ms-grid-row-span: 1;
  grid-row: 2/3;
}
.post-grid__item:nth-child(4) {
  -ms-grid-column: 9;
  -ms-grid-column-span: 2;
  grid-column: 9/11;
  -ms-grid-row: 2;
  -ms-grid-row-span: 1;
  grid-row: 2/3;
}

.post-grid__link {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.post-grid__link:hover > .post-grid__thumbnail {
  webkit-transform: scale(1);
  -moz-transform: scale(1);
  -o-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
}

.post-grid__thumbnail {
  width: 100%;
    height: 100%;
    margin: 0px;
    position: absolute;
    background-repeat: no-repeat;
    background-position: left center;
    background-size: cover;
    -webkit-transition: All .7s ease;
    -moz-transition: All .7s ease;
    -o-transition: All .7s ease;
    transition: All .5s ease;
    -webkit-transform: scale(1.20);
    -moz-transform: scale(1.20);
    -o-transform: scale(1.20);
    -ms-transform: scale(1.20);
    transform: scale(1.20);
}

.post-grid__thumbnail::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  -webkit-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  transition: opacity 0.2s;
  background-image: -webkit-gradient(linear, left top, left bottom, from(transparent), to(rgba(0, 0, 0, 0.8)));
  background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
  background-image: -o-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
  background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.8));
}

.subcategory {
  position: absolute;
  top: 15px;
  left: 15px;
  display: inline-block;
  padding: 0 0.5rem;
  background: #A20315;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  z-index: 1;
  line-height: 24px;
}

.post-grid__title {
  position: absolute;
  left: 15px;
  bottom: 15px;
  text-shadow: 0 1px 5px rgba(0,0,0,0.4);
  margin: 0;
  font-weight: 500;
  color: #fff;
}

1 个答案:

答案 0 :(得分:1)

我找到了一个蓝色的解决方案。我从容器和包装中删除了flexbox。我加了高度:0;包装。它似乎在所有浏览器中都有效。

我已经更新了codepen演示。

.post-grid-slider {
  height:100%;
  padding: 0 15px;
}

.post-grid-wrapper {
  position: relative;
  width:100%;
  height: 0;
  padding-top: 25%;
}

.post-grid {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: auto;
  grid-template-columns: auto;
  -ms-grid-rows: 50% 50%;
  grid-template-rows: 50% 50%;
  grid-column-gap: 0.0625rem;
  grid-row-gap: 0.0625rem;
  width: 100%;
  height: 100%;
}
.post-grid__item {
  position: relative;
  overflow: hidden;
}

.post-grid__item:nth-child(1) {
  -ms-grid-column: 1;
  -ms-grid-column-span: 6;
  grid-column: 1/7;
  -ms-grid-row: 1;
  -ms-grid-row-span: 2;
  grid-row: 1/3;
}

.post-grid__item:nth-child(2) {
  -ms-grid-column: 7;
  -ms-grid-column-span: 4;
  grid-column: 7/11;
  -ms-grid-row: 1;
  -ms-grid-row-span: 1;
  grid-row: 1/2;
}
.post-grid__item:nth-child(3) {
  -ms-grid-column: 7;
  -ms-grid-column-span: 2;
  grid-column: 7/9;
  -ms-grid-row: 2;
  -ms-grid-row-span: 1;
  grid-row: 2/3;
}
.post-grid__item:nth-child(4) {
  -ms-grid-column: 9;
  -ms-grid-column-span: 2;
  grid-column: 9/11;
  -ms-grid-row: 2;
  -ms-grid-row-span: 1;
  grid-row: 2/3;
}

.post-grid__link {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.post-grid__link:hover > .post-grid__thumbnail {
  webkit-transform: scale(1);
  -moz-transform: scale(1);
  -o-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
}

.post-grid__thumbnail {
  width: 100%;
    height: 100%;
    margin: 0px;
    position: absolute;
    background-repeat: no-repeat;
    background-position: left center;
    background-size: cover;
    -webkit-transition: All .7s ease;
    -moz-transition: All .7s ease;
    -o-transition: All .7s ease;
    transition: All .5s ease;
    -webkit-transform: scale(1.20);
    -moz-transform: scale(1.20);
    -o-transform: scale(1.20);
    -ms-transform: scale(1.20);
    transform: scale(1.20);
}

.post-grid__thumbnail::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  -webkit-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  transition: opacity 0.2s;
  background-image: -webkit-gradient(linear, left top, left bottom, from(transparent), to(rgba(0, 0, 0, 0.8)));
  background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
  background-image: -o-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
  background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.8));
}

.subcategory {
  position: absolute;
  top: 15px;
  left: 15px;
  display: inline-block;
  padding: 0 0.5rem;
  background: #A20315;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  z-index: 1;
  line-height: 24px;
}

.post-grid__title {
  position: absolute;
  left: 15px;
  bottom: 15px;
  text-shadow: 0 1px 5px rgba(0,0,0,0.4);
  margin: 0;
  font-family: 'Roboto';
  font-weight: 500;
  color: #fff;
}