본문 바로가기
: ) Web/웹 스터디

[HTML, CSS 실습] Contact Form 만들기

by miiinn 2023. 11. 17.

 

 

[css]

div, input, textarea {
    box-sizing: border-box;
}

body {
    margin: 0;
}

.form-background{
    padding: 30px;
    background-color: black;
}

.form-white {
    padding: 30px;
    background-color: white;
    
    /* 크기 제한 */
    width: 80%;
    max-width: 600px;
    /* 가운데 정렬 */
    margin: auto;
}

.form-input {
    width: 100%;
    padding: 5px;
    font-size: 10px;
    border: 1px solid gray;
    border-radius: 5px;
}

.w-50 {
    width: 50%;
    float: left;
    padding: 10px;
}

.w-100 {
    width: 100%;
    padding: 10px;
    /* name이랑 padding 맞추려고 사용 */
}

.form-long {
    height: 70px;

    /* textarea의 최대 크기 제한 */
    max-height: 200px;
    max-width: 100%;
}

.yellow-button {
    padding: 10px;
    background-color: rgb(255, 197, 38);
    border: none;
    border-radius: 5px;
    color: white;

    /* 우측 정렬 간단하게 */
    display: block;
    margin-left: auto;
}

 

 

[html]

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Contact Form</title>
        <link href="css/form.css" rel="stylesheet">
    </head>
    <body>

        <div class="form-background">
            <div class="form-white">
                <form>
                    <div class="w-100">
                        <h3>Contact us</h3>
                        <p>Your Email</p>
                        <input class="form-input" type="email" placeholder="email@naver.com">    
                    </div>

                    <div class="w-50">
                        <p>First name</p>
                        <input class="form-input" type="text">
                    </div>

                    <div class="w-50">
                        <p>Last name</p>
                        <input class="form-input" type="text">
                    </div>
                    
                    <div style="clear: both;"></div>

                    <div class="w-100">
                        <p>Message</p>
                        <textarea class="form-input form-long"></textarea>
                    </div>

                    <div>
                        <input id="sub" type="checkbox">
                        <label for="sub">Subscribe</label>
                        <button class="yellow-button">SEND</button>
                    </div>

                </form>
                
            </div>
        </div>




    </body>
</html>

 

  • 가로로 꽉 차게 하기
    • width를 100으로

 

  • float는 쓰면 이상현상 방지를 위해 clear:both해줘야 함.
    • <div style="clear: both;"></div>

 

  • 체크박스 할 떄 글씨 쓸 떄 >뒤에 그냥 써도 되지만 대부분 의미없는 <span>이용.
  • 근데 <span>보다 <label>이 더 좋음
  • <label>태그
    • id 사용
    • 라벨을 누르면 인풋도 누른 것처럼 동작한다.
    • input의 제목 달 떄도 많이 이용