1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-17 19:37:26 +02:00

Add CSS code for layout patterns

This commit is contained in:
Phuoc Nguyen
2021-03-31 16:35:26 +07:00
parent 28998e445e
commit 9156f3a5cc
9 changed files with 165 additions and 117 deletions

View File

@@ -22,23 +22,9 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
display: flex;
/* Put a card in the next row when previous cards take all width */
flex-wrap: wrap;
margin-left: -8px;
margin-right: -8px;
">
<!-- A card with given width --> <!-- A card with given width -->
<div style=" <div class="card">
/* There will be 4 cards per row */
flex-basis: 25%;
padding-left: 8px;
padding-right: 8px;
">
... ...
</div> </div>
@@ -46,7 +32,24 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
/* Put a card in the next row when previous cards take all width */
flex-wrap: wrap;
margin-left: -8px;
margin-right: -8px;
}
.card {
/* There will be 4 cards per row */
flex-basis: 25%;
padding-left: 8px;
padding-right: 8px;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -22,45 +22,49 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
display: flex;
flex-direction: column;
">
<header> <header>
... ...
</header> </header>
<main style=" <main class="main">
/* Take the remaining height */
flex-grow: 1;
/* Layout the left sidebar, main content and right sidebar */
display: flex;
flex-direction: row;
">
<!-- Left sidebar --> <!-- Left sidebar -->
<aside style=" <aside class="left">...</aside>
width: 25%;
">...</aside>
<!-- Main content --> <!-- Main content -->
<article style=" <article class="middle">...</article>
/* Take the remaining width */
flex-grow: 1;
">
...
</article>
<!-- Right sidebar --> <!-- Right sidebar -->
<nav style=" <nav class="right">...</nav>
width: 20%;
">...</nav>
</main> </main>
<footer> <footer>
... ...
</footer> </footer>
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
flex-direction: column;
}
.main {
/* Take the remaining height */
flex-grow: 1;
/* Layout the left sidebar, main content and right sidebar */
display: flex;
flex-direction: row;
}
.left {
width: 25%;
}
.middle {
/* Take the remaining width */
flex-grow: 1;
}
.right {
width: 20%;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -22,25 +22,14 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style="display: flex;"> <div class="container">
<!-- Column --> <!-- Column -->
<div style=" <div class="column">
flex: 1;
/* Space between columns */
margin: 0 8px;
/* Layout each column */
display: flex;
flex-direction: column;
">
<!-- Cover --> <!-- Cover -->
... ...
<!-- Content --> <!-- Content -->
<div style=" <div class="content">
/* Take available height */
flex: 1;
">
... ...
</div> </div>
@@ -52,7 +41,24 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
}
.column {
flex: 1;
/* Space between columns */
margin: 0 8px;
/* Layout each column */
display: flex;
flex-direction: column;
}
.content {
/* Take available height */
flex: 1;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -22,25 +22,33 @@ const Details: React.FC<{}> = () => {
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>Try to scroll the main content!</div> <div style={{ lineHeight: 1.5, marginBottom: '16px' }}>Try to scroll the main content!</div>
<BrowserFrame <BrowserFrame
html={` html={`
<div style="display: flex;"> <div class="container">
<!-- Sidebar --> <!-- Sidebar -->
<aside style="width: 30%;"> <aside class="sidebar">
... ...
</aside> </aside>
<!-- Main --> <!-- Main -->
<main style=" <main class="main">
...
</main>
</div>
`}
css={`
.container {
display: flex;
}
.sidebar {
width: 30%;
}
.main {
/* Take the remaining width */ /* Take the remaining width */
flex: 1; flex: 1;
/* Make it scrollable */ /* Make it scrollable */
overflow: auto; overflow: auto;
"> }
...
</main>
</div>
`} `}
css={``}
> >
<div style={{ display: 'flex', height: '100%' }}> <div style={{ display: 'flex', height: '100%' }}>
<div <div

View File

@@ -23,30 +23,36 @@ const Details: React.FC<{}> = () => {
<BrowserFrame <BrowserFrame
html={` html={`
<!-- Row --> <!-- Row -->
<div style=" <div class="row">
display: flex;
margin-left: -8px;
margin-right: -8px;
">
<!--Cell with given width. Replace 25% with whatever you want --> <!--Cell with given width. Replace 25% with whatever you want -->
<div style=" <div class="cell width-1/4">25%</div>
flex: 0 0 25%;
padding-left: 8px;
padding-right: 8px;
">25%</div>
<!-- Cell that takes remaining width --> <!-- Cell that takes remaining width -->
<div style=" <div class="cell width-fill">
flex: 1;
padding-left: 8px;
padding-right: 8px;
">
... ...
</div> </div>
</div> </div>
`} `}
css={``} css={`
.row {
display: flex;
margin-left: -8px;
margin-right: -8px;
}
.cell {
padding-left: 8px;
padding-right: 8px;
}
/* Cell with given width. Replace 25% with whatever you want */
.cell.width-1/4 {
flex: 0 0 25%;
}
.cell.width-fill {
flex: 1;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -23,19 +23,26 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style="display: flex;"> <div class="container">
<!-- Left content --> <!-- Left content -->
<div style="flex: 1;"> <div class="half">
... ...
</div> </div>
<!-- Right content --> <!-- Right content -->
<div style="flex: 1;"> <div class="half">
... ...
</div> </div>
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
}
.half {
flex: 1;
}
`}
> >
<div style={{ display: 'flex', height: '100%' }}> <div style={{ display: 'flex', height: '100%' }}>
<div <div

View File

@@ -25,23 +25,32 @@ const Details: React.FC<{}> = () => {
</div> </div>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
display: flex; <header class="header">
flex-direction: column;
height: 100%;
">
<header style="flex-shrink: 0;">
... ...
</header> </header>
<main style="flex-grow: 1;"> <main class="main">
... ...
</main> </main>
<footer style="flex-shrink: 0;"> <footer class="footer">
... ...
</footer> </footer>
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.header,
.footer {
flex-shrink: 0;
}
.main {
flex-grow: 1;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -27,11 +27,7 @@ const Details: React.FC<{}> = () => {
<BrowserFrame <BrowserFrame
html={` html={`
<div> <div>
<header style=" <header class="header">
/* Stick to the top */
position: sticky;
top: 0;
">
... ...
</header> </header>
<main> <main>
@@ -39,7 +35,13 @@ html={`
</main> </main>
</div> </div>
`} `}
css={``} css={`
.header {
/* Stick to the top */
position: sticky;
top: 0;
}
`}
> >
<div> <div>
<div <div

View File

@@ -24,19 +24,8 @@ const Details: React.FC<{}> = () => {
</div> </div>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
height: 100%; <section class="section">
overflow: scroll;
">
<section style="
/* Take full size */
height: 100%;
width: 100%;
/* Stick to the top */
position: sticky;
top: 0;
">
... ...
</section> </section>
@@ -44,7 +33,21 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.container {
height: 100%;
overflow: scroll;
}
.section {
/* Take full size */
height: 100%;
width: 100%;
/* Stick to the top */
position: sticky;
top: 0;
}
`}
> >
<div <div
style={{ style={{