CSS ã«ãã³ã³ããã¯ã¨ãªã¨ããæ©è½ããããããã
ã¡ãã£ã¢ã¯ã¨ãªã§ã¯ç»é¢å ¨ä½ã®å¤§ããã«å¿ãã¦è¦ç´ ã®ã¹ã¿ã¤ã«ãå¤ãããã¨ãã§ãããã©ãã³ã³ããã¯ã¨ãªã使ãã¨å½è©²è¦ç´ ã®è¦ªã®å¤§ããã«å¿ãã¦ã¹ã¿ã¤ã«ãå¤ããããã
/* ã¡ãã£ã¢ã¯ã¨ãªã®ä¾ */ /* ç»é¢å¹ ã 400px 以ä¸ã ã£ãããdiv ã赤ããã */ @media screen and (max-width: 400px) { div { background-color: red; } } /* ã³ã³ããã¯ã¨ãªã®ä¾ */ /* div ã®è¦ªè¦ç´ ã®å¹ ã 400px 以ä¸ã ã£ãããdiv ã赤ããã */ @container (max-width: 400px) { div { background-color: red; } }
ãã®æ©è½ã Google Chrome Canary ã§ä½¿ããããã«ãããã¨èããã®ã§ã使ã£ã¦ã¿ãã
ããããã®ãä½ã£ãâ
ãã㯠HTML/CSS ã ãã§ã§ãã¦ãã¦ãå¹ ã«å¿ãã¦é¡ãå¤ããã¨ããã¯ã³ã³ããã¯ã¨ãªã使ã£ã¦ä»¥ä¸ã®ããã«æ¸ããã¦ããã
.cell-content { border-radius: 50px; background-color: #ffd3b4; /* ãªã¬ã³ã¸ */ background-image: url("./images/face-large.svg"); } @container (max-width: 250px) { .cell-content { border-radius: 25px; background-color: #d5ecc2; /* ç· */ background-image: url("./images/face-medium.svg"); } } @container (max-width: 150px) { .cell-content { border-radius: 10px; background-color: #a3e4d2; /* é */ background-image: url("./images/face-small.svg"); } }
ããã«ãåãè¾¼ãã§ã¿ããGoogle Chrome Canary ã§ãEnable CSS Container Queriesããã©ã°ãæå¹ã«ãããä¸è¨ã® gif ã®ããã«åãã¯ãã
å®é使ãã«ã¯è¦ªè¦ç´ ã« contain
ããããã£ãã¤ãããããå¿
è¦ãããã®ã§ã試ãããæ¹ã¯ä»¥ä¸ã®ãªãã¸ããªã®ã½ã¼ã¹ã³ã¼ããåç
§ããããã£ã¨ã¡ããã¨ããè¨äºãèªãã§ãã ãããã¾ããå®é¨çæ©è½ãªã®ã§ä»å¾ä»æ§ãå¤ããããããã¾ããã