{"id":305681,"date":"2020-04-07T07:51:52","date_gmt":"2020-04-07T14:51:52","guid":{"rendered":"https:\/\/css-tricks.com\/?p=305681"},"modified":"2020-04-07T07:51:53","modified_gmt":"2020-04-07T14:51:53","slug":"how-to-re-create-a-nifty-netflix-animation-in-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/how-to-re-create-a-nifty-netflix-animation-in-css\/","title":{"rendered":"How to Re-Create a Nifty Netflix Animation in CSS"},"content":{"rendered":"\n

The design for Netflix’s browse page has remained pretty similar for a few years now. One mainstay component is the preview slider that allows users to scroll through content and hover on items to see a preview.<\/p>\n\n\n\n

One unique characteristic of the UI is its hover behavior. When a show preview expands on hover, the cards next to it are pushed outward so that they don\u2019t overlap. <\/p>\n\n\n\n\n\n\n\n

Like this:<\/p>\n\n\n\n

\"\"
It\u2019s like Bill Murray and Brad Pitt are fighting for the spotlight.<\/figcaption><\/figure>\n\n\n\n

We can do this in CSS! No JavaScript. No dependencies. Plain CSS. But before getting into any code, here\u2019s exactly what we want to do:<\/p>\n\n\n\n

  1. The card that is hovered over should expand while keeping its aspect ratio.<\/li>
  2. When a card is hovered, the other cards should not change size and move outwards so that they don’t overlap one another.<\/li>
  3. All the cards should remain vertically centered with one another.<\/li><\/ol>\n\n\n\n

    Sound good? Now let\u2019s get into the code.<\/p>\n\n\n

    HTML and flexible elements<\/h3>\n\n\n

    Let\u2019s set up a row of images that represents Netflix\u2019s video previews. That includes:<\/p>\n\n\n\n

    • A  .container<\/code> parent element with several .item<\/code> elements inside<\/li>
    • Each .item<\/code> element consisting of an image wrapped in an anchor tag<\/li>
    • Turning .container<\/code> into a flex container that aligns the items in a row<\/li>
    • Setting the flex behavior for the .item<\/code> class so they take up equal space in the row<\/li><\/ul>\n\n\n\n