w3.css
인라인 양식
CSS를 사용하여 반응형 인라인 양식을 만드는 방법을 알아보자.
인라인 양식을 만드는 방법
1단계) HTML 추가
<form> 요소를 사용하여 입력을 처리한다.
<form class="form-inline" action="/action_page.php"> <label for="email">Email:</label> <input type="email" id="email" placeholder="Enter email" name="email"> <label for="pwd">Password:</label> <input type="password" id="pwd" placeholder="Enter password" name="pswd"> <label> <input type="checkbox" name="remember"> Remember me </label> <button type="submit">Submit</button> </form>
2단계) CSS 추가
/* Style the form - display items horizontally */ .form-inline { display: flex; flex-flow: row wrap; align-items: center; } /* Add some margins for each label */ .form-inline label { margin: 5px 10px 5px 0; } /* Style the input fields */ .form-inline input { vertical-align: middle; margin: 5px 10px 5px 0; padding: 10px; background-color: #fff; border: 1px solid #ddd; } /* Style the submit button */ .form-inline button { padding: 10px 20px; background-color: dodgerblue; border: 1px solid #ddd; color: white; } .form-inline button:hover { background-color: royalblue; } /* Add responsiveness - display the form controls vertically instead of horizontally on screens that are less than 800px wide */ @media (max-width: 800px) { .form-inline input { margin: 10px 0; } .form-inline { flex-direction: column; align-items: stretch; } }
기본 예시
예제 보기참고
W3C School - How TO - Inline Form