1

I was really unsure what to title this question so I think the best way to explain is with a snippet:

$(document).ready(function () {

  $(".navbar-toggle").on("click", function () {

           $(".navbar").toggleClass("open");
           $(".navbar-toggle").toggleClass("open");

    });            
});
html {
    font-family: "Raleway", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
    font-weight: normal;
    color: #888;
}

html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
ul,
p {
    margin: 0;
    padding: 0;
    font-weight: normal;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    border: none;
    -webkit-appearance: button;
    cursor: pointer;
}

.navbar {
    background: rgba(255, 236, 176, 0.97);
    color: #555;
    line-height: 50px;
    display: none;
    position: relative;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    z-index: 99;
}

.navbar-fixed {
    position: fixed;
    top: 0;
}

.navbar-brand {
    display: inline-block;
    padding: 0 15px;
}

.navbar-mobile {
    background: #ffecb0;
    position: fixed !important;
    top: -100%;
    display: block;
    height: 275px;
    width: 100%;
    overflow-y: auto;
    opacity: 0.0;
    transition: .3s ease
}

.navbar.open {
    opacity: 1.0;
    top: 0;
}

.navbar-mobile .container {
    padding: 0;
}

.navbar-toggle {
    background: #ffecb0;
    position: fixed;
    display: block;
    top: 10px;
    left: 15px;
    padding: 9px 10px;
    border-radius: 5px;
    z-index: 100;
    background-image: none;
    outline: none;
}

.navbar-toggle .icon-bar {
    background-color: #555;
    display: block;
    width: 22px;
    height: 2px;
    border-radius: 1px;
    transition: .3s ease;
}

.navbar-toggle .icon-bar+.icon-bar {
    margin-top: 4px;
}

.navbar-toggle.open .icon-bar:first-child {
    transform: translate(0, 6px) rotate(225deg);
}

.navbar-toggle.open .icon-bar:nth-child(2) {
    opacity: 0;
}

.navbar-toggle.open .icon-bar:last-child {
    transform: translate(0, -6px) rotate(135deg);
}

nav ul {
    list-style: none;
    text-align: center;
}

nav a {
    position: relative;
    display: block;
    font-size: 16px;
    font-weight: 500;
}

nav li a:hover {
    color: black;
    background-color: #ffe389;
}

nav li a.active {
    color: white;
    background-color: #847d64;
}
.btn {
     
}

.navbar-button {
    color: #fff;
    display: inline-block;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 1px;
    text-align: center;
    overflow: hidden;
    transition: .3s;  
    background-color: #a48eff;
    border-color: #8c6aff;
    line-height: 1;
    padding: 10px 10px;
    margin: 0 15px;
}

.navbar-button:hover {
    background-color: #b9a8ff;
    color: white;
    border-color: #ad94ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="navbar-toggle" type="button" role="button">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>

        <nav class="navbar navbar-mobile">
            <div class="container">
                <a href="test.html" class="navbar-brand"></a>
                <div class="navbar-items">
                    <ul>
                        <li><a href="test.html" class="active">Home</a></li>
                        <li><a href="test2.html">Link 2</a></li>
                        <li><a href="test3.html">Link 3</a></li>
                        <li><a  class="button navbar-button" href="contact.html">Call to Action</a></li>
                    </ul>
                </div>
            </div>
        </nav>

As you can see I have a mobile navbar collapse/expand button which is working fine. But for some reason, only in Mac OS Safari, when the button is clicked something is getting selected and the blue highlight is appearing.

I have no idea what is causing this and I've tried a few different ideas to fix it. As you can see I tried adding onfocus="blur()" to the button but that didn't work. I also tried adding user-select: none; to the button and also the span tags inside but that didn't work either.

It's not a massive issue because usually this button will only be visible when the user is looking at my website on their phone and the problem doesn't occur there. But it is really irritating me and I'd like to fix it so any help is greatly appreciated :)

Thanks in advance.


UPDATE

Thank you for all your answers. The solution you have all given is to add .navbar-toggle {outline: 0;} or outline: none; or some variation of this. But this isn't working for me. In fact, all your snippets still have the same problem when I view them. Any idea why I'm not seeing the same result as you guys?

Just to be clear about the behaviour I am seeing, here is a screenshot of Dev_NIX's snippet running after I have just opened and closed the nav menu by clicking the button:

enter image description here


ANOTHER UPDATE

I've tried running this code snippet from another version of Safari on another Mac and there is no issue! So I guess it must just be some strange bug with my version of Safari (9.1). So the problem hasn't been solved but it seems to be unique to me so I'm not gonna worry about it any longer :)

Thanks again for all your answers!

Redtama
  • 1,603
  • 1
  • 18
  • 35

4 Answers4

3

Try setting the outline to none:

button.navbar-toggle{ outline:none; }

$(document).ready(function() {

  $(".navbar-toggle").on("click focus", function() {

    $(".navbar").toggleClass("open");
    $(".navbar-toggle").toggleClass("open");

  });
});
html {
  font-family: "Raleway", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-weight: normal;
  color: #888;
}
html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
ul,
p {
  margin: 0;
  padding: 0;
  font-weight: normal;
}
a {
  text-decoration: none;
  color: inherit;
}
button {
  border: none;
  -webkit-appearance: button;
  cursor: pointer;
}
.navbar {
  background: rgba(255, 236, 176, 0.97);
  color: #555;
  line-height: 50px;
  display: none;
  position: relative;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  z-index: 99;
}
.navbar-fixed {
  position: fixed;
  top: 0;
}
.navbar-brand {
  display: inline-block;
  padding: 0 15px;
}
.navbar-mobile {
  background: #ffecb0;
  position: fixed !important;
  top: -100%;
  display: block;
  height: 275px;
  width: 100%;
  overflow-y: auto;
  opacity: 0.0;
  transition: .3s ease
}
.navbar.open {
  opacity: 1.0;
  top: 0;
}
.navbar-mobile .container {
  padding: 0;
}
.navbar-toggle {
  background: #ffecb0;
  position: fixed;
  display: block;
  top: 10px;
  right: 15px;
  padding: 9px 10px;
  border-radius: 5px;
  z-index: 100;
  background-image: none;
  outline: none;
}
.navbar-toggle .icon-bar {
  background-color: #555;
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 1px;
  transition: .3s ease;
}
.navbar-toggle .icon-bar+.icon-bar {
  margin-top: 4px;
}
.navbar-toggle.open .icon-bar:first-child {
  transform: translate(0, 6px) rotate(225deg);
}
.navbar-toggle.open .icon-bar:nth-child(2) {
  opacity: 0;
}
.navbar-toggle.open .icon-bar:last-child {
  transform: translate(0, -6px) rotate(135deg);
}
nav ul {
  list-style: none;
  text-align: center;
}
nav a {
  position: relative;
  display: block;
  font-size: 16px;
  font-weight: 500;
}
nav li a:hover {
  color: black;
  background-color: #ffe389;
}
nav li a.active {
  color: white;
  background-color: #847d64;
}
.btn {} .navbar-button {
  color: #fff;
  display: inline-block;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
  text-align: center;
  overflow: hidden;
  transition: .3s;
  background-color: #a48eff;
  border-color: #8c6aff;
  line-height: 1;
  padding: 10px 10px;
  margin: 0 15px;
}
.navbar-button:hover {
  background-color: #b9a8ff;
  color: white;
  border-color: #ad94ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="navbar-toggle" type="button" role="button">
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
</button>

<nav class="navbar navbar-mobile">
  <div class="container">
    <a href="test.html" class="navbar-brand">Logo</a>
    <div class="navbar-items">
      <ul>
        <li><a href="test.html" class="active">Home</a>
        </li>
        <li><a href="test2.html">Link 2</a>
        </li>
        <li><a href="test3.html">Link 3</a>
        </li>
        <li><a class="button navbar-button" href="contact.html">Call to Action</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
Jai
  • 74,255
  • 12
  • 74
  • 103
  • That will work, certainly, but remember that you need to provide feedback on the element in focus for those using keyboards (not everyone uses a mouse). – David Thomas May 16 '16 at 11:47
  • That doesn't seem to work for me. I've edited my question to add `outline:none` to navbar-toggle and the problem remains – Redtama May 16 '16 at 11:50
  • @Redtama As David mentioned you have to provide feedback to user for element in foucs either using a tooltip or triggeriing the click on focus. – Jai May 16 '16 at 11:57
  • @Jai My browser must be behaving differently for some reason because your snippet has the same problem when I run it. As do all the other answers. – Redtama May 16 '16 at 11:59
2

You can find this line in different browsers with different colors depending of your OS too, it is an outline.

As described by W3Schools:

An outline is a line that is drawn around elements (outside the borders) to make the element "stand out".

The outline shorthand property sets all the outline properties in one declaration.

The properties that can be set, are (in order): outline-color, outline-style, outline-width.

If one of the values above are missing, e.g. "outline:solid #ff0000;", the default value for the missing property will be inserted, if any.

I would select the item's class and set the outline to zero.

.navbar-toggle {
    outline: 0;
}

And a working demo:

$(document).ready(function () {

  $(".navbar-toggle").on("click", function () {

           $(".navbar").toggleClass("open");
           $(".navbar-toggle").toggleClass("open");

    });            
});
html {
    font-family: "Raleway", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
    font-weight: normal;
    color: #888;
}

html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
ul,
p {
    margin: 0;
    padding: 0;
    font-weight: normal;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    border: none;
    -webkit-appearance: button;
    cursor: pointer;
}

.navbar {
    background: rgba(255, 236, 176, 0.97);
    color: #555;
    line-height: 50px;
    display: none;
    position: relative;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    z-index: 99;
}

.navbar-fixed {
    position: fixed;
    top: 0;
}

.navbar-brand {
    display: inline-block;
    padding: 0 15px;
}

.navbar-mobile {
    background: #ffecb0;
    position: fixed !important;
    top: -100%;
    display: block;
    height: 275px;
    width: 100%;
    overflow-y: auto;
    opacity: 0.0;
    transition: .3s ease
}

.navbar.open {
    opacity: 1.0;
    top: 0;
}

.navbar-mobile .container {
    padding: 0;
}

.navbar-toggle {
    background: #ffecb0;
    position: fixed;
    display: block;
    top: 10px;
    left: 15px;
    padding: 9px 10px;
    border-radius: 5px;
    z-index: 100;
    background-image: none;
    outline: 0;                  /* <<== line added */
}

.navbar-toggle .icon-bar {
    background-color: #555;
    display: block;
    width: 22px;
    height: 2px;
    border-radius: 1px;
    transition: .3s ease;
}

.navbar-toggle .icon-bar+.icon-bar {
    margin-top: 4px;
}

.navbar-toggle.open .icon-bar:first-child {
    transform: translate(0, 6px) rotate(225deg);
}

.navbar-toggle.open .icon-bar:nth-child(2) {
    opacity: 0;
}

.navbar-toggle.open .icon-bar:last-child {
    transform: translate(0, -6px) rotate(135deg);
}

nav ul {
    list-style: none;
    text-align: center;
}

nav a {
    position: relative;
    display: block;
    font-size: 16px;
    font-weight: 500;
}

nav li a:hover {
    color: black;
    background-color: #ffe389;
}

nav li a.active {
    color: white;
    background-color: #847d64;
}
.btn {
     
}

.navbar-button {
    color: #fff;
    display: inline-block;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 1px;
    text-align: center;
    overflow: hidden;
    transition: .3s;  
    background-color: #a48eff;
    border-color: #8c6aff;
    line-height: 1;
    padding: 10px 10px;
    margin: 0 15px;
}

.navbar-button:hover {
    background-color: #b9a8ff;
    color: white;
    border-color: #ad94ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="navbar-toggle" type="button" role="button">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>

        <nav class="navbar navbar-mobile">
            <div class="container">
                <a href="test.html" class="navbar-brand">Logo</a>
                <div class="navbar-items">
                    <ul>
                        <li><a href="test.html" class="active">Home</a></li>
                        <li><a href="test2.html">Link 2</a></li>
                        <li><a href="test3.html">Link 3</a></li>
                        <li><a  class="button navbar-button" href="contact.html">Call to Action</a></li>
                    </ul>
                </div>
            </div>
        </nav>

EDIT: As mentioned here and here, outline: none; and outline: 0; can give to you similar visual results, but I would go to outline: 0; definetly.

UPDATE: Your screenshot does not look at all like an outline. May you should restart your browser or even your computer/device? It really seems like an inspector bug to me...

Community
  • 1
  • 1
Dev_NIX
  • 163
  • 4
  • 18
  • I've edited my answer to match your new `.navbar-toggle` position – Dev_NIX May 16 '16 at 11:59
  • Man this is crazy! Everyone's given practically the same answer but it's just not working for me! It definitely gets rid of the blue outline that Chrome normally puts around the element. But I still have a problem with Safari. I've added a screenshot of your snippet to my question. Please take a look and thanks again! – Redtama May 16 '16 at 12:18
  • Wow... Just for testing, try with `outline: 0; !important` or `outline: none; !important`, I'll keep looking solutions – Dev_NIX May 16 '16 at 14:08
  • Also, try with the `:focus` selector – Dev_NIX May 16 '16 at 14:10
  • Another property you can test: `outline-width: 0` – Dev_NIX May 16 '16 at 14:12
  • Tried all of these but still no success. Could this be altogether different from the outline property? I'm wondering because when I tab through items in Safari I can see what the blue outline looks like on focused items and it's different from the problem I'm having. – Redtama May 16 '16 at 14:33
  • Hm, I don't see any outline in your screenshot, just the hover effect when you are using the webkit inspector... – Dev_NIX May 16 '16 at 14:35
  • Problem is it's there when I'm not using the webkit inspector. – Redtama May 16 '16 at 14:42
  • I've just discovered that the problem goes away when I set `.navbar-toggle {position: static;}` but that doesn't help me a great deal since I want the element to be fixed. This is so strange... :o) – Redtama May 16 '16 at 14:49
  • Take a look to the computed styles – Dev_NIX May 16 '16 at 15:11
  • I've updated my question again. Seems like the problem is unique to my computer or at least my version of Safari. – Redtama May 16 '16 at 15:13
  • But anyway, your screenshot does not look at all like an outline. May you should restart your browser or even your computer/device? It really seems like an inspector bug to me :/ – Dev_NIX May 16 '16 at 15:14
  • Yeah it really does seem like that. But I've restarted my computer and browser but that didn't change anything. Thanks for all your help anyway. I'll give you a +1 because you've been most helpful ^^. – Redtama May 16 '16 at 15:16
  • Thank you, Redtama! If you find a solution give me a touch around here, my mind is going nuts right now – Dev_NIX May 16 '16 at 15:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112069/discussion-between-dev-nix-and-redtama). – Dev_NIX May 16 '16 at 15:18
0

This should do the trick. The focus pseudoclass is the key.

.navbar-toggle:focus {
   outline: none;
}
Syren
  • 1,961
  • 2
  • 15
  • 19
0

Try below css.

* {
  outline: none;
}
bhaskarmac
  • 339
  • 1
  • 3
  • 8