예전에 테이블에 부여했던 테두리를 자세히 설명한다.


테두리는 기본적으로 border 키워드를 사용


border-width, border-style, border-color 세가지가 있고,


세가지를 합친 border: [width style color] 키워드도 있다.


또한 border-[top/bottom/left/right]-attr(속성)을 통해


테두리의 각 부분의 속성을 컨트롤 할 수 있다.


사용법과 예시를 확인해보자



<html>
    <head>
        <meta charset="UTF-8">
        <title>Input</title>
        <link rel="icon" href = "btn.png">
        <style>
            /*border-width, border-style, border-color 세가지를 합친*/
            /*border: [width style color]을 사용한 것.*/
            /*또한 border-[top/bottom/left/right]-attr(속성)을 통해*/
            /*테두리의 각 부분의 속성을 컨트롤 할 수 있다.*/

            .one{
                border: 5px solid red;
            }

            .two{
                border-style: dashed;
                border-width: thin;
                border-color: brown;
            }

            .three{
                border-bottom-style: dotted;
                border-top-style: double;
                border-right-style: solid;
                border-left-style: solid;
                border-left-color: aquamarine;
                /*선이 없을 경우, 색깔만 줘도 아무 변화 없다.*/
            }

            .four{
                border-bottom-style:groove;
                border-top-style: groove;

                border-right-style: ridge;
                border-left-style: ridge;
            }

            .five{
                /*한번에 주는 방법*/
                /*12-3-6-9, 시계방향*/
                border-style: double solid dotted dashed; 
            }
        </style>
        <!--스타일이 많으면 로딩이 느려질 수 있다.-->
        <!--아이디가 # 클래스가 . 태그는 p-->
    </head>
    <body>
        <p class="one">This is content</p>
        <p class="two">This is content</p>
        <p class="three">This is content</p>
        <p class="four">This is content</p>
        <p class="five">This is content</p>
    </body>

</html>



실행 화면







테이블에 적용 예시


마진 기능을 추가하여 좀 더 이쁘게 자리잡았다. 


<html>
    <head>
        <meta charset="UTF-8">
        <title>로그인 박스</title>
        <style>
            table, th, td{
                border: 1px solid black;
                border-collapse: collapse;
            }
            th{
                width: 50px;
                padding: 3px;
            }
            td{
                width: 50px;
                padding: 3px;
            }
            </style>
    </head>
    <body>
        <h2>로그인</h2>
        <hr/>
        <form action="" method="GET">
            <fieldset>
            <table>
                <tr><!--행(row)선언-->
                    <th><b>ID</b></th>
                    <th><input type="text" name = "UserID" value=""placeholder = "아이디를 입력 해주세요."/></th>
                    <th rowspan="2"><input type="submit" value="로그인"/></th>
                </tr>
                <tr><!--행(row)선언-->
                    <th><b>PW</b></th>
                    <th><input type="password" name = "UserPW" value=""placeholder = "비밀번호를 입력 해주세요."/></th>
                </tr>
                <tr><!--행(row)선언-->
                    <th colspan="3"><input type="button" value="회원가입"/> <input type="button" value="아이디/비번 찾기"></th>
                </tr>
            </table>
            </fieldset>
        </form>

    </body>
</html>




<html>
    <head>
        <meta charset="UTF-8">
        <title>회원가입 페이지</title>
        <style>
            table, th, td{
                border: 1px solid black;
                border-collapse: collapse;
            }
            th, td{
                padding: 3px;
            }
        </style>
    </head>
    <body>
        <fieldset>
        <h2>회원가입</h2>
        <hr/>
        <form action="" method="GET">
        <table>
            <tr>
                <th>아이디</th>
                <td><input type="text" name = "UserID" value=""/></td>
            </tr>
            <tr>
                <th>비밀번호</th>
                <td><input type="text" name = "UserPW" value=""/></td>
            </tr>
            <tr>
                <th>비밀번호 확인</th>
                <td><input type="text" name = "ReUserPW" value=""/></td>
            </tr>
            <tr>
                <th>이름</th>
                <td><input type="text" name = "Name" value=""/></td>
            </tr>
            <tr>
                <th>이메일</th>
                <td><input type="email" name="mail" required/></td>
            </tr>
            <tr>
                <th>생년월일</th>
                <td>
                    <select name="year">
                        <option value="1995">1995</option>
                        <option value="1996"d>1996</option>
                        <option value="1997" selected>1997</option>
                        <option value="1998">1998</option>
                        <option value="1999">1999</option>
                        <option value="2000">2000</option>
                    </select>
                    <select name="month">
                        <option value="01" selected>01</option>
                    </select>
                    <select name="day">
                        <option value="01" selected>01</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>성별</th>
                <td>
                    <input type="radio" name="gender" value="male"/> 남자
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="gender" value="female"/> 여자
                </td>
            </tr>
            <tr>
                <th>취미</th>
                <td>
                    <input type="checkbox" name="hobby" value="드라이브"/>드라이브
                    <input type="checkbox" name="hobby" value="스포츠"/>스포츠
                    <input type="checkbox" name="hobby" value="게임"/>게임
                    <input type="checkbox" name="hobby" value="낚시"/>낚시
                </td>
            </tr>
            <tr>
                <th>나이</th>
                <td><input type="number" name="age" min="1" max="200" value="20"/></td>
            </tr>
            <tr>
                <th>보안등급</th>
                <td><input type="range" name="security" min="0" max="100" value="0" step="20"/></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="회원가입"/>
                </td>
            </tr>
        </table>
        </form>
        </fieldset>
    </body>
</html>










CSS는 따로 어려운게 아니고


html 코드의 바디 부분에 나오는 블록들에


속성을 달아주는 것이다.


html에서 테이블, 표를 만들때 Style을 통해 테두리를 만들었는데


그것도 CSS의 한 부분이라고 할 수 있다.





근데 구지 body에 명시 안하고 style에 하는 이유를 비유하자면


뼈대를 만들어놓고 스타일을 입혀야지


뼈대 만들면서 입히면 어떻게 될지 모르기 때문이다.


이러한 방법으로 하면 작업이 좀 느려질 뿐만 아니라


사이트 접근 시 뼈대만 보이다가 갑자기 style 효과가 주어지는 등 불안정적인 상태가 보인다.


그러므로 head에 쓰는걸 권장.





예전에 java FX할 때 프로젝트를 만들면 CSS 파일이 항상 담겨 있었다.


.css 확장자 파일은 하나의 style의 집합체라고 보면 되고


html에서 따로 경로 참조 코드를 쓰면 불러와진다.





보통 블록에 Id나 Class를 부여하여


해당 블록을 지정하여 속성을 변경한다.


또한 태그를 써서 전부 선택 할 수도 있다.





Id에 부여하는 방법은 #을 사용하여 잡고


Class를 부여하는 방법은 '.'을 사용하여 잡고


태그는 블록으로 잡는다.





특별한 케이스로도 있다.


만약 표 안의 특정 태그를 잡고싶을 때에는 '>'를 표시해서 자식관계를 표시하는데


'>'는 생략이 가능하다.


또한 input의 경우는 '[]'를 사용하여 특정 type 들만 골라서 변경 할 수 있다.


이러한 


아래 예시를 통해 여러가지 경우를 확인해보자.




<html>
    <head>
        <meta charset="UTF-8">
        <title>Input</title>
        <link rel="icon" href = "btn.png">
        <style>
            /*css 주석*/
            /*p태그 잡는 법*/
            p{
                /*전체 p 태그에 배경색 주기*/
                background-color: gray;
            }

            /*class 잡는 법*/
            .myclass{
                /*class="myclass"의 글자 색상 변경*/
                color: brown;
            }
            
            /*myid 잡는 법*/
            #myid{
                color: darkgoldenrod
                /*id가 중복인게 여러개 인 경우 무조건 첫번째 것을 인지*/
            }

            /*여러개 선택*/
            p, div{
                /*글자 굵기 : 600 b 태그*/
                font-weight: 600;
            }

            /*div의 자식인 p 잡는 법*/
            div>p{
                /*>를 통해서 자식 관계를 잡는데 >를 생략해도 정상적으로 잡힌다.*/
                background-color: blueviolet;
            }

            /*input 잡는 법*/
            input[type = 'text']{ /*[]를 생략하면 input이 전부 잡히고 특정 타입만 변경할 때 쓴다.*/
                background-color: forestgreen;
            }
            input[type = 'email']{
                background-color:lightskyblue;
            }

            /*img 태그 잡는 법*/
            img{
                /*하나만 설정하면 비율에 맞춰서 작아 진다.*/
                width:100;
                border: 1px solid white;
                /*border는 테두리 라인을 말한다.*/
                /*테두리는 다음 장에서 자세히*/
            }
            /*마우스가 올라갔을 경우 강조 표시*/
            img:hover{
                border: 1px solid black;
                /*테두리(픽셀)가 생기면서 마우스를 올릴 때 마다 이미지가 밀린다.*/
                /*위의 border을 통해 픽셀 테두리를 만들어 놓으면 이미지가 밀리지 않는다.*/
            }
            
        </style>
        <!--스타일이 많으면 로딩이 느려질 수 있다.-->
        <!--아이디가 # 클래스가 . 태그는 p-->
    </head>
    <body>
        <p id="myid">id가 있는 요소</p>
        <p class="myclass">Class가 있는 요소</p>
        <p class="myclass">Class가 있는 요소</p>
        <p>태그만 있는 요소</p>
        <div>DIV 요소</div>
        <!--div는 기능 X, 영역만 묶어줌-->
        <div>
            <p>DIV 안의 P 태그</p>
        </div>
        <input type="text" placeholder="이름"/>
        <input type="email" placeholder="이메일"/>
        <br/><br/>
        <img src="img/img01.jpg" alt="초록버섯"/>
        <img src="img/img02.jpg" alt="꽃"/>
        <img src="img/img03.jpg" alt="마리오"/>
        <img src="img/img04.jpg" alt="초코송이"/>
    </body>

</html>







이미지는 아무거나 쓰세요


위의 코드를 보면 style에 특이한걸 넣은게 아닌데도 코드의 길이가 길다.





input을 사용할 때 form을 사용했었는데


form은 내용을 서버에 전달할 때 핵심인 개념이다.


저번 게시글에서 form으로 input 항목들을 묶었을 때 reset 버튼을 만들어 누르면 전부 리셋되는걸 확인 했었을 것이다.


이렇게 form으로 묶어 속성에 보낼 서버와 보낼 방식을 지정하고


특정 버튼을 누르면 작동이 된다.


방식에는 아래와 같이 두가지 지정 방법이 있다


get 방식은 url 그대로 보내 빠르지만 보안이 안좋다.


post 방식은 head와 붙여 보내 느리지만 보안에 좋다.



마지막으로 데이터가 전송된 것을 확인하려면 서버가 필요하지만 우선 서버는 생략한다.



form을 선언할 때 <form action="" method="POST">와 같이 만들면 된다.



아래의 예제를 확인해 get과 post의 차이를 확인해보자



<html>
    <head>
        <meta charset="UTF-8">
        <title>Input</title>
        <link rel="icon" href = "btn.png">
    </head>
    <body>
        <!--action="보낼 서버", method="GET|POST"-->
        <form action="" method="GET">
            First Name<input type="text" name="firstname"/>
            <br/>
            Last Name<input type="text" name="lastname"/>
            <br/><br/>
            <input type="submit"/>
        </form>

    </body>

</html>







주소줄을 보면 내가 입력한 정보가 제출을 눌렀을때 url에 전부 나오는게 보인다.


이러한 이유로 보안에 안좋다.


참고로 한글을 입력하면 url에는 한글로 보이긴 한데 복사해서 붙여넣으면 url 코딩 방법으로 이상하게 나온다.






<html>
    <head>
        <meta charset="UTF-8">
        <title>Input</title>
        <link rel="icon" href = "btn.png">
    </head>
    <body>
        <!--action="보낼 서버", method="GET|POST"-->
        <form action="" method="POST">
            First Name<input type="text" name="firstname"/>
            <br/>
            Last Name<input type="text" name="lastname"/>
            <br/><br/>
            <input type="submit"/>
        </form>

    </body>

</html>




method를 post로 바꾸면 url에 뜨지 않는다.






이것을 08(https://qdgbjsdnb.tistory.com/136)의 예제에 적용하면 다음과 같다.




<html>
    <head>
        <meta charset="UTF-8">
        <title>로그인 박스</title>
        <style>
                th{
                    width: 50px;
                }
                td{
                    width: 50px;
                }
            </style>
    </head>
    <body>
        <h2>로그인</h2>
        <hr/>
        <form action="" method="GET">
            <fieldset>
            <table>
                <tr><!--행(row)선언-->
                    <th ><b>ID</b></th>
                    <th><input type="text" name = "UserID" value=""placeholder = "아이디를 입력 해주세요."/></th>
                    <th rowspan="2"><input type="submit" value="로그인"/></th>
                </tr>
                <tr><!--행(row)선언-->
                    <th><b>PW</b></th>
                    <th><input type="password" name = "UserPW" value=""placeholder = "비밀번호를 입력 해주세요."/></th>
                </tr>
                <tr><!--행(row)선언-->
                    <th colspan="3"><input type="button" value="회원가입"/> <input type="button" value="아이디/비번 찾기"></th>
                </tr>
            </table>
            </fieldset>
        </form>

    </body>
</html>




<html>
    <head>
        <meta charset="UTF-8">
        <title>회원가입 페이지</title>
        <style>
            td{
                width: 300px;
            }
        </style>
    </head>
    <body>
        <fieldset>
        <h2>회원가입</h2>
        <hr/>
        <form action="" method="GET">
        <table>
            <tr>
                <th>아이디</th>
                <td><input type="text" name = "UserID" value=""/></td>
            </tr>
            <tr>
                <th>비밀번호</th>
                <td><input type="text" name = "UserPW" value=""/></td>
            </tr>
            <tr>
                <th>비밀번호 확인</th>
                <td><input type="text" name = "ReUserPW" value=""/></td>
            </tr>
            <tr>
                <th>이름</th>
                <td><input type="text" name = "Name" value=""/></td>
            </tr>
            <tr>
                <th>이메일</th>
                <td><input type="email" name="mail" required/></td>
            </tr>
            <tr>
                <th>생년월일</th>
                <td>
                    <select name="year">
                        <option value="1995">1995</option>
                        <option value="1996"d>1996</option>
                        <option value="1997" selected>1997</option>
                        <option value="1998">1998</option>
                        <option value="1999">1999</option>
                        <option value="2000">2000</option>
                    </select>
                    <select name="month">
                        <option value="01" selected>01</option>
                    </select>
                    <select name="day">
                        <option value="01" selected>01</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>성별</th>
                <td>
                    <input type="radio" name="gender" value="male"/> 남자
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="gender" value="female"/> 여자
                </td>
            </tr>
            <tr>
                <th>취미</th>
                <td>
                    <input type="checkbox" name="hobby" value="드라이브"/>드라이브
                    <input type="checkbox" name="hobby" value="스포츠"/>스포츠
                    <input type="checkbox" name="hobby" value="게임"/>게임
                    <input type="checkbox" name="hobby" value="낚시"/>낚시
                </td>
            </tr>
            <tr>
                <th>나이</th>
                <td><input type="number" name="age" min="1" max="200" value="20"/></td>
            </tr>
            <tr>
                <th>보안등급</th>
                <td><input type="range" name="security" min="0" max="100" value="0" step="20"/></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="회원가입"/>
                </td>
            </tr>
        </table>
        </form>
        </fieldset>
    </body>
</html>




+ Recent posts