0

I've noticed that if you define a <style> tag in your markup, like this:

 tr:nth-child(even) {background-color:#F4F4F4;}

And then you try to apply a css binding using knockout (this sets a background-color when you click on a row):

<tr data-bind="click: $parent.selectRow, css: {red:  $parent.seletedRow() == $data}">

The second one is not set since I already defined a background-color within the <style> tag.

I need to mark the even rows with a color but when you click over a row its background-color must be replaced by the css class red. Here's an example:

http://jsfiddle.net/q3Uuz/1/ Try to click on the second row and you notice the redclass is not applyed.

How can achieve this?

2 Answers 2

1

In this case there is no need for using !important;

A more specific selector than your tr:nth-child(even) also fixes your issue

So you can write something like:

tr:nth-child(even) { background-color:#F4F4F4; }

tr.red { background-color: red; }

Demo JSFiddle.

You can read more about how the selector's specificity calculated

Sign up to request clarification or add additional context in comments.

Comments

0

You can add !important to background-color style in red class:

.red {
    background-color: red !important;
}

Here is working fiddle: http://jsfiddle.net/q3Uuz/2/

4 Comments

there is no need for !important; a more specific selector also fixes it like: tr.red { background-color: red; }
every time when you use !important, one little koala is crying because this is no more cascade style sheet.
Agree with you guys, never again :)
@nemesv please post this comment as answer.

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.