{"id":306066,"date":"2020-04-15T07:51:48","date_gmt":"2020-04-15T14:51:48","guid":{"rendered":"https:\/\/css-tricks.com\/?p=306066"},"modified":"2020-04-15T07:51:49","modified_gmt":"2020-04-15T14:51:49","slug":"create-a-responsive-css-motion-path-sure-we-can","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/create-a-responsive-css-motion-path-sure-we-can\/","title":{"rendered":"Create a Responsive CSS Motion Path? Sure We Can!"},"content":{"rendered":"\n

There was a discussion recently on the Animation at Work Slack<\/a>: how could you make a CSS motion path responsive?<\/em> What techniques would be work? This got me thinking.<\/p>\n\n\n\n

A CSS motion path allows us to animate elements along custom user-defined paths. Those paths follow the same structure as SVG paths. We define a path for an element using offset-path<\/code>.<\/p>\n\n\n\n

.block {\n\u00a0 offset-path: path('M20,20 C20,100 200,0 200,100');\n}<\/code><\/pre>\n\n\n\n

These values appear relative at first and they would be if we were using SVG. But, when used in an offset-path<\/code><\/a>, they behave like px units.<\/strong> This is exactly the problem. Pixel units aren\u2019t really responsive. This path won\u2019t flex as the element it is in gets smaller or larger. Let\u2019s figure this out.<\/p>\n\n\n\n

To set the stage, the offset-distance<\/code> property dictates where an element should be on that path:<\/p>\n\n\n\n