0

i'm learning styled components...

const Container = styled.div`
 background-color : black;
 & img{
    width: 80px;
   }
`

vs

const Container = styled.div`
 background-color : black;
 > img{
    width: 80px;
   }
`

both work just fine.... when should I use respectively? when are they uninterchangeable?

Rickard Elimää
  • 6,469
  • 3
  • 13
  • 28
Ingyu Yu
  • 7
  • 2
  • The duplicate answer has almost nothing to do with this question. `&` is typical for SASS and adds (in this case) `img` to parent selector. However, because you got a space between `&` and `img`, that will be interpreted as "parent img". The second one is "parent > img", targeting only the images that are direct child of parent. "parent img" targes _all_ images within the parents. – Rickard Elimää May 30 '22 at 07:41

0 Answers0