1

I'm programming a todo app in React. At the bottom I give the date when the todo is due. If it is due today, it is red, if not, it is normal. I give the small day the class "dueToday" if it is due today. That also works:

<small className="dueToday">2021-11-24</small>
<small>2021-11-25</small>

In my CSS I have the following code:

small .dueToday {
 /* color: rgb(160,84,112); */
 color: red;
}

In the browser it looks like this: Screenshot

React Code:

{todos.map((todo) => (
  <div
    key={todo.id}
    className="todo"
    onClick={() => deleteTodo(todo.id)}
  >
    <h3>{todo.title}</h3>
    {todo.due !=
    `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}` ? (
      <small>{todo.due}</small>
    ) : (
      <small className="dueToday">{todo.due}</small>
    )}
  </div>
))}
Toni
  • 23
  • 6
  • 3
    `small .dueToday` selects that class **inside** a `small` element, `small.dueToday` would be both selectors matching the same element (assuming `small` appears in the DOM at all and isn't just a React component) – DBS Nov 24 '21 at 16:13
  • This is [conditional rendering](https://reactjs.org/docs/conditional-rendering.html) not [conditional class](https://stackoverflow.com/questions/30533171/react-js-conditionally-applying-class-attributes) (just for clarification). – Jax-p Nov 24 '21 at 16:16

1 Answers1

2

Your issue is you are looking for a small tag that has inside item with the class .dueToday you are supposed to check if a small tag with a .dueToday class, to do that just remove the space in your CSS selector like this:

small.dueToday {
 /* color: rgb(160,84,112); */
 color: red;
}
Jose Lora
  • 1,392
  • 4
  • 12
  • 18