1

I use datatables from fluent kit and the pagination, when clicked (:active) is highlighted with:

box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);

I want it gone, but only when clicked. I want the effect to work only for the :focus done with keyboard, a TAB key. I don't think it is possible with CSS only. If it is, that's awesome. If not, javascript / jquery solution is acceptable.

Here's simplified example of the code:

.pagination {
  padding: 20px;
}

.pagination a {
  padding: 10px;
}

.pagination a:focus {
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.pagination a:active {
  border: 1px solid black;
}
<div class="pagination">
  <a href="#">1</a>
  <a href="#">2</a>
  <a href="#">3</a>
</div>

Use TAB to change focus between the <a> links to see what I mean.


EDIT

As it is the external plugin, I don't want to use another HTML elements for that to work, like in Enable :focus only on keyboard use (or tab press).

  • Possible duplicate of [Enable :focus only on keyboard use (or tab press)](https://stackoverflow.com/questions/31402576/enable-focus-only-on-keyboard-use-or-tab-press) – pretzelhammer Jul 17 '18 at 05:02
  • You can combine both: `a:active:focus`, and also exclude one `a:focus:not(:active)`. – connexo Jul 17 '18 at 05:06

2 Answers2

2

On TAB click e.key === 'Tab' (or e.keyCode=9 in ASCI code)

Learn here:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

Use this function:

document.addEventListener('keydown', function(e) {
  if (e.key === 'Tab') {
   console.log('tab is clicked!')
  }
});
.pagination {
  padding: 20px;
}

.pagination a {
  padding: 10px;
}

.pagination a:focus {
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.pagination a:active {
  border: 1px solid black;
}
<div class="pagination">
  <a href="#">1</a>
  <a href="#">2</a>
  <a href="#">3</a>
</div>

OR only by css

this plugin:https://github.com/ten1seven/track-focus in css:

body[data-whatinput="keyboard"] a:focus {
  box-shadow:  0 0 5px red;
}
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47
0

I think you might be this code here

.pagination {
  padding: 20px;
}

.pagination a {
    padding: 10px;
    border: 1px solid transparent;
}

.pagination a:focus {
  outline:0;
  box-shadow: inherit;
}

.pagination a:active {
  border: 1px solid black;
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}
<div class="pagination">
  <a href="#">1</a>
  <a href="#">2</a>
  <a href="#">3</a>
</div>
Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26