Một số layout thông dụng, Sidebar, Card, Masonry

Trang chủ Tin tức Website Một số layout thông dụng, Sidebar, Card, Masonry

1. Sidebar

Sidebar

HTML

<div class="container">
    <div class="main">
      <p style="color:#fff;">MAIN</p>
    </div>
    <div class="sidebar">
      <p>SIDEBAR</p>
    </div>
  </div>

CSS

.container {
    height: 100vh;
    background-color: #EFF9FF;
    display: flex;
}

.main {
    flex: 1;
    background-color: #164172;
}
.sidebar {
    flex-basis: 30%;
    background-color: #FFFF40;
}

2. Card

Card

HTML

<div class="cards">
    <div class="cards__item"></div>
    <div class="cards__item"></div>
    <div class="cards__item"></div>
 </div>

CSS

.cards {
    display: flex;
    margin-left: -8px;
    margin-right: -8px;
}
.cards__item {
    flex-basis: 25%;
    padding-left: 8px;
    padding-right: 8px;
}

3. Masonry

Masonry

HTML

<div class="masonry-grid">
    <!--Item -->
    <div class="masonry-grid__item">...</div>
    <div class="masonry-grid__item">...</div>
    <div class="masonry-grid__item">...</div>
</div>

CSS

.masonry-grid {
    column-count: 3;
    column-gap: 1rem;
    width: 100%;
}

.masonry-grid__item {
    break-inside: avoid;
    margin-bottom: 1rem;
}