Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masonry - 瀑布流布局 #1

Open
imjeen opened this issue Jun 3, 2021 · 0 comments
Open

Masonry - 瀑布流布局 #1

imjeen opened this issue Jun 3, 2021 · 0 comments

Comments

@imjeen
Copy link
Owner

imjeen commented Jun 3, 2021

使用CSS的多列布局

  • 属性 column-count 设置特定数量的列数
  • 属性 column-width 设置期望的最小列宽。(如果 column-count 没有设置,那么浏览器就会以合适的宽度尽量显示更多的列。)

使用简写属性 columns 书写

  • 声明 column-count: 8 和 column-width:12em 等效于 columns:12 8em
  • 声明 column-count:4 等效于 columns:4
    -声明 column-width:12em 等效于 columns:12em

兼容性: https://www.caniuse.com/#search=columns

<main class="masonry">
    <section class="item>1</section>
    <section class="item>2</section>
    <section class="item>3</section>
    <section class="item>4</section>
    <!-- more items -->
</main>
.masonry{
    column-count: 3; /* 列数 */
}
.item{
    break-inside: avoid; /* 元素不能中断 */
}

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant