Простые макеты сетки (HTML код)
<body>
<div class="container">
<header>
<h1>Easy Grid Layouts</h1>
<p>Lightweight grid layouts, with minimum lines of code to get the most out of layouts.
</p>
</header>
<main>
<section>
<h2>Grids Are...</h2>
<div class="section-content">
<p>⋯here to stay, get over it, with the introduction of <codes>@supports</codes>,
you can now have a fallback to flex for your layouts. Grids allow for
<a href="https://codepen.io/ghaste/pen/dyWoNXP" target="blank">traditional</a> and
<a href="https://codepen.io/ghaste/pen/wvdwdjp" target="blank">non traditional</a> layouts
</p>
<p>More Demos: <a href="https://codepen.io/ghaste/full/vYZjQgr" target="blank">lightweight css layouts</a></p>
</div>
</section>
<section>
<h2>Stack of Pancakes</h2>
<div class="section-content">
<p>The pancake stack with the header main body footer has become so ubiquitous that
designers are getting tired of it.
<pre class="language-css"><code class="language-css">.parent-container {
display: grid;
grid-template-rows:
auto 1fr auto;
}
</code></pre>
This is used in this on the main container to layout the header and main sections.
</p>
</div>
</section>
<section>
<h2>Game of Cards</h2>
<div class="section-content">
<p>
Another layout we see in common is cards laid out in rows and columns.
There are two ways of doing this.
<pre class="language-css"><code class="language-css">.parent-container {
display: grid;
grid-template-columns:
repeat(auto-fit,
minmax(40ch, 1fr));
}
</code></pre>
With <codes>auto-fit</codes>, the boxes will stretch as their horizontal
size exceeds <codes>40ch</codes> to fill the entire remaining space. However, if you change this to <codes>auto-fill</codes>, they will not stretch when their base size in the minmax function is exceeded.
</p>
</div>
</section>
<section>
<h2>Pancake Double...</h2>
<div class="section-content">
<p>
I have used the pancake layout again to layout the contents of the cards themselves.
<pre class="language-css"><code class="language-css">.parent-container {
display: grid;
grid-template-rows:
auto 1fr;
}
</code></pre>
</p>
</div>
</section>
<section>
<h2>Nothing Beats the Classic</h2>
<div class="section-content">
<p>
If you are old enough then you remember the classic layout we used to bandy about
<pre>
header
side main side
footer
</pre>
you could do this with a template
<pre class="language-css"><code class="language-css">grid-template:
"h h h" auto,
"s1 m s2" 1fr,
"f f f" auto;
</code></pre>
and assign your sections to the grid areas that you have defined<codes>grid-area:h</codes>.
</p>
<p>
Another easy way of doing this is.
<pre class="language-css"><code class="language-css">.parent-container {
display: grid;
grid-template:
auto 1fr auto /
auto 1fr auto;
}
</code></pre>
</p>
</div>
</section>
</main>
<footer>Have fun with code™</footer>
</div>
</body>
Простые макеты сетки (CSS код)
@import url("https://fonts.googleapis.com/css2?family=Carter+One&family=Comfortaa&display=swap");
:root {
font-family: "Comfortaa", sans-serif;
}
*,
*::after,
*::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
h1,
h2,
h3 {
font-family: "Carter One", cursive;
line-height: 1;
color: #ffd60af0;
}
.container {
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
background: linear-gradient(to bottom, #090909, #303030);
background-size: 100vw 100vh;
background-attachment: fixed;
color: #f0f8ffa0;
}
header,
footer {
padding: 2em 0;
background: hsla(50, 100%, 30%, 0.03);
}
footer {
background: #0001;
text-align: center;
font-size: 0.8rem;
}
@supports (-webkit-background-clip: text) {
h1 {
background-image: radial-gradient(
ellipse at top center,
#ffd60a,
transparent
),
radial-gradient(circle at right, #ffd60a, #ffe681);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
}
h1 {
font-size: clamp(3rem, 10vw, 4rem);
padding: 0.5rem 0;
width: max-content;
}
main {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(40ch, 1fr));
gap: 1rem;
}
section {
display: grid;
grid-template-rows: auto 1fr;
position: relative;
}
section h2 {
transform: translateY(45%) translateX(1rem);
}
.section-content {
padding: 2rem 1rem;
border: 1px solid #ffd60a60;
border-radius: 3px;
line-height: 1.5;
}
a {
text-decoration: none;
color: #ffd60ab0;
position: relative;
}
a:hover,
a:focus {
color: #ffd60a;
}
a::before {
content: "";
position: absolute;
left: 0;
top: 98%;
width: 100%;
height: 2px;
transform-origin: right;
transform: scaleX(0);
transition: transform 150ms ease-in;
background: #ffe681;
}
a:hover::before,
a:focus::before {
transform: scaleX(1);
transform-origin: left;
}
codes {
padding: 0.1rem;
background: linear-gradient(to bottom right, #ccc9, #6669);
border-radius: 0.1rem;
border: 1px solid;
color: #ffd60a90;
filter: hue-rotate(180deg) saturate(3);
}
codes::before {
content: "";
border-left: 5px solid;
padding-left: 0.5rem;
}
codes::after {
content: "";
border-right: 5px solid;
padding-right: 0.5rem;
}
p:not(:first-of-type) {
margin-top: 2rem;
}
/* PrismJS 1.24.1
https://prismjs.com/download.html#themes=prism-twilight&languages=markup+css+clike+javascript */
/**
* prism.js Twilight theme
* Based (more or less) on the Twilight theme originally of Textmate fame.
* @author Remy Bach
*/
code[class*="language-"],
pre[class*="language-"] {
color: white;
background: none;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
text-align: left;
text-shadow: 0 -0.1em 0.2em black;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"],
:not(pre) > code[class*="language-"] {
background: hsl(0, 0%, 8%); /* #141414 */
}
/* Code blocks */
pre[class*="language-"] {
border-radius: 0.5em;
border: 0.3em solid hsl(0, 0%, 33%); /* #282A2B */
box-shadow: 1px 1px 0.5em black inset;
margin: 0.5em 0;
overflow: auto;
padding: 1em;
}
pre[class*="language-"]::-moz-selection {
/* Firefox */
background: hsl(200, 4%, 16%); /* #282A2B */
}
pre[class*="language-"]::selection {
/* Safari */
background: hsl(200, 4%, 16%); /* #282A2B */
}
/* Text Selection colour */
pre[class*="language-"]::-moz-selection,
pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection,
code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
}
pre[class*="language-"]::selection,
pre[class*="language-"] ::selection,
code[class*="language-"]::selection,
code[class*="language-"] ::selection {
text-shadow: none;
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
}
/* Inline code */
:not(pre) > code[class*="language-"] {
border-radius: 0.3em;
border: 0.13em solid hsl(0, 0%, 33%); /* #545454 */
box-shadow: 1px 1px 0.3em -0.1em black inset;
padding: 0.15em 0.2em 0.05em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: hsl(0, 0%, 47%); /* #777777 */
}
.token.punctuation {
opacity: 0.7;
}
.token.namespace {
opacity: 0.7;
}
.token.tag,
.token.boolean,
.token.number,
.token.deleted {
color: hsl(14, 58%, 55%); /* #CF6A4C */
}
.token.keyword,
.token.property,
.token.selector,
.token.constant,
.token.symbol,
.token.builtin {
color: hsl(53, 89%, 79%); /* #F9EE98 */
}
.token.attr-name,
.token.attr-value,
.token.string,
.token.char,
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable,
.token.inserted {
color: hsl(76, 21%, 52%); /* #8F9D6A */
}
.token.atrule {
color: hsl(218, 22%, 55%); /* #7587A6 */
}
.token.regex,
.token.important {
color: hsl(42, 75%, 65%); /* #E9C062 */
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
pre[data-line] {
padding: 1em 0 1em 3em;
position: relative;
}
/* Markup */
.language-markup .token.tag,
.language-markup .token.attr-name,
.language-markup .token.punctuation {
color: hsl(33, 33%, 52%); /* #AC885B */
}
/* Make the tokens sit above the line highlight so the colours don't look faded. */
.token {
position: relative;
z-index: 1;
}
.line-highlight {
background: hsla(0, 0%, 33%, 0.25); /* #545454 */
background: linear-gradient(
to right,
hsla(0, 0%, 33%, 0.1) 70%,
hsla(0, 0%, 33%, 0)
); /* #545454 */
border-bottom: 1px dashed hsl(0, 0%, 33%); /* #545454 */
border-top: 1px dashed hsl(0, 0%, 33%); /* #545454 */
left: 0;
line-height: inherit;
margin-top: 0.75em; /* Same as .prism’s padding-top */
padding: inherit 0;
pointer-events: none;
position: absolute;
right: 0;
white-space: pre;
z-index: 0;
}
.line-highlight:before,
.line-highlight[data-end]:after {
background-color: hsl(215, 15%, 59%); /* #8794A6 */
border-radius: 999px;
box-shadow: 0 1px white;
color: hsl(24, 20%, 95%); /* #F5F2F0 */
content: attr(data-start);
font: bold 65%/1.5 sans-serif;
left: 0.6em;
min-width: 1em;
padding: 0 0.5em;
position: absolute;
text-align: center;
text-shadow: none;
top: 0.4em;
vertical-align: 0.3em;
}
.line-highlight[data-end]:after {
bottom: 0.4em;
content: attr(data-end);
top: auto;
}
Простые макеты сетки (JS код)
//ignore the css related to prism in the css section.
//# sourceURL=pen.js
Простые макеты сетки (Результат кода)
Comments