5

I'm currently working on building an website with React. I paid for a Material-UI React template for this, and I found these codes below and cannot understand the part of '& > *' in line 4.

Is it just a name of a property or does it mean something else?

const useStyles = makeStyles((theme) => ({
    card: {
        maxWidth: '475px',
        '& > *': {
            flexGrow: 1,
            flexBasis: '50%'
        },
        [theme.breakpoints.down('sm')]: {
            margin: '20px'
        },
        [theme.breakpoints.down('lg')]: {
            maxWidth: '400px'
        }
    },
    content: {
        padding: `${theme.spacing(5)} !important`,
        [theme.breakpoints.down('lg')]: {
            padding: `${theme.spacing(3)} !important`
        }
    }
}));
NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
CatherineKim
  • 109
  • 1
  • 5

3 Answers3

2

The sign & related to css compiler, like scss. The * means all, as the sign > means direct child.

Basically, it will refer to the element you are in his scopes, this case:

// element card
card: {
        maxWidth: '475px',

        // all direct children of the element card
        '& > *': {
            flexGrow: 1,
            flexBasis: '50%'
        },
}
Aviv Ben Shahar
  • 268
  • 1
  • 8
0

The greater than sign (>) selector in CSS is used to select the element with a specific parent. It is called as element > element selector. It is also known as the child combinator selector which means that it selects only those elements which are direct children of a parent. It looks only one level down the markup structure and not further deep down. Elements which are not the direct child of the specified parent is not selected.

The & character basically means “this”. Here's some examples:

a { color:#ff0000; &:hover { color:#0000ff; } } Will be compiled into: a { color:#ff0000; } a:hover { color:#0000ff; }

MrBlender
  • 197
  • 14
0
// Selects all elements where the parent is a <card> element
card: {
        '& > *': {
            flexGrow: 1,
            flexBasis: '50%'
        }
}

//this same as 

card > * {
    flex-grow: 1;
    flex-basis: 50%;
}