2

I'm having some funny behavior with Safari 9 and a list of links with border.

enter image description here

Reproduction online

I isolated the problem as much as I could. It seems to get solved when:

  • I remove the absolute position from #fp-nav ul li a
  • Or whenever I use a bigger width in #fp-nav ul li a
  • Or when I remove the style #fp-nav ul li:hover a span

And probably there are more cases, but nevertheless none of them make any sense to me, so I believe we are talking about a weird bug in Safari 9.X.

The problem was reported by a developer who found it using a javascript library. (fullPage.js)

Alvaro
  • 40,778
  • 30
  • 164
  • 336

4 Answers4

2

You're right it's a bug with Safari 9.x.

I tested in on thoroughly on windows, osx and linux. It's the same everywhere.

atefth
  • 1,624
  • 13
  • 26
1

I do see the issue in Safari 9, however I believe it's just a matter of how you've coded the solution. I have taken your online solution and coded it properly and there is no bugs anymore.

Considering the animation of the elements only :

  • If you can, I think it makes more sense to add the active class to the li elements. In your case it's easier because the width of the a and span is related to the li so you just need to scale its size for your animation,
  • Only transition the properties that need to change. In your case it's the transform property,
  • What you want is to increase the size of your element without affecting the other li. This is what the scale property is for in CSS,
  • The order of your CSS is important (for the a tag it should be in this order visited, hover and active).

Here is the code (and the JSFiddle):

body {
  background-color: #000;
}

#fp-nav {
  position: fixed;
  z-index: 100;
  height: 100vh; /* IE9+ */
  display: table; /* that will be used to center the li elements */
}

#fp-nav.right {
  right: 17px;
}

#fp-nav ul {
  margin: 0;
  padding: 0;
  /* center the li elements (vertical and horizontal) */
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

#fp-nav li {
  display: block;
  width: 8px;
  height: 8px;
  margin: 1em;
  border: 3px solid green;
  border-radius: 50%; /* 50% is enough to create a circle */
  background-color: #fff;
  overflow: hidden; /* To hide everything outside the li */
  transition: transform 0.3s; /* your transition for the size */
}

#fp-nav a {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  text-decoration: none;
}

#fp-nav li.active,
#fp-nav li:hover {
  transform: scale(1.4); /* the transformation */
}

#fp-nav span {
  /* To remove the text inside the span (better for accessibility) */
  text-indent: 100%;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
}
<div id="fp-nav" class="right">
  <ul>
    <li><a href="#"><span>Page1</span></a></li>
    <li class="active"><a href="#"><span>Page2</span></a></li>
    <li><a href="#"><span>Page3</span></a></li>
    <li><a href="#"><span>Page4</span></a></li>
  </ul>
</div>

Of course you need to include any vendor-prefixes needed (and probably some style for the :active and :visited states).

Let me know if you need any clarification!

UPDATED ANSWER BASED ON LATEST CODE PROVIDED

Here is the updated code based on the latest code provided. As you can see there is no bug.

body {
    background-color: #000;
}
#fp-nav {
    position: fixed;
    top: 20px;
    left:20px;
}
#fp-nav ul {
  margin: 0;
  padding: 0;
}
#fp-nav li {
    display: inline-block;
}
#fp-nav li + li {
  margin-left: -7px; /* it's the size of your border + 4px coming from the inline-block */
}
#fp-nav a {
    display: block;
    color: #fff;
    padding: .5em 1em;
    border: 3px solid red;
    text-decoration: none;
    background-color: black;
}
#fp-nav a:hover {
  transform: scale(1.2);
  transform-origin: top left;
}
#fp-nav a:visited,
#fp-nav a:active {
  outline: none;
}
<div id="fp-nav">
  <ul>
    <li><a href="#">Page 1</a></li>
    <li><a href="#">Page 2</a></li>
    <li><a href="#">Page 3</a></li>
    <li><a href="#">Page 4</a></li>
  </ul>
</div>

As you can see the code is clean, much shorter with less specificity and no !important. If you need to support IE8 and under or Opera mini then you can't use transform properties, otherwise it's best to use it as it doesn't repaint the DOM so it's better for performance. Don't forget to add vendor-prefixes.

Pipo
  • 978
  • 6
  • 19
  • I realised I added the wrong link to the reproduction. [Here's the one](https://jsfiddle.net/a69q2b6r/9/). So, few things: there are no transition, the `active` class is irrelevant and therefore the order, and I prefer not to play with the scale property as it won't work in the same way in all browsers. – Alvaro Apr 10 '16 at 19:14
  • If there is no `transition` then just remove it. In my code I am talking about the CSS pseudo-class `:active` which is usually used for touch screen (https://developer.mozilla.org/en-US/docs/Web/CSS/:active) which is always relevant except if you didn't plan to support touch screen. The order of your CSS is also relevant as it can lead to bugs in some browsers (plus it decreases specificity). The scale property is supported the same way in all modern browsers (IE9+) except Opera Mini (http://caniuse.com/#search=scale). – Pipo Apr 11 '16 at 09:30
  • In my latest fiddle you can see how I removed the transform property, so not the problem. Your jsfiddle doesn't even contain the `:active` style, so that doesn't seem to be the problem either. And well, I do want to support IE 8, and even if I didn't, I used the scale property [here](https://jsfiddle.net/a69q2b6r/14/) and it doesn't solve the problem either. – Alvaro Apr 11 '16 at 10:22
  • I am not saying the problem comes from the `:active` pseudo-class, I am just saying that this how you are supposed to code to avoid any bugs. See my updated code to see how I solved your problem with the `scale` property. – Pipo Apr 11 '16 at 10:56
1

I had the same problem in Safari. What I figured out is, that somehow something is marked as "selected" within the navigation list. So I was able to create a work around using the ::selection selector in my style sheets. In your jsfiddle I made the following update in line 27

#fp-nav ul li a::selection{
    display: inline-block;
    position: absolute;
    width: 100%;
    cursor: pointer;
    text-decoration: none;
}

This worked for me. Maybe it's still useful for your work.

Heiko
  • 71
  • 2
  • Something I forgot: Firefox might ignore the whole block when it detects "::selection". So, you have to add the same block again without the pseudo class. – Heiko Aug 31 '16 at 10:21
1

I know I'm late to the discussion but I found this bug as well and what worked for me is just adding the following to the a link:

-webkit-transform: translateZ(0);

That fixed the issue for me. Don't know what the theory is behind it ;)

ekad
  • 14,436
  • 26
  • 44
  • 46
hmartens
  • 33
  • 5