1

Currently I am developing a simple application with React, I have chosen to use Aphrodite for handling my CSS.

However I've come across a problem which I cannot find the answer for and it's handling odd and even psuedo selectors. Has anyone got an example on how to use Aphrodite to handle odd + even psuedo.

Ash._
  • 364
  • 1
  • 3
  • 16

2 Answers2

0

With Aphrodite you use a stylesheet in js and you can define a pseudo class with a string representation of it for an object key. It would look something like this

const styles = StyleSheet.create({
    hover: {
        ':hover': {
            backgroundColor: 'red'
        }
    },
    ... other styles here ...
});

so when using Aphrodite you use their css function to inject it into the <head>

<div className={css(styles.hover)}>I get a red background on hover!</div>

Here is a great video showing how to use Aphrodite (including pseudo classes!)

John Ruddell
  • 25,283
  • 6
  • 57
  • 86
0

The above answer is correct, I didn't realise what you can do is this..

const styles = StyleSheet.create({
    red: {
        backgroundColor: '#dedcdb'
    },

    nthChild: {
      ':nth-child(even)': {
        backgroundColor: '#e8e8e8'
      }
    },

    small: {
        '@media (max-width: 600px)': {
            backgroundColor: 'red',
        }
    }
});

Which will colour each even child with the correct colour.

Ash._
  • 364
  • 1
  • 3
  • 16