전역 구성 요소 만들기: 예제가 포함된 체크리스트
하나의 큰 할 일 목록인 이 자습서에서는 다양한 방식으로 구성할 수 있고
dir="ltr"
및 dir="rtl"
등을 지원하는 Timeline 구성 요소를 만들 것입니다.다이빙하자.
목차
dir="ltr"
and dir="rtl"
? :hover
? 마크업은 최소한이어야 하고 의미상 정확해야 합니다.
Timelines are typically lists, build with <ul>
and <li>
-tags. But do you always need a list? If the first thing you do, is adding list-style: none;
to your CSS, are you using the correct tag?
I've worked on quite a few projects, where someone decided to “CSS reset” all list-styles:
ul,
ol {
list-style: none;
}
This is really annoying, because I typically want to show a list when I'm using <ul>
or <ol>
-tags, otherwise I'd chosen different tags!
Andy Bell's “CSS reset” is much nicer:
/* Remove list styles on ul, ol elements with a list role, which suggests default styling will be removed */
ul[role="list"],
ol[role="list"] {
list-style: none;
}
In our first Timeline-example, we'll be using plain <a>
nchor-tags, since the timeline only contains <a>
nchors pointing to locations within the same document.
In CSS naming, we'll consider the <a>
nchors as a type of list-items anyway, and use the class tmln__item
— and tmln__list
for the “list wrapper”:
<nav class="tmln">
<h2 class="tmln__header">Timeline</h2>
<div class="tmln__list">
<a class="tmln__item" href="#2021"><span data-title>2021</span></a>
<a class="tmln__item" href="#2020"><span data-title>2020</span></a>
<a class="tmln__item" href="#2019"><span data-title>2019</span></a>
<a class="tmln__item" href="#2018"><span data-title>2018</span></a>
/* etc. */
</div>
</nav>
dir="ltr"
version:dir="ltr" 및 dir="rtl" 모두에서 작동합니까?
Instead of writing unique CSS for both text-directions, use CSS Logical Properties. I've . Here's the dir="rtl"
version:
계속하기 전에 수평 버전을 추가해 보겠습니다. 기본 요소
tmln--hr
에 수정자를 추가합니다.dir="rtl"
버전을 확인하십시오.마이크로데이터로 마크업을 강화해야 합니까?
While we're still working with the markup, let's consider whether we can enrich the markup by adding microdata, aka schema.org , 콘텐츠에 대해 더 자세히 검색 엔진에 알려줍니다.콘텐츠가 Events 또는 News Articles 목록입니까?
Google은 "리치 결과"에 대한 스키마를 호출하고 URL 또는 마크업을 붙여넣을 수 있는 testing-tool을 생성했습니다.
키보드로 탐색할 수 있습니까?
In this case, because we used <a>
-tags, it's navigable by keyboard by default. If you'd used a <div>
-tag and added a click-handler with JavaScript, you'd have to add tabindex="0"
for it to recieve keyboard-focus (but please: don't go there!)
초점 스타일이 있습니까?
To make it usable for keyboard-users, we'll add some styles using focus-visible
, thus not triggering the style, when using a pointer-device (mouse or touch):
계속해서 생성할 다음 유형의 타임라인에서 예를 보여 드리겠습니다.
focus-within
를 사용하여 포커스 가능한 요소의 부모 요소를 대상으로 지정하는 방법을 보여 드리겠습니다.이 경우 글머리 기호에 a
box-shadow
가 추가되고 기본 상자에 미묘한box-shadow
이 추가되고 링크 자체에 adotted outline
가 추가됩니다.:hover 는 어떻습니까?
Should :hover
work intentionally on mobile devices (it acts like a “pseudo-click”), or should it be disabled?
If you only want to show :hover
-styles on devices that actually support them (recommended), use:
@media (hover: hover) { ... }
더 긴 콘텐츠로 확장됩니까?
Some languages take up much more space 다른 사람보다:언어
번역
비율
한국인
조회
0.8
영어
견해
1
중국인
次檢視
1.2
포르투갈 인
시각화
2.6
프랑스 국민
상담
2.6
독일 사람
말안게헨
2.8
이탈리아 사람
시각화
삼
다양한 텍스트 길이로 확인(또는 콘텐츠에 실시간으로 Google 번역 사용) — 레이아웃에 따라
min-width
(또는 min-inline-size
), fit-content
등을 살펴보십시오.스크롤 및 스냅
If your content overflows (like our horizontal timeline), do not hide the default scrollbar (it will be hidden on mobile devices, though — but that's expected). The browsers default scrollbar can be navigated by keyboard, using the arrow-keys. You're welcome to style it, though:
더 멋진 디자인을 위해 WebKit의 스크롤 막대 버튼
::-webkit-scrollbar-button
을 배경과 동일한 색상으로 설정할 수 있습니다.항상 그렇듯이 확인하는 것을 잊지 마십시오
rtl
.모바일 장치에서는 "scroll-snap"을 상위 항목에 추가합니다.
.tmln__list {
overflow-x: auto;
scroll-snap-type: x mandatory;
}
항목에 다음을 추가합니다.
.tmln__item {
scroll-snap-align: start;
scroll-margin-inline-start: value;
}
개발 도구로 테스트
Before we continue, let's check our component in Lighthouse:
와우 - 지금까지 좋아 보인다!
지금이 CSS 적용 범위를 확인하기에 좋은 시기이기도 합니다.
Esc 키를 눌러 Chrome 개발자 도구에서 서랍을 엽니다(아직 열려 있지 않은 경우). "범위"탭 추가/확인:
흠... 9.9%의 사용되지 않은 CSS가 있습니다... 확인해 보겠습니다.
아! CSS가 축소되지 않고 주석이 포함되어 있기 때문입니다.
자체 구성 요소를 빌드할 때 전체 파일을 살펴보고 사용하지 않는 CSS가 있는지 확인하십시오.
유효성 및 문서 개요 확인
Although Lighthouse finds most issues, I always — check the console for errors, and fix them.
To see a visualization of the Document Outline, I use HTML5 Outliner , Chrome용 플러그인:Tip! Add a headline (
<h1>
to<h6>
) to your<nav>
-tags to prevent a bunch ofuntitled NAV
-entries in the outliner.
보너스: 뉴스 타임라인
Now, let's look into a News Timeline. In this case, we do need a list, so we'll replace the <div>
and <a>
nchors with <ul>
and <li>
-items:
<nav class="tmln tmln--box tmln--hr">
<h2 class="tmln__header">Latest News</h2>
<ul class="tmln__list">
<li class="tmln__item tmln__item--active">
<span data-title>32 mins ago</span>
<h3 class="tmln__item-headline">Someone, somewhere, did something stupid</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias, ab? Sequi dolorem aspernatur ad earum! Eius nulla tempora pariatur temporibus.</p>
</li>
</ul>
</nav>
그리고 다시
dir="rtl"
버전도 작동하는지 확인합니다.이제 수평 버전과 박스 버전을 혼합해 보겠습니다.
<nav class="tmln tmln--box tmln--hr">
그리고 …
dir="rtl"
버전을 확인해 보겠습니다.목록을 다시 확인하십시오
이 시점에서 일반 타임라인 구성 요소의 모든 단계를 다시 검토하고 포커스 상태 등을 추가 또는 편집해야 합니다.
결론
Wow — you made it to the end! If you're primarily a JavaScript-developer, you might wonder why I:
- Tagged this article with
JavaScript
†) - Chose the tags I did (instead of just using
<div>
s for everything). Here's a screenshot demonstrating why chosing the correct HTML-tags matters, if CSS for some reason fails:
†) 2 때문에 😁
코드 예제
Here's a Codepen with examples:
Cover photo by Andrey Grushnikov from Pexels
Reference
이 문제에 관하여(전역 구성 요소 만들기: 예제가 포함된 체크리스트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/madsstoumann/creating-global-components-a-checklist-with-examples-2n4g텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)