Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS nth-child for a range of elements

I'm a bit new to using nth-child() so any help would be greatly appreciated. I'm trying to use it in my css file and not directly into the html. Below is my code - I want to highlight the first four items that populate into this list.

        <div class="icdcode-selector row-fluid " icdcode="@icd.ICDCode" orderID="@x" icdID="@icd.ID">
            <div class="span2 icdcode-sortable-handle">
                <div class="row-fluid">
                    <div class="span6">
                        <i class="icon-align-justify"></i>
                    </div>
                    <div class="span6">
                        <span class="icd-name">@icd.ICDCode</span>
                    </div>
                </div>
            </div>
            <div class="span9">
                @Html.TextAreaFor(m => icd.UserText, new { @class = "span11", id = "icd_" + Model.Encounter.DictationID.ToString() + "_" + icd.ICDCode.Replace('.', '-'), icd = icd.ICDCode })
            </div>
            <div class="span1">
                <a href="#" class="btn btn-mini icd-remove"><i class="icon-remove"></i></a>
            </div>
        </div>

I'm trying to use a class like this: .primary-billing .div:nth-child(-n+4), but it doesn't seem to work properly.

Please help.

like image 583
Jonathan Mayer Avatar asked Aug 22 '12 15:08

Jonathan Mayer


People also ask

How do you target the nth child in SCSS?

Writing Complex :nth-child() Selectors It works exactly the same as :nth-child except that it starts from the end of the parent. For example, you can select the first three children of a parent by using the selector :nth-child(-n + 3) . You can use :nth-last-child(-n + 3) to select the last three.

How do I select a specific child in CSS?

The CSS child selector has two selectors separated by a > symbol. The first selector indicates the parent element. The second selector indicates the child element CSS will style.

Can we use Nth child for class?

The :nth-child selector allows you to select one or more elements based on their source order, according to a formula. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling elements.


1 Answers

The best guide you can have to understand nth-child is this website: http://nthmaster.com/

like image 69
warmth Avatar answered Sep 22 '22 10:09

warmth