1

I am using react-tab to create an interface like this

enter image description here

However if i click on the tab, it will turn into this:

enter image description here

It is the default css style when the tab gets focus.

I have tried this css (in less) but it is unable to override the default style:

.react-tabs [role=tab],
.react-tabs [role=tablist],
.react-tabs [role=tab]:focus,
.react-tabs [role=tablist]:focus, {
  border-top: none ;
  border-left: none ;
  border-right: none;
  border-bottom: 2px solid #ddd;
}

How can I override the css styles?

In addition, is there anywhere to make the above css more concise? For one I would like to be able to combine [role=tab] and [role=tablist] into a single selector.

EDIT

The html markup of the tab

enter image description here

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304

3 Answers3

1

You have a syntax error in your CSS: the last comma in .react-tabs [role=tablist]:focus, /* <-- */ must be removed.

Demo

.react-tabs {
  height: 20px;
}

.react-tabs [role=tab]  { background: orange; } /* correct version */
.react-tabs [role=tab], { background: blue; } /* won't work */
<div class="react-tabs">
  <div class="something" role="tab">Want to change this guy</div>
</div>
Marvin
  • 9,164
  • 3
  • 26
  • 44
  • The structure is actually more like `
    `. I tried your solution but it does not work.
    – Anthony Kong Mar 22 '17 at 01:00
  • Ok this changes everything. Then just remove the last comma and see if the styles get applied (inspect element). – Marvin Mar 22 '17 at 07:17
1

You must override all default properties of :focus and :focus:after.

This code below works for me:

  .react-tabs [role=tab]:focus {
    box-shadow: none;
    border-color: none;
    border-bottom-color: $yourColor;
    outline: none;
  }

  .react-tabs [role=tab]:focus:after{
    content: "";
    position: absolute;
    height: 5px;
    left: -4px;
    right: -4px;
    bottom: -5px;
    background: transparent; 
  }
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Kieu Tran
  • 36
  • 3
0

Provide outline: 0 to your code.

outline by default appears over many form elements like input & button, when they are active or focussed. So you have to manually make it disappear.

Outlines differ from borders in the following ways:

  • Outlines do not take up space, they are drawn above the content.
  • Outlines may be non-rectangular. They are rectangular in Gecko/Firefox. But e.g. Opera draws a non-rectangular shape around
    the construct.

Refer code:

.react-tabs [role=tab],
.react-tabs [role=tablist],
.react-tabs [role=tab]:focus,
.react-tabs [role=tablist]:focus, {
  border-top: none ;
  border-left: none ;
  border-right: none;
  border-bottom: 2px solid #ddd;
  outline: 0 !important;
}
nashcheez
  • 5,067
  • 1
  • 27
  • 53