0

I want to apply a attribute to all input[type=text] elements but exclude certain elements. The elements to exclude does not have any class but their parent parent does.

The HTML looks like

<tr class="filters">
    <td>
        <input type="text" name="aName">
    </td>
    <td>
        <input type="text" name="anotherName">
    </td>
        ...
</tr>

I tried this CSS:

input[type=text]:not(tr.filters > td > input[type=text])
{
    min-width:400px;
}

but it does not work. Is it not possible to use not() in this way?

2 Answers 2

3

It's not possible with :not() as a CSS selector. The :not() pseudo-class accepts only a simple selector (which means exactly one type, .class, #id, [attribute] or :pseudo-class selector). Combinators like , > and + aren't allowed.

The default value of min-width is zero, so you can simply use an overriding rule instead and set it to that:

input[type="text"] {
    min-width: 400px;
}

tr.filters > td > input[type="text"] {
    min-width: 0;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your selector would work just fine in jQuery though, as it implements its own :not() selector that accepts that syntax.
0

Why don't you use something like this?

tr:not(.filters) td input[type=text]
{
    min-width:400px;
}

1 Comment

Perhaps because there may be input[type="text"]s that aren't in any tables.

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.