From 6dc84b92a396cdf3237c5543219b498fc35f0d79 Mon Sep 17 00:00:00 2001
From: pdelboca
Date: Wed, 7 Feb 2024 17:53:39 -0300
Subject: [PATCH] Fixes for margin collapse. Adding main element as part of the
design.
---
css/style.css | 20 +++++++++++++++++
css/sustainable.css | 52 +++++++++++++++++++++++++++++++-------------
demo.html | 33 ++++++++--------------------
index.html | 53 ++++++++++++++++++++-------------------------
4 files changed, 89 insertions(+), 69 deletions(-)
create mode 100644 css/style.css
diff --git a/css/style.css b/css/style.css
new file mode 100644
index 0000000..90f3a98
--- /dev/null
+++ b/css/style.css
@@ -0,0 +1,20 @@
+header {
+ display: grid;
+ margin-inline: auto;
+ place-content: center;
+ text-align: center;
+ background-color: canvastext;
+ color: canvas;
+}
+
+strong {
+ color: var(--color-10)
+}
+
+h1 {
+ font-size: 3rem;
+}
+
+h2 {
+ margin-top: 3rem
+}
\ No newline at end of file
diff --git a/css/sustainable.css b/css/sustainable.css
index 08c820e..8971cbc 100644
--- a/css/sustainable.css
+++ b/css/sustainable.css
@@ -1,6 +1,6 @@
/*!
- * Sustainable CSS v0.0.6 (https://github.com/pdelboca/sustainable-css/)
- * Copyright 2023 - Licensed under MIT
+ * Sustainable CSS v0.0.7 (https://github.com/pdelboca/sustainable-css/)
+ * Copyright 2023 by Patricio Del Boca - Licensed under MIT
*
* Sustainable CSS reuses system colors:
* https://drafts.csswg.org/css-color-4/#css-system-colors
@@ -18,10 +18,32 @@
}
body {
+ line-height: 1.65;
+ font-size: 1.15rem;
+ margin-top: 0;
+}
+
+main {
max-width: var(--max-width);
- padding: 0 20px 20px 20px;
- margin-left: auto;
- margin-right: auto;
+ margin: 4vb auto;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+p {
+/*
+* Setting margins to 0 to avoid margin collapse:
+* https://www.joshwcomeau.com/css/rules-of-margin-collapse/
+*/
+ margin:0;
+}
+
+p ~ p {
+ margin-bottom: 0.75rem;
}
img {
@@ -45,14 +67,10 @@ fieldset, input:not([type=submit]), select, textarea {
border: 1px solid;
}
-input[type=submit], input[type=reset] {
+input[type=submit], input[type=reset], button[type=submit] {
cursor: pointer;
}
-ul > li, ol > li {
- margin: 0.125em;
-}
-
header > nav > * > a, header > nav > a {
font-size: larger;
text-decoration: none;
@@ -61,11 +79,13 @@ header > nav > * > a, header > nav > a {
details > summary {
cursor: pointer;
+ padding: 0.5em;
}
/* Branding and colors */
a {
color: inherit;
+ font-size: inherit;
text-decoration-color: var(--color-10);
}
@@ -77,7 +97,7 @@ input {
accent-color: var(--color-10);
}
-input[type=submit], input[type=reset] {
+input[type=submit], input[type=reset], button[type=submit] {
background-color: var(--color-10);
color: canvas;
}
@@ -95,10 +115,12 @@ mark {
article {
border: 1px solid;
border-radius: .25em;
- padding: 0em 0.5em 0.5em 0.5em;
+ padding: 0.5em;
}
-article > footer {
- font-size: 0.9em;
+article footer {
+ font-size: 0.9rem;
text-align: right;
}
-
+article footer, article > p + p {
+ margin-top: 1rem;
+ }
diff --git a/demo.html b/demo.html
index 4e33c96..d5e1b06 100644
--- a/demo.html
+++ b/demo.html
@@ -6,46 +6,35 @@
Sustainable.css Demo
-
+
-
-
-
Header 1
-
Header 2
-
Header 3
-
Header 4
-
Header 5
-
Header 6
+
+
Header and paragraphs
+
Header and paragraphs do not have margins. Avoiding margin collapse makes styling way easier.
Top Navigation links
I only make the font-size: larger and text-decoration: none. You can then layout it as you want.
-
Paragraph
-
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Neque minima libero sint, veritatis quo ratione. Magni
- assumenda fuga fugiat iure dolor eaque ratione culpa mollitia expedita voluptates. Alias, odio vel?
-
Details
Click to expand
-
I just added cursor: pointer; to the summary element, good enough.
Forms layout are always customized and the styling is highly coupled with the layout. Example: margins of labels are
highly coupled with the decision on puting them above the input or besides it. That's why Sustainable.css do not add
@@ -55,11 +44,9 @@
Forms
We focus on giving a small styling to the inputs elements and let the user define how to layout it and further customize it.
We do recommend using the sadly forgotten fieldset element.
-
The following form is just 10 lines of CSS, good enough.