IE 11中的flexbox需要溢出

时间:2017-09-19 10:31:58

标签: html css flexbox overflow

我有一个弹性箱,它的孩子应该向左侧和右侧溢出。这是我的解决方案的代码。它适用于所有浏览器,但在IE 11中不起作用(儿童仅在右侧溢出flexbox)。

我尝试使用overflow-x:visible解决此问题的部分和列表,但它不起作用。正文中的overflow-x属性隐藏了水平滚动,这对我的任务来说没问题。正如你所看到的,我已经为我的CSS使用了autoprefixer,但我没有在前缀中找到解决方案。这是IE flexbox溢出的特殊行为吗? :)

所以我的问题是为什么我的解决方案在IE 11中不起作用,我该怎么做才能解决这个问题?

body{
  width: 1400px;
  margin: 0 auto;
  font-family: "Open Sans", "Arial", sans-serif;
  overflow-x: hidden;
  font-size: 16px;
  line-height: 24px;
  color: #999;
}

.visually-hidden{
  position: absolute;
  clip: rect(0,0,0,0);
  width: 1px;
  height: 1px;
}

.testimonials{
  position: relative;
  height: 576px;
  background-color: #fafafa;
  background-image: url("../img/quotes.png"),
  url("../img/quotes-reversed.png"),
  url("../img/worldmap.png"),
  url("../img/worldmap.png");
  background-repeat: no-repeat;
  background-position: 115px 60px,
  1140px 380px, -290px 205px, 530px -270px;
  background-size: auto, auto, auto, auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  overflow-x: visible;
  -webkit-box-align: start;
      -ms-flex-align: start;
          align-items: flex-start;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  margin-top: 100px;
}

.reviews-catalog{
  padding: 0;
  list-style: none;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  margin-top: 160px;
  overflow-x: visible;
}

.review{
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  position: relative;
  min-width: 470px;
  height:243px;
  background-color: white;
  margin-left: 15px;
  margin-right: 15px;
  -webkit-box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
          box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
}

.review:first-of-type{
  margin-left: 0px;
}

.review:last-of-type{
  margin-right: 0px;
}

.review:first-of-type::before,
.review:last-of-type::before{
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  opacity: 0.6;
}

.review:first-of-type .review-photo,
.review:last-of-type .review-photo{
  opacity: 0.6;
}

.review:first-of-type:hover .review-photo,
.review:last-of-type:hover .review-photo{
  opacity: 1;
}

.review:first-of-type:hover::before,
.review:last-of-type:hover::before{
  opacity: 0;
}

.review-photo{
  display: block;
  border-radius: 50%;
  margin-top: -45px;
  -webkit-box-ordinal-group: 0;
      -ms-flex-order: -1;
          order: -1;
}

.review-author{
  margin: 0;
  margin-top: 30px;
  color: black;
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
}

.review-content{
  margin: 0;
  margin-top: 15px;
  text-align: center;
  max-width: 370px;
  color: black;
}
<section class="testimonials">
      <h2 class="visually-hidden">Other reviews</h2>
      <ul class="reviews-catalog">
        <li class="review">
          <h3 class="review-author">Kevin Smith,</h3>
          <p class="role">Pediatrics student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Kevin Smith,</h3>
          <p class="role">Pediatrics student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Jane Lambert,</h3>
          <p class="role">Psychiatry student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Jane Lambert,</h3>
          <p class="role">Psychiatry student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
        </li>
      </ul>
    </section>

1 个答案:

答案 0 :(得分:0)

如果从.testimonials中删除flex属性并添加这些属性,您将获得相同的跨浏览器结果,其中项目 center 溢出同样向左/右

  display: inline-block;
  left: 50%;
  transform: translateX(-50%);

这就是这样的,inline-block按内容调整大小,left: 50%(连同已设置的position: relative)位置,其左边缘位于其父级中间,在这种情况下,bodytransform: translateX(-50%)会将自己宽度的50%向左移动。

Stack snippet

body{
  width: 1400px;
  margin: 0 auto;
  font-family: "Open Sans", "Arial", sans-serif;
  overflow-x: hidden;
  font-size: 16px;
  line-height: 24px;
  color: #999;
}

.visually-hidden{
  position: absolute;
  clip: rect(0,0,0,0);
  width: 1px;
  height: 1px;
}

.testimonials{
  position: relative;
  height: 576px;
  background-color: #fafafa;
  background-image: url("../img/quotes.png"),
  url("../img/quotes-reversed.png"),
  url("../img/worldmap.png"),
  url("../img/worldmap.png");
  background-repeat: no-repeat;
  background-position: 115px 60px,
  1140px 380px, -290px 205px, 530px -270px;
  background-size: auto, auto, auto, auto;
  /*
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  overflow-x: visible;
  -webkit-box-align: start;
      -ms-flex-align: start;
          align-items: flex-start;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  margin-top: 100px;
  */
  display: inline-block;                    /*  added  */
  left: 50%;                                /*  added  */
  transform: translateX(-50%);              /*  added  */
}

.reviews-catalog{
  padding: 0;
  list-style: none;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  margin-top: 160px;
  overflow-x: visible;
}

.review{
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  position: relative;
  min-width: 470px;
  height:243px;
  background-color: white;
  margin-left: 15px;
  margin-right: 15px;
  -webkit-box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
          box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
}

.review:first-of-type{
  margin-left: 0px;
}

.review:last-of-type{
  margin-right: 0px;
}

.review:first-of-type::before,
.review:last-of-type::before{
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  opacity: 0.6;
}

.review:first-of-type .review-photo,
.review:last-of-type .review-photo{
  opacity: 0.6;
}

.review:first-of-type:hover .review-photo,
.review:last-of-type:hover .review-photo{
  opacity: 1;
}

.review:first-of-type:hover::before,
.review:last-of-type:hover::before{
  opacity: 0;
}

.review-photo{
  display: block;
  border-radius: 50%;
  margin-top: -45px;
  -webkit-box-ordinal-group: 0;
      -ms-flex-order: -1;
          order: -1;
}

.review-author{
  margin: 0;
  margin-top: 30px;
  color: black;
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
}

.review-content{
  margin: 0;
  margin-top: 15px;
  text-align: center;
  max-width: 370px;
  color: black;
}
<section class="testimonials">
      <h2 class="visually-hidden">Other reviews</h2>
      <ul class="reviews-catalog">
        <li class="review">
          <h3 class="review-author">Kevin Smith,</h3>
          <p class="role">Pediatrics student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Kevin Smith,</h3>
          <p class="role">Pediatrics student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Jane Lambert,</h3>
          <p class="role">Psychiatry student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
        </li>
        <li class="review">
          <h3 class="review-author">Jane Lambert,</h3>
          <p class="role">Psychiatry student</p>
          <p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
          <img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
        </li>
      </ul>
    </section>