안정성을 위해 클래스 이름 또는 id스타일을 지정할 요소 ( class텍스트 입력에는 이상적으로 a 가있을 것이므로)와 id제출 버튼 (a class도 작동 하지만 )을 제공하는 것이 좋습니다 .
<form action="#" method="post">
<label for="text1">Text 1</label>
<input type="text" class="textInput" id="text1" />
<label for="text2">Text 2</label>
<input type="text" class="textInput" id="text2" />
<input id="submitBtn" type="submit" />
</form>
CSS로 :
.textInput {
/* styles the text input elements with this class */
}
#submitBtn {
/* styles the submit button */
}
최신 브라우저의 경우 동일한 HTML을 사용하여 속성별로 선택할 수 있습니다.
.input {
/* styles all input elements */
}
.input[type="text"] {
/* styles all inputs with type 'text' */
}
.input[type="submit"] {
/* styles all inputs with type 'submit' */
}
스타일링을위한 텍스트 입력은 항상 label요소를 따르고 제출은 텍스트 영역을 따르기 때문에 (매우 약하기 때문에) 형제 결합자를 사용할 수도 있습니다 .
label + input,
label + textarea {
/* styles input, and textarea, elements that follow a label */
}
input + input,
textarea + input {
/* would style the submit-button in the above HTML */
}