Answers for "conditional inline styling"

4

conditional inline styling

class App extends Component {
  constructor() {
    super()
    this.state = { isRed: true }
  }

  render() {
    const isRed = this.state.isRed

    return <p style={{ color: isRed ? 'red' : 'blue' }}>Example Text</p>
  }
}
Posted by: Guest on August-19-2020
0

conditional styling css

Not in the traditional sense, but you can use classes for this, if you have access to the HTML. Consider this:

<p class="normal">Text</p>

<p class="active">Text</p>
and in your CSS file:

p.normal {
  background-position : 150px 8px;
}
p.active {
  background-position : 4px 8px;
}
That's the CSS way to do it.
Posted by: Guest on March-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language