html5 <label></label>
요소는 텍스트 설명을 양식 제어와 연관시키는 데 사용되어 유용성과 접근성을 향상시킵니다. 레이블을 양식 컨트롤과 연결하는 두 가지 주요 방법이 있습니다.
포장 방법 :
<label></label>
요소 내에서 양식 제어를 랩핑 할 수 있습니다. 예는 다음과 같습니다.
<code class="html"><label> Name: <input type="text" name="username"> </label></code>
이 방법에서 텍스트 "이름 :"은 레이블 역할을하며 <input>
요소와 자동으로 연관됩니다.
for
메소드 :
<label></label>
요소 내에서 for
속성을 사용하여 양식 컨트롤의 id
로 설정할 수 있습니다. 예는 다음과 같습니다.
<code class="html"><label for="username">Name:</label> <input type="text" id="username" name="username"></code>
이 방법에서 텍스트 "이름 :"은 id
"username"과 <input>
요소와 관련이 있습니다.
두 방법 모두 유효하고 널리 지원되지만 레이블 및 컨트롤이 인접 해 있지 않거나 스타일링을 별도로 적용하려는 경우 for
속성 메소드가 선호됩니다.
양식 컨트롤과 함께 <label></label>
요소를 사용하면 몇 가지 이점이 있습니다.
레이블을 양식 입력과 올바르게 연결하여 접근성을 향상 시키려면 다음과 같은 모범 사례를 따르십시오.
<label></label>
요소를 사용하십시오 :<label></label>
요소를 사용하여 모든 양식 컨트롤과 레이블을 연결하십시오. 이것은 스크린 리더에 의존하는 사용자에게 필수적입니다.for
속성 메소드를 사용하십시오. 그렇지 않으면 포장 방법이 충분할 수 있습니다.title
속성을 적절한 <label></label>
대체하지 마십시오. title
속성은 모든 화면 독자가 발표 할 수 없으며 <label></label>
텍스트와 충돌하면 혼란을 일으킬 수 있습니다. 예, <label></label>
요소는 다양한 유형의 양식 컨트롤과 함께 사용할 수 있습니다. 다른 유형에 적용 할 수있는 방법은 다음과 같습니다.
텍스트 입력 :
<code class="html"><label for="email">Email:</label> <input type="email" id="email" name="email"></code>
"이메일 :"라벨은 이메일 입력 필드와 관련이 있습니다.
확인란 :
<code class="html"><label> <input type="checkbox" name="subscribe" value="yes"> Subscribe to newsletter </label></code>
"뉴스 레터 구독"텍스트는 확인란과 관련이 있습니다. 텍스트를 클릭하면 확인란이 전환됩니다.
라디오 버튼 :
<code class="html"><label> <input type="radio" name="color" value="red"> Red </label> <label> <input type="radio" name="color" value="blue"> Blue </label></code>
각 레이블은 해당 라디오 버튼과 관련이 있습니다. "빨간색"또는 "파란색"을 클릭하면 해당 라디오 버튼이 선택됩니다.
드롭 다운 선택 :
<code class="html"><label for="country">Country:</label> <select id="country" name="country"> <option value="usa">USA</option> <option value="canada">Canada</option> </select></code>
"Country :"라벨은 드롭 다운 메뉴와 관련이 있습니다.
Textarea :
<code class="html"><label for="comments">Comments:</label> <textarea id="comments" name="comments"></textarea></code>
레이블 "댓글 :"는 Textarea와 관련이 있습니다.
다양한 유형의 양식 컨트롤과 함께 <label></label>
요소를 올바르게 사용하면 웹 양식의 유용성과 접근성을 모두 향상시킬 수 있습니다.
위 내용은 html5 & lt; label; label & gt; 레이블을 양식 컨트롤과 연결하는 요소?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!