무언가에 대해 블로그를 작성하려면 스타일을 가지고 하세요.

If you're going to do something, do it with style!1



내 스타일은 어디에 있습니까?



방금 프로젝트에 TailwindCSS를 설치했고 더 보기 좋게 만들기 위해 스타일을 추가할 준비가 되었습니다.


전에
후에






Preflight configuration은 우리 스타일을 "훔친"범인입니다. 나는 다른 시리즈 중 하나에서 그것을 다루었습니다. 여기에 문서를 인용하겠습니다.

Built on top of modern-normalize, Preflight is a set of base styles for Tailwind projects that are designed to smooth over cross-browser inconsistencies and make it easier for you to work within the constraints of your design system.



기본적으로 모든 브라우저에서 일관된 스타일을 유지하기 위해 일부 요소에는 추가 스타일이 있고, 일부 요소에는 스타일이 비활성화되어 있으며, headings for example과 같은 요소에는 스타일이 완전히 적용되지 않습니다.

이제 블로그 스타일 지정을 시작하고 작업 속도를 높이기 위해 공식 TailwindCSStypography plugin를 사용하겠습니다.

타이포그래피 플러그인 추가



  • 플러그인 설치

    $ npm install --save-dev @tailwindcss/typography
    

  • pluginstailwind.config.js 항목 추가

    diff --git a/blog/tailwind.config.js b/blog/tailwind.config.js
    index 9d0ca2f..586083d 100644
    --- a/blog/tailwind.config.js
    +++ b/blog/tailwind.config.js
    @@ -4,5 +4,5 @@ module.exports = {
       theme: {
         extend: {},
       },
    -  plugins: [],
    +  plugins: [require('@tailwindcss/typography')],
     }
    


  • 이제 html에 prose 스타일을 추가할 수 있습니다.

    diff --git a/blog/src/layouts/_default/single.html b/blog/src/layouts/_default/single.html
    index 560541c..6cc083d 100644
    --- a/blog/src/layouts/_default/single.html
    +++ b/blog/src/layouts/_default/single.html
    @@ -1,5 +1,5 @@
     {{ define "main" }}
    -    <article>
    +    <article class="prose">
             <h1>{{ .Title }}</h1>
             {{ .Content }}
         </article>
    

    즉시 우리는 개선 사항을 볼 수 있습니다


  • 콘텐츠를 중앙에 배치하고 중단점 수정자를 추가하여 한 단계 더 나아가겠습니다.

    diff --git a/blog/src/layouts/_default/single.html b/blog/src/layouts/_default/single.html
    index 560541c..6cc083d 100644
    --- a/blog/src/layouts/_default/single.html
    +++ b/blog/src/layouts/_default/single.html
    @@ -1,5 +1,5 @@
     {{ define "main" }}
    -    <article class="prose">
    +    <article class="prose prose-sm prose-table:table-fixed lg:prose-lg xl:prose-xl 2xl:prose-2xl mx-auto">
             <h1>{{ .Title }}</h1>
             {{ .Content }}
         </article>
    


    훨씬 낫다. prose-table:table-fixed 요소 수정자도 추가했음을 알 수 있습니다. 이는 기사의 테이블 크기가 고정되도록 하기 위한 것입니다.

  • 헤더에 스타일 추가



    지금은 헤더 크기만 늘리겠습니다.

    diff --git a/blog/src/layouts/index.html b/blog/src/layouts/index.html
    index 4fbcad1..9c1cdd3 100644
    --- a/blog/src/layouts/index.html
    +++ b/blog/src/layouts/index.html
    @@ -1,8 +1,10 @@
     {{ define "main" }}
    -    <h1>{{ .Site.Title }}</h1>
    +    <h1 class="text-5xl font-bold">{{ .Site.Title }}</h1>
         {{ range .Pages }}
             <article>
    -            <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
    +            <h2 class="text-4xl underline">
    +                <a href="{{ .Permalink }}">{{ .Title }}</a>
    +            </h2>
             </article>
         {{ end }}
     {{ end }}
    

    blog/src/layouts/_default/list.html에서 동일한 작업을 수행합니다.

    Prettier를 사용한 자동 클래스 정렬



    html에 유틸리티 css 클래스를 포함하는 것은 매우 장황하고 번거로울 수 있습니다. 코드를 따르기 어렵게 만드는 것은 쉽습니다. 이를 돕기 위해 automatically sort them 할 수 있습니다.

    커밋 전 후크로 prettier를 사용하고 있으므로 prettier-plugin-tailwindcss 을 npm 종속성으로 설치하는 대신 additional_dependency 후크에 대해 prettier로 추가합니다.

    diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
    index b8b2f7f..0b88113 100644
    --- a/.pre-commit-config.yaml
    +++ b/.pre-commit-config.yaml
    @@ -26,6 +26,7 @@ repos:
                 additional_dependencies:
                     - "[email protected]"
                     - "[email protected]"
    +                - "[email protected]"
    


    타이포그래피 플러그인 클래스가 정렬되지 않음



    어떤 이유로 @tailwindcss/typography 의 클래스가 정렬되지 않았습니다. 다른 옵션을 시도했지만 제대로 작동하지 못했습니다. 나는 started discussion이 있습니다. 이것은 나에게 버그처럼 보이지만 뭔가 빠졌을 수 있습니다.

    연결


  • https://tailwindcss.com/docs/preflight

  • https://tailwindcss.com/docs/preflight#headings-are-unstyled
  • https://github.com/tailwindlabs/prettier-plugin-tailwindcss
  • https://tailwindcss.com/docs/typography-plugin
  • https://github.com/tailwindlabs/tailwindcss/discussions/8921




  • Quote by Jason Statham

    좋은 웹페이지 즐겨찾기