菜单按钮显示在野生动物园的下一行

时间:2017-04-27 00:44:22

标签: html css google-chrome safari

真正奇怪的问题。菜单按钮显示在safari(浏览器和iphone)的下一行。这在chrome和android上正确显示。

Bad Safari enter image description here 请注意,菜单按钮不在黑条上。

好Chrome enter image description here

这是我的代码。这是Fiddle

//make the topnav responsive for mobile screens
function topNav() {
  var x = document.getElementById("myTopnav");
  if (x.className === "myTopnav") {
    x.className += " responsive";
  } else {
    x.className = "myTopnav";
  }
}
body{
  background-color:red;
}

.topnav {
  background-repeat: no-repeat;
  background-size: cover;
  overflow: visible;
  width: 100%;
  padding-bottom: 0px;
}

.topnav nav {
  padding-top: 5px;
  padding-bottom: 8px;
 background-color:black;
  /* Standard syntax (must be last) */
  width: 100%;
}

.topnav nav div {
  width: 85%;
  margin-left: 7.5%;
  margin-right: 7.5%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.link {
  color: white;
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  /* this is futura heavy*/
  width: 11.25%;
  letter-spacing: 2px;
  word-wrap: true;
  display: inline-block;
  vertical-align: top;
  text-align: center;
  /*line-height: 5em;*/
}

.notlink {
  width: 30.4%;
  margin-left: 1%;
  margin-right: 1%;
  display: inline-block;
}

.notlink img {
  width: 100%;
}

.topnav nav .link:hover {
  color: #008ed2;
}

.icon {
  display: none;
  font-size: 32px;
  color: white;
  text-decoration: none;
  text-align: center;
  line-height: 40px;
  min-width: 40px;
  min-height: 40px;
}


/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */

@media only screen and (max-width: 767px) {
  .myTopnav a.link {
    display: none;
  }
  .topnav nav div {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    position: relative;
    top: 0;
    left: 0;
  }
  .icon {
    display: inline-block;
    position: absolute;
    right: 0;
  }
  .notlink {
    width: 70%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .notlink img {
    max-width: 100%;
    max-height: 75px;
    width: auto;
    height: auto;
  }
}

@media screen and (max-width: 767px) {
  .myTopnav.responsive {
    position: relative;
  }
  .myTopnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .myTopnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  .topnav nav div {
    flex-direction: column;
  }
  .myTopnav.responsive a.link:first-child {
    margin-top: 30px;
  }
  .myTopnav.responsive a.link {
    width: 100%;
  }
  .myTopnav.responsive a.notlink {
    width: 70%;
    position: absolute;
    top: 0px;
    text-align: center;
  }
}
<div class="topnav">
  <nav>
    <div class="myTopnav" id="myTopnav">
      <a class="link" href="index.html">HOME</a>
      <a class="link" id="selected" href="about.html">ABOUT</a>
      <a class="link" href="expertise.html">EXPERTISE</a>
      <a class="notlink" href="index.html"><img src="https://www.google.com/logos/doodles/2017/earth-day-2017-5650394117046272-s.png"></a>
      <a class="link" href="industries.html">INDUSTRIES</a>
      <a class="link" href="friends.html">FRIENDS OF MARY</a>
      <a class="link" href="contact.html">CONTACT</a>
      <a href="javascript:void(0);" class="icon" onclick="topNav()">&#9776;</a>
    </div>
  </nav>
</div>

1 个答案:

答案 0 :(得分:1)

只需将//make the topnav responsive for mobile screens function topNav() { var x = document.getElementById("myTopnav"); if (x.className === "myTopnav") { x.className += " responsive"; } else { x.className = "myTopnav"; } }添加到图标

即可

&#13;
&#13;
body{
  background-color:red;
}

.topnav {
  background-repeat: no-repeat;
  background-size: cover;
  overflow: visible;
  width: 100%;
  padding-bottom: 0px;
}

.topnav nav {
  padding-top: 5px;
  padding-bottom: 8px;
 background-color:black;
  /* Standard syntax (must be last) */
  width: 100%;
}

.topnav nav div {
  width: 85%;
  margin-left: 7.5%;
  margin-right: 7.5%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.link {
  color: white;
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  /* this is futura heavy*/
  width: 11.25%;
  letter-spacing: 2px;
  word-wrap: true;
  display: inline-block;
  vertical-align: top;
  text-align: center;
  /*line-height: 5em;*/
}

.notlink {
  width: 30.4%;
  margin-left: 1%;
  margin-right: 1%;
  display: inline-block;
}

.notlink img {
  width: 100%;
}

.topnav nav .link:hover {
  color: #008ed2;
}

.icon {
  display: none;
  font-size: 32px;
  color: white;
  text-decoration: none;
  text-align: center;
  line-height: 40px;
  min-width: 40px;
  min-height: 40px;
}


/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */

@media only screen and (max-width: 767px) {
  .myTopnav a.link {
    display: none;
  }
  .topnav nav div {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    position: relative;
    top: 0;
    left: 0;
  }
  .icon {
    display: inline-block;
    position: absolute;
    top: 0;
    right: 0;
  }
  .notlink {
    width: 70%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .notlink img {
    max-width: 100%;
    max-height: 75px;
    width: auto;
    height: auto;
  }
}

@media screen and (max-width: 767px) {
  .myTopnav.responsive {
    position: relative;
  }
  .myTopnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .myTopnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  .topnav nav div {
    flex-direction: column;
  }
  .myTopnav.responsive a.link:first-child {
    margin-top: 30px;
  }
  .myTopnav.responsive a.link {
    width: 100%;
  }
  .myTopnav.responsive a.notlink {
    width: 70%;
    position: absolute;
    top: 0px;
    text-align: center;
  }
}
&#13;
<div class="topnav">
  <nav>
    <div class="myTopnav" id="myTopnav">
      <a class="link" href="index.html">HOME</a>
      <a class="link" id="selected" href="about.html">ABOUT</a>
      <a class="link" href="expertise.html">EXPERTISE</a>
      <a class="notlink" href="index.html"><img src="https://www.google.com/logos/doodles/2017/earth-day-2017-5650394117046272-s.png"></a>
      <a class="link" href="industries.html">INDUSTRIES</a>
      <a class="link" href="friends.html">FRIENDS OF MARY</a>
      <a class="link" href="contact.html">CONTACT</a>
      <a href="javascript:void(0);" class="icon" onclick="topNav()">&#9776;</a>
    </div>
  </nav>
</div>
&#13;
{{1}}
&#13;
&#13;
&#13;