From f7cb267854c46e0169c07c6f8ce81e21e8dceea1 Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Sat, 14 Jun 2025 23:44:03 +0700 Subject: [PATCH] refactor: update tailwind typography css overrides (#538) * refactor: update tailwind typography css overrides Update TailwindCSS typography overrides to use less `important`; and update selectors to make them easier to read. * refactor: update focus styles to be consistent --- src/components/BackToTopButton.astro | 2 +- src/components/Tag.astro | 2 +- src/layouts/PostDetails.astro | 2 +- src/styles/typography.css | 92 ++++++++++++++++++++++------ 4 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/components/BackToTopButton.astro b/src/components/BackToTopButton.astro index da2da17..88e733e 100644 --- a/src/components/BackToTopButton.astro +++ b/src/components/BackToTopButton.astro @@ -16,7 +16,7 @@ import IconArrowNarrowUp from "@/assets/icons/IconArrowNarrowUp.svg"; class:list={[ "group relative bg-background px-2 py-1", "size-14 rounded-full shadow-xl", - "md:h-8 md:w-fit md:rounded-md md:shadow-none", + "md:h-8 md:w-fit md:rounded-md md:shadow-none md:focus-visible:rounded-none", "md:bg-background/35 md:bg-clip-padding md:backdrop-blur-lg", ]} > diff --git a/src/components/Tag.astro b/src/components/Tag.astro index d952a1b..28578b2 100644 --- a/src/components/Tag.astro +++ b/src/components/Tag.astro @@ -20,7 +20,7 @@ const { tag, tagName, size = "sm" } = Astro.props; href={`/tags/${tag}/`} transition:name={tag} class:list={[ - "relative pe-2 text-lg underline decoration-dashed group-hover:-top-0.5 group-hover:text-accent focus-visible:p-1", + "relative pe-2 text-lg underline decoration-dashed group-hover:-top-0.5 group-hover:text-accent focus-visible:p-1 focus-visible:no-underline", { "text-sm": size === "sm" }, ]} > diff --git a/src/layouts/PostDetails.astro b/src/layouts/PostDetails.astro index d6240e3..e6b0cc6 100644 --- a/src/layouts/PostDetails.astro +++ b/src/layouts/PostDetails.astro @@ -105,7 +105,7 @@ const nextPost =
diff --git a/src/styles/typography.css b/src/styles/typography.css index 26f01ba..f803911 100644 --- a/src/styles/typography.css +++ b/src/styles/typography.css @@ -2,11 +2,80 @@ @layer base { /* ===== Override default Tailwind Typography styles ===== */ - .prose { - @apply prose-headings:!mb-3 prose-headings:!text-foreground prose-h3:italic prose-p:!text-foreground prose-a:!text-foreground prose-a:!decoration-dashed prose-a:underline-offset-8 hover:prose-a:text-accent prose-blockquote:!border-l-accent/50 prose-blockquote:opacity-80 prose-figcaption:!text-foreground prose-figcaption:opacity-70 prose-strong:!text-foreground prose-code:rounded prose-code:bg-muted/75 prose-code:p-1 prose-code:!text-foreground prose-code:before:!content-none prose-code:after:!content-none prose-ol:!text-foreground prose-ul:overflow-x-clip prose-ul:!text-foreground prose-li:marker:!text-accent prose-table:text-foreground prose-th:border prose-th:border-border prose-td:border prose-td:border-border prose-img:mx-auto prose-img:!my-2 prose-img:border-2 prose-img:border-border prose-hr:!border-border; + .app-prose { + @apply prose; + + h1, + h2, + h3, + h4, + th { + @apply mb-3 text-foreground; + } + + h3 { + @apply italic; + } + + p, + strong, + ol, + ul, + figcaption, + table, + code { + @apply text-foreground; + } a { - @apply break-words hover:!text-accent; + @apply break-words text-foreground decoration-dashed underline-offset-4 hover:text-accent focus-visible:no-underline; + } + + ul { + @apply overflow-x-clip; + } + + li { + @apply marker:text-accent; + } + + hr { + @apply border-border; + } + + img { + @apply mx-auto border border-border; + } + + figcaption { + @apply opacity-75; + } + + table { + th, + td { + @apply border border-border p-2; + } + + th { + @apply py-1.5; + } + + code { + @apply break-all sm:break-normal; + } + } + + code { + @apply rounded bg-muted/75 p-1 break-words text-foreground before:content-none after:content-none; + } + + .astro-code code { + @apply bg-inherit; + } + + blockquote { + @apply border-s-accent/80 break-words opacity-80; } details { @@ -17,10 +86,8 @@ @apply focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent focus-visible:outline-dashed; } - thead th:first-child, - tbody td:first-child, - tfoot td:first-child { - padding-inline-start: 0.5714286em !important; + pre { + @apply focus-visible:border-transparent focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-dashed; } } @@ -49,15 +116,4 @@ @apply rounded-sm border border-border px-0.5 py-px; } } - - /* Break words in code and blockqoute */ - .prose code, - .prose blockquote { - @apply break-words; - } - - .prose table code { - /* add line breaks whenever necessary for codes under table */ - @apply break-all sm:break-normal; - } }