1

Is it possible to change edit the css of only 4th tab of this li menu. If so, how?

All help appreciated. Thank you!

<div class="rt_tabs clearfix  left tab-style-2" id="single-product-details" data-tab-style="tab-style-2">
  <ul class="tab_nav hidden-xs">
    <li class="tab_title  active" id="tab-1-title" data-tab-number="1"><span class="icon-lightbulb"></span>TAB 1</li>
    <li class="tab_title " id="tab-2-title" data-tab-number="2"><span class="icon-home"></span>TAB 2</li>
    <li class="tab_title " id="tab-3-title" data-tab-number="3"><span class="icon-plus-circled"></span>TAB 3</li>
    <li class="tab_title " id="tab-4-title" data-tab-number="4"><span class="icon-mail-1"></span>TAB 4</li>
  </ul>

0

4 Answers 4

3

You can use :nth-child(4), in the case you want the 4th child of anything:

.rt_tabs li:nth-child(4) {
  background: #99c;
}
<div class="rt_tabs clearfix  left tab-style-2" id="single-product-details" data-tab-style="tab-style-2">
  <ul class="tab_nav hidden-xs">
    <li class="tab_title  active" id="tab-1-title" data-tab-number="1"><span class="icon-lightbulb"></span>TAB 1</li>
    <li class="tab_title " id="tab-2-title" data-tab-number="2"><span class="icon-home"></span>TAB 2</li>
    <li class="tab_title " id="tab-3-title" data-tab-number="3"><span class="icon-plus-circled"></span>TAB 3</li>
    <li class="tab_title " id="tab-4-title" data-tab-number="4"><span class="icon-mail-1"></span>TAB 4</li>
  </ul>

Other ways to do (in this particular example):

  1. Use the id: #tab-4-title {}.
  2. Use the attribute selector: [data-tab-number="4"] {}.
Sign up to request clarification or add additional context in comments.

Comments

0

.tab_nav li:nth-child(4) targets the 4th li child of .tab_nav. Or in this case .tab_nav li:last-child should also work.

More information on nth-child: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child

Comments

0

Your element already has an id, so its easy

#tab-4-title{
        /*Whatever change you want*/
    }

7 Comments

Code snippet must be used when you have something that has both HTML, CSS, or something that shows a working demo.
Didn't know. Edited it. Although now it looks like i've left comments all over. Is there a way to write code snippets for CSS but not working code?
Hey your code solved it for me! Thank you very much!
@ishaan I made it right for you and you again screwed up. LoL. :)
Ohh I do that quite often. :P
|
0

Use the id:

#tab-4-title {...}

Use a attribute selector:

[data-tab-number="4"] {...}

Use a pseudo-selector:

li:nth-child(4) {...}
li:last-child {...}
li:nth-last-child(1) {...}
li:last-of-type {...}

There are several other possibilities.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.