>容器查詢仍處於起步階段,缺乏廣泛的瀏覽器支持。 儘管Chromium已經支持他們,但Safari的支持始於16版,而Firefox的實施很快就會。
早期討論通常會在容器查詢和媒體查詢語法之間引起相似之處。 考慮以下示例:
兩個示例目標
<code>/* Stacked flex container */ .post { display: flex; flex-direction: column; } /* Change direction when viewport is 600px or wider */ @media(min-width: 600px) { .post { flex-direction: row; } }</code>
<code>/* Define the container */ .posts { container-name: posts; container-type: inline-size; } .post { display: flex; flex-direction: column; } /* Query the container's min-width */ @container posts (min-width: 600px) { /* Change styles when `posts` container is 600px or wider */ .post { flex-direction: row; } }</code>
。
在此基礎上,CSS封裝模塊3級規格介紹了min-width: 600px
.posts
容器樣式查詢
)。 >
一個假設的例子:@supports
請注意,
(或它的缺席)是暗示的;所有容器查詢默認情況下(當前)成為樣式查詢。 Miriam Suzanne的作品通過這種方法強調了潛在的挑戰。<code>.posts { container-name: posts; } @container posts (background-color: #f8a100) { /* Change styles when `posts` container has an orange background */ .post { color: #fff; } }</code>
container-type: style
自定義屬性值:
對用作狀態指標的自定義屬性的更改做出反應。以上是集裝箱風格查詢的初期的詳細內容。更多資訊請關注PHP中文網其他相關文章!