0

My full code is posted here Apply Range for Class and ID in CSS

My JSfiddle - http://jsfiddle.net/9Tpzp/

My existing CSS code is like below

#tab1:target ~ .tabs .tab1 dd div {
   height: 28px;
}
#tab2:target ~ .tabs .tab2 dd div {
   height: 28px;
}
#tab3:target ~ .tabs .tab3 dd div {
   height: 28px;
}
#tab4:target ~ .tabs .tab4 dd div {
   height: 28px;
}

I changed as below

[id*='tab']:target ~ .tabs [class*='tab'] dd div {
    height : 28px;
}

HTML:

<body>
        <div class="container">

            <div class="accordion">
                <span id="tab1"></span>
                <span id="tab2"></span>
                <div class="tabs">
                    <dl class="tab1">
                        <dd>
                            <a href="#tab1">Tab #1</a>
                            <div><p>Tab1</p></div>
                        </dd>
                    </dl>
                    <dl class="tab2">
                        <dd>
                            <a href="#tab2">Tab #2</a>
                            <div>
                                <p>
                                   Tab2
                                </p>
                            </div>
                        </dd>
                    </dl>
                </div>
            </div>

        </div>
    </body>

Now how can i specify the number range 1-4 in that regular expression.

If it is impossible in CSS, Can we achieve through any other way like jquery,etc,.

10
  • If you mean you want the class regex to be something like tab[1-4], I don't think CSS supports that. Commented Feb 4, 2014 at 3:34
  • can we achieve through any other way like jquery, etc,. @mathematical.coffee Commented Feb 4, 2014 at 3:36
  • Could you get rid of that .tab* class? Commented Feb 4, 2014 at 3:42
  • .tab* class is required @j08691 Commented Feb 4, 2014 at 3:47
  • Can you post the HTML? Commented Feb 4, 2014 at 3:48

1 Answer 1

1

Solved the problem by using jquery. Below is the fix.

$(document).on('click','a[href^="#tab"]',function(){
                $('a[href^="#tab"]').siblings('div').css('height',0);
                if($(this).siblings('div').height() == 0){
                        $(this).siblings('div').css('height',28); 
            }
                else {
                $(this).siblings('div').css('height',0);
            }       
            })
Sign up to request clarification or add additional context in comments.

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.