>本教程演示瞭如何通過使用CSS網格設計的Tumblr設計來創建響應迅速的基於網格的卡片佈局,並為較舊的瀏覽器提供了使用浮子的後備。 我們將構建一個佈局,其中包含標頭卡和多個主題卡,每張包含圖像和標題。
密鑰功能:
CSS網格:
object-fit
:focus-within
標記結構:
)的無序列表(
)組成。 每個主題卡()都包含一個鏈接()包裝標題()和圖像( <img src="%E2%80%9C" https: alt="“" redesigning>
卡樣式: > CSS樣式卡,確保圖像使用 >
浮點後期: 規則可確保僅在不支持CSS網格時使用浮點佈局。 ><ul></ul>
<li>
<li class="card">
>佈局實現(CSS Grid):<a></a>
>
<h2></h2>
CSS網格佈局是使用SASS變量來定義的,可維護性和響應能力:<img src="https://img.php.cn/" alt="Redesigning a Card-based Tumblr Layout with CSS Grid ">
<!-- More topic cards -->
<code class="language-scss">$item-size: 210px;
$col-gutter: 10px;
$vp-gutter: $col-gutter;
$max-cols: 5;
.grid {
display: grid;
grid-gap: $col-gutter;
padding: 0 $vp-gutter;
grid-template-columns: repeat(auto-fill, $item-size);
grid-auto-rows: $item-size;
max-width: grid-width($max-cols); // Function defined below
justify-content: center;
margin: 40px auto;
}
@function grid-width($num-cols) {
@return $num-cols * $item-size + ($num-cols - 1) * $col-gutter;
}
// Media queries (Sass mixin) to handle header card spanning
@mixin when-n-cols($n) {
@media screen and (min-width: #{grid-width($n) + 2 * $vp-gutter + $scrollbar-size}) {
@content;
}
}
@include when-n-cols(2) {
.grid .header {
grid-row: span 2;
grid-column: span 2;
}
}
// ... (Styling for cards and header) ...</code>
和CSS過渡實現的。 為缺乏支持>的瀏覽器提供了後備大綱。 @supports
>
以上是使用CSS網格重新設計基於卡的Tumblr佈局的詳細內容。更多資訊請關注PHP中文網其他相關文章!