css - Navbar 仅在 Safari 上全高拉伸(stretch)

标签 css safari

我有一个导航栏,它在除 Safari 之外的所有浏览器中看起来都很出色——它在全屏高度(但不是宽度)处被拉伸(stretch)。 在所有浏览器中它看起来像这样:https://imgur.com/KB1sBlM

enter image description here 在 Safari 中……好吧:https://imgur.com/g1L6wxe

enter image description here

我的第一个假设和怀疑是 position:stickylinear-gradientbox-shadow 但这只是我的怀疑。 甚至不确定这是否是 CSS 问题。我在那里也使用了 react-scroller,所以我的就是这个问题?

这是我的 SCSS 代码:

导航栏一般:

.thematic-area-nav {
  position: sticky;
  position: -webkit-sticky;
  width: 70vw;
  top: 0;
  left: 0;
  z-index: 2;
  font-size: 1.3vw;
  -webkit-box-shadow: 0 0 25px 1px #000000;
  box-shadow: 0 0 25px 1px #000000;
  border-radius: 0 0 5px 5px;
  background: -webkit-gradient(
    linear,
    left top,
    left bottom,
    from($color-background-primary),
    color-stop(50%, rgb(237, 237, 237)),
    to($color-background-primary)
  );
  background: -webkit-linear-gradient(
    top,
    $color-background-primary 0%,
    rgb(237, 237, 237) 50%,
    $color-background-primary 100%
  );
  background: -o-linear-gradient(
    top,
    $color-background-primary 0%,
    rgb(237, 237, 237) 50%,
    $color-background-primary 100%
  );
  background: linear-gradient(
    to bottom,
    $color-background-primary 0%,
    rgb(237, 237, 237) 50%,
    $color-background-primary 100%
  );
  color: black;
  padding: 10px;

  & > * {
    color: black;
  }

  & > ul {
    list-style: none;
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 25% auto;
    grid-template-columns: 25% auto;
  }
}

标志:

.thematic-area-nav__logo {
  -ms-grid-column: 1;
  -ms-grid-column-span: 1;
  grid-column: 1/2;
  -ms-flex-item-align: center;
  -ms-grid-row-align: center;
  align-self: center;
  width: 100%;
  height: 150%;
}

按钮:

.thematic-area-nav__areas {
  -ms-grid-column: 2;
  -ms-grid-column-span: 1;
  grid-column: 2/3;
  display: -ms-grid;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12vw, 16vw));
  grid-gap: 0.5em;
  & > button {
    border-top: none;
    border-bottom: none;
    border-right: 1px solid rgb(218, 218, 218);
    border-left: 1px solid rgb(218, 218, 218);
    border-radius: 5px;
    -webkit-box-shadow: 1px 1px 1px;
    box-shadow: 1px 1px 1px;
    background-color: $color-background-primary;
    font-size: 1vw;
    &:hover {
      color: black;
      -webkit-box-shadow: inset 1px 1px 1px;
      box-shadow: inset 1px 1px 1px;
      font-weight: bold;
    }
    &:focus {
      outline: none;
      -webkit-box-shadow: inset 1px 1px 1px;
      box-shadow: inset 1px 1px 1px;
      font-weight: bold;
    }
  }
}
.thematic-area-nav__singleThematicArea {
  & a {
    text-decoration: none;
    color: black;
  }
  & > * {
    text-decoration: none;
    cursor: pointer;
    color: black;
  }
}

这真的是 CSS 问题吗?

最佳答案

我查看了来自 jsbin 的 html/scss 代码,进行了一些清理并设法实现了我认为接近您的想法的东西。

一些注意事项:

避免使用 vw 和 vh 作为字体大小,除非有充分的理由不这样做。

如果以 % 指定宽度/高度,请始终弄清楚浏览器如何计算它们(问问自己“百分比是多少?”)。

使用https://validator.w3.org/ - 它有帮助。

避免混合使用驼峰命名法和-this__thingy。

保持代码整洁。

HTML

<div class="thematic-area-nav">
  <div class="thematic-area-nav__logo-wrapper">
    <img class="thematic-area-nav__logo" src="https://picsum.photos/200/90" alt="Logo Coaching People">
  </div>
  <ul class="thematic-area-nav__areas">
    <li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 1">Obszar tematyczny 1</a></li>
    <li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 2">Obszar tematyczny 2</a></li>
    <li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 3">Obszar tematyczny 3</a></li>
    <li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 4">Obszar tematyczny 4</a></li>
  </ul>

</div>

SCSS

.thematic-area-nav {
  position: sticky;
  padding: 5px;
  border-radius: 0;
  margin: 0 0 20px;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  font-size: 16px;
  box-shadow: 0 0 25px 1px #000000;
  border-radius: 0 0 5px 5px;
  background: -webkit-gradient(
    linear,
    left top,
    left bottom,
    from($color-background-primary),
    color-stop(50%, rgb(237, 237, 237)),
    to($color-background-primary)
  );
  color: black;
  padding: 10px;
  display: flex;
  flex-direction: row; 
  justify-content: space-between;
  @media (max-width: 420px) {
    display: block;
  }
 }

.thematic-area-nav__logo-wrapper {
   @media (max-width: 420px) {
     text-align: center;
     margin-bottom: .6em;
  }
}
.thematic-area-nav__areas {
  list-style: none;
  margin: 0;
  padding: 0 0 0 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-around;
  flex: 1;
}

.thematic-area-nav__singleThematicArea {
    padding: .6em 1em;
    margin-bottom: .6em;
    text-decoration: none;
    color: black;
    border-top: none;
    border-bottom: none;
    border-right: 1px solid rgb(218, 218, 218);
    border-left: 1px solid rgb(218, 218, 218);
    border-radius: 5px;
    box-shadow: 1px 1px 1px;
    background-color: $color-background-primary;
    &:hover {
      color: black;
      box-shadow: inset 1px 1px 1px;
    }
    &:focus {
      outline: none;
      box-shadow: inset 1px 1px 1px;
    }
}

关于css - Navbar 仅在 Safari 上全高拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54650402/

相关文章:

css - 列出 : Centering a custom bullet with first line of text

css - Chrome 和 Safari 中的 float 错误

javascript 在不同的浏览器中表现不同

ios - 无法使用 ionic2/angular2 在 iOS/Safari 中正确显示日期时间

javascript - 带有隐藏 overflow-x 的父级的 div 上的编程滚动

javascript - 表格不适用于学校元素。我还必须将答案放入数组中

javascript - DIV 元素的 Border-Radius 在 IE8 中不起作用

javascript - 如何在头部设置标题样式 (html)

jquery - 单击离开页面按钮后页面重新加载后,beforeunload 在 Safari 9.1 中不起作用

iphone - 为什么这个苹果触摸图标不起作用?