CSS Only Accordion适用于Chrome,但不适用于Safari

时间:2018-06-10 16:49:37

标签: css

我试图通过创建一个包含所有样式等的单个html文件来运行附加的codepen。

它可以在Chrome上正常运行,但不会显示“grid__description”,因为它应该在用户点击“grid_item”时显示。

这是我的源代码,我在这个文件中列出了css。

请有人帮我理解如何在Safari上使用它吗?

以下是codepen的链接: https://codepen.io/javiervd/pen/MEajJx

一切都很棒!

* {
  box-sizing: border-box;
}

.grid__item {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #aaa;
  min-height: 150px;
  font-size: 5em;
  color: inherit;
  text-decoration: none;
  background: #ddd;
  &:focus+.grid__description {
    max-height: 200px;
    transition: max-height 0.4s ease-in;
  }
}

.grid__description {
  max-height: 0;
  overflow: hidden;
  background: #aaa;
  transition: max-height 0.15s ease-in;
  div {
    padding: 2em;
    box-shadow: inset 0 0 2px #000;
  }
}

@media screen and (min-width: 30em) {
  .grid {
    display: grid;
    grid-template-areas: "item item item" "desc desc desc";
    grid-template-columns: 1fr 1fr 1fr;
  }
  .grid__description {
    grid-area: desc;
  }
}
<div class="grid">
  <a href="#" class="grid__item">1</a>
  <div class="grid__description">
    <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet dolores quos laudantium harum ea minus magnam hic ut tempore. Ipsam doloribus perferendis architecto magnam, exercitationem blanditiis corrupti totam ut praesentium</div>
  </div>
  <a href="#" class="grid__item">2</a>
  <div class="grid__description">
    <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis dolores deserunt alias a earum, expedita ipsam ea tempora voluptatibus. Debitis modi tempore, totam doloribus sapiente qui quaerat eum fugit magni!</div>
  </div>
  <a href="#" class="grid__item">3</a>
  <div class="grid__description">
    <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit magni similique esse, ipsum sapiente voluptate nihil nisi omnis nulla non consequatur veritatis voluptas sit cum sequi eaque, architecto, mollitia dolore.</div>
  </div>
</div>
<div class="grid">
  <a href="#" class="grid__item">4</a>
  <div class="grid__description">
    <div>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, dolorem! Esse earum quis neque soluta, id fugiat magni consequatur placeat praesentium illum a sit ex dolore nisi ipsa similique deserunt!</div>
  </div>
  <a href="#" class="grid__item">5</a>
  <div class="grid__description">
    <div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nulla voluptatibus eos quia sequi totam reprehenderit in cupiditate deserunt facere temporibus libero ut doloremque reiciendis ab commodi quibusdam consequatur corporis?</div>
  </div>
  <a href="#" class="grid__item">6</a>
  <div class="grid__description">
    <div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Iste laborum atque numquam distinctio illum deleniti architecto voluptas modi, repellat non! Itaque numquam architecto pariatur impedit, tempora ab eius sint incidunt.</div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

在Safari上,您需要将tabindex属性添加到要关注的元素。我将这些添加到你的html中,例如:

  <div class="grid">
    <a tabindex="0" href="#" class="grid__item">1</a>
    <div class="grid__description">
      <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet dolores quos laudantium harum ea minus magnam hic ut tempore. Ipsam doloribus perferendis architecto magnam, exercitationem blanditiis corrupti totam ut praesentium</div>
    </div>
    <a tabindex="0" href="#" class="grid__item">2</a>
    <div class="grid__description">
      <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis dolores deserunt alias a earum, expedita ipsam ea tempora voluptatibus. Debitis modi tempore, totam doloribus sapiente qui quaerat eum fugit magni!</div>
    </div>
    <a tabindex="0" href="#" class="grid__item">3</a>
    <div class="grid__description">
      <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit magni similique esse, ipsum sapiente voluptate nihil nisi omnis nulla non consequatur veritatis voluptas sit cum sequi eaque, architecto, mollitia dolore.</div>
    </div>
  </div>
  <div class="grid">
    <a tabindex="0" href="#" class="grid__item">4</a>
    <div class="grid__description">
      <div>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, dolorem! Esse earum quis neque soluta, id fugiat magni consequatur placeat praesentium illum a sit ex dolore nisi ipsa similique deserunt!</div>
    </div>
    <a tabindex="0" href="#" class="grid__item">5</a>
    <div class="grid__description">
      <div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nulla voluptatibus eos quia sequi totam reprehenderit in cupiditate deserunt facere temporibus libero ut doloremque reiciendis ab commodi quibusdam consequatur corporis?</div>
    </div>
    <a tabindex="0" href="#" class="grid__item">6</a>
    <div class="grid__description">
      <div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Iste laborum atque numquam distinctio illum deleniti architecto voluptas modi, repellat non! Itaque numquam architecto pariatur impedit, tempora ab eius sint incidunt.</div>
    </div>
  </div>