首页 > 解决方案 > 显示:显示中的弹性:断点中没有在 OSX 上的 Safari 中不起作用

问题描述

给定以下 HTML 和 CSS,myLinks div 隐藏在 1025px 以下的屏幕上,并在 1025px 以上的屏幕上显示为 flexbox。div 仍然隐藏在 Safari 中。

#myLinks {
  display: none;
}

.menu-link {
    padding-top: 0.5em;
}

@media only screen and (min-width: 1025px) {
  #myLinks {
    background-color: transparent;
    display: -webkit-flex;
    display: flex;
    flex-direction: column;
    position: fixed;
    width: 300px;
    top: 10%;
    right: 0;
    height: 85vh;
    max-height: 85%;
    border-radius: 10px;
  }
}
<div id="myLinks" class="menu-link"></div>

真正奇怪的是我只是注意到页面上的元素,但没有被渲染。我可以点击它们,但我看不到它们。将 z-index 更改为 999 并不能解决问题

编辑:这是一个完全构建的示例,我认为没有任何孩子会导致 #myLinks 被隐藏,因为从 #myLinks 中删除的 .menu-card 元素已显示并正常工作,但可能这里的某些内容无法播放与 myLinks 中的某些内容一样...

全页运行

#myLinks {
  display: none;
}

.menu-link { 
    padding-top: 0.5em;
}

.menu-card {
    display: block;
    text-align: center;
    padding-bottom: 0;
    margin-left: 5%;
    margin-right: 5%;
    margin-bottom: 4%;
}

.card-text {
    text-align: center;
    font-size: 0.75em;
    padding: 0;
    margin: 0;
    line-height: 1;
}

/*Style navigation menu images*/
.menu-icon {
    display: block;
    max-width: 15%;
    vertical-align: middle;
    margin: auto;
}

/* Style navigation menu links */
#myLinks a {
    display: block;
    color: white;
    font-size: 1.4rem;
    text-shadow: 2px 2px black;
    text-decoration: none;
    text-align: center;
    margin-top: 0;
    padding: 14px 16px;
    padding-top: 0;
}

@media only screen and (min-width: 1025px) {
#myLinks {
        background-color: transparent;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        position: fixed;
        width: 300px;
        top: 10%;
        right: 0;
        height: 85vh;
        max-height: 85%;
        border-radius: 10px;
    }

.menu-card a {
        position: relative;
        width: 100%;
    }

    .menu-icon {
        position: absolute;
        z-index: 1;
        right: 20%;
        max-height: 55%;
        border-radius: 50%;
        background-color: rgb(148, 181, 201);
        background-color: rgba(148, 181, 201, 0.9);
        transition: all 0.8s;
        max-width: 100%;
    }

    .card-text {
        display: -webkit-flex;
        display: flex;
        align-items: center;
        width: 0;
        top: 6%;
        height: 100%;
        max-height: 0;
        text-align: left;
        font-size: 125%;
        opacity: 0;
        color: #5DCA31;
        background-color: transparent;
        text-shadow: 2px 2px black;
        margin: 0;
        border-color: rgb(148, 181, 201);
        border-color: rgba(148, 181, 201, 0.9);
        border-style: solid;
        border-radius: 90px;
        transition: all 0.8s;
        padding-right: 0;
    }

    .menu-card:hover {
        background-color: transparent;
        opacity: 1;
        transition: all 0.8s;
    }

    .menu-card:hover .menu-icon {
        right: 5%;
    }

    .menu-card:hover .card-text {
        opacity: 1;
        padding-left: 10%;
        max-height: 65%;
        width: 100%;
        border-width: 8px;
        box-sizing: border-box;
        background-color: rgb(148, 181, 201);
        background-color: rgba(148, 181, 201, 0.9);
        padding-right: 100px;
        padding-top: 10px;
        padding-bottom: 10px;
        transition: background-color 0.8s, border-width 0.8s, max-width 0.8s;
    }
}
<div id="myLinks" class="menu-link">
  <div class="menu-card">
      <a href="#">
          <img class="menu-icon" src="https://nuclearterrortoday.org/img/home.jpg">
          <p class="card-text"  id="home">Home</p>
      </a>
  </div>
</div>

标签: htmlcsssafariflexbox

解决方案


尝试使用

@media screen and (min-width: 1025px) {
    #myLinks {
        /* all the styles */
    }
}

要不就

@media (min-width: 1025px) {
    #myLinks {
        /* all the styles */
    }
}

关键字 'only' 隐藏了旧用户代理的样式表。希望这可以帮助!


推荐阅读