JAVASCRIPT 배열

배열 추가(변경) 방법 : 배열명[인덱스명] = "값";

.join() : 배열 사이에 넣을 값 지정 (default = ,) (타입 = String)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const city = ["서울", "부산", "인천"];
      const printArr = () => {
        for (let i = 0; i < city.length; i++) {
          document.write(`배열 데이터[${i}] : ${city[i]}<br>`);
        }
      };
      printArr();
      city[3] = "대구";
      document.write("<hr>" + city);
      document.write(`<br>${typeof city}<br>`);
      const join01 = city.join();
      const join02 = city.join("-");
      document.write(`조인 결과 1 : ${join01}, type : ${typeof join01}<br>`);
      document.write(`조인 결과 2 : ${join02}, type : ${typeof join02}<br>`);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 (2)

배열명.push() : 배열 맨 뒤에 값을 추가

배열명.pop() : 배열 맨 뒤 값을 삭제

배열명.unshift() : 배열 맨 앞에 값을 추가

배열명.shift() : 배열 맨 앞에 값을 삭제

배열명.concat() : 해당 배열을 복사한다 (복사 후 추가도 가능)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let kdata = ["서울", "부산"];
      document.write(`기본 배열 : ${kdata}<hr>`);
      kdata.push("인천", "대구");
      document.write(`push : ${kdata}<br>`);
      kdata.pop();
      document.write(`pop : ${kdata}<hr>`);

      kdata.unshift("111", "222");
      document.write(`unshift : ${kdata}<br>`);
      kdata.shift();
      document.write(`shift : ${kdata}<hr>`);

      let data = kdata.concat("안녕", "하세요");
      document.write(`concat : ${data}, type : ${typeof data}<br>`);
      document.write(`shift : ${kdata}<hr>`);
      
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 (3)

배열명.forEach(함수); : 단순출력, 연산 (return값을 가질 수 없다)

배열명.map(함수); : return값을 가질 수 있다

* 함수를 생성해서 넣을수도 있고, 생성된 함수를 넣을수도 있다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const data = ["1111", "2222", "3333"];
      for (let i = 0; i < data.length; i++) {
        document.write(data[i] + "<br>");
      }
      document.write("<hr>");
      //   function t(d) {
      //     console.log(d);
      //   }

      //   const t = (d) => {
      //     console.log(d);
      //   };
      //   data.forEach(t);

      data.forEach((d) => {
        document.write(d + "<br>");
      });
      /*
      function t02(d) {
        return `<b style="color:blue;">${d}</b>`;
      }
      */
      const t02 = (d) => `<b style="color:red;">${d}</b>`;
      const mapData = data.map(t02);
      document.write("<hr>" + mapData + "<hr>");

      const mapData02 = data.map((d) => `<b style="color:yellow;">${d}</b>`);
      document.write("<hr>" + mapData02 + "<hr>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 (4)

dic : 키와 값을 가진다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let dic = { f0: 100, f1: 200 };
      document.write(`기본 값 : ${dic}<br>`);

      function test() {
        document.write("test실행<br>");
      }

      dic.f2 = "값 추가";
      dic["f3"] = "f3333";
      dic.func = test;

      document.write(dic + "<br>");
      document.write(dic["f1"] + "<br>");
      document.write(dic.f2 + "<br>");
      document.write(dic.func + "<br>");
      dic.func();
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 (5)

배열명.filter(함수) : 데이터를 비교해서 해당하는 값만 돌려줌

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const data = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
      const filter01 = (value, index) => {
        console.log(`index : ${index}, value : ${value}`);
        return value >= 50;
      };
      const result01 = data.filter(filter01);
      document.write(result01 + "<br>");
      
      const result02 = data.filter((value) => value <= 50);
      document.write(result02 + "<br>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 (6)

for (const 타입명 of 배열명) : forEach문

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      let userDB = [
        { id: "aaa", name: "홍길동", age: "20" },
        { id: "bbb", name: "김개똥", age: "30" },
        { id: "ccc", name: "고길동", age: "40" },
      ];
      function init() {
        //alert("실행");
        const div = document.querySelector(".test");
        let msg = `아이디 : ${userDB[0].id}<br>
        이름 : ${userDB[0].name}<br>
        나이 : ${userDB[0].age}<br>`;
        div.innerHTML = msg;

        const div2 = document.querySelector(".test2");
        let msg2 = "";
        for (const user of userDB) {
          msg2 += `아이디 : ${user.id}<br>
            이름 : ${user.name}<br>
            나이 : ${user.age}<br>`;
        }
        div2.innerHTML = msg2;
      }
    </script>
  </head>
  <body onload="init()">
    <div class="test"></div>
    <hr />
    <div class="test2"></div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz01

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      let userInfo = [
        { id: "aaa", name: "홍길동", age: 20 },
        { id: "bbb", name: "김개똥", age: 30 },
        { id: "ccc", name: "고길동", age: 40 },
      ];
      function init() {
        const div1 = document.querySelector(".list");
        let msg1 = `<h3>목록을 보여 줍니다</h3><hr>`;
        div1.innerHTML = msg1;

        // const div2 = document.querySelector(".search");
        // let msg2 = `<hr><input placeholder="input id" id="search">`;
        // div2.innerHTML = msg2;

        // const div3 = document.querySelector(".delete");
        // let msg3 = `<hr><input placeholder="input id">`;
        // div3.innerHTML = msg3;
      }
      function listFunc() {
        const list1 = document.querySelector(".list");
        let msg01 = `<table border="1">`;
        msg01 += `<tr>
                        <td>아이디</td> <td>이름</td> <td>나이</td>
                     </tr>`;
        for (i = 0; i < userInfo.length; i++) {
          console.log(userInfo[i].id);
          msg01 += `<tr>
                        <td>${userInfo[i].id}</td> <td onclick="info('${userInfo[i].name}')">${userInfo[i].name}</td> <td>${userInfo[i].age}</td>
                     </tr>`;
        }
        msg01 += `</table>`;

        list1.innerHTML = msg01;
      }
      function info(name) {
        const list = document.querySelector(".list");
        let msg;
        for (i = 0; i < userInfo.length; i++) {
          if (name == userInfo[i].name) {
            msg = `<h2>아이디 : ${userInfo[i].id}</h2>
                <h2>이름 : ${userInfo[i].name}</h2>
                    <h2>나이 : ${userInfo[i].age}</h2>
                `;
          }
        }
        list.innerHTML = msg;
      }

      function searchFunc() {
        const search = document.querySelector("#search");
        val = search.value;

        const list1 = document.querySelector(".list");
        let msg02 = `<table border="1">`;
        msg02 += `<tr>
                        <td>아이디</td> <td>이름</td> <td>나이</td>
                     </tr>`;
        for (i = 0; i < userInfo.length; i++) {
          if (val == userInfo[i].id) {
            msg02 += `<tr>
                        <td>${userInfo[i].id}</td> <td>${userInfo[i].name}</td> <td>${userInfo[i].age}</td>
                     </tr>`;
          }
        }
        msg02 += `</table>`;
        list1.innerHTML = msg02;
      }
      function deleteFunc() {
        const d = document.querySelector("#delete");
        val2 = d.value;

        const list2 = document.querySelector(".list");
        let msg03 = `<table border="1">`;
        msg03 += `<tr>
                        <td>아이디</td> <td >이름</td> <td>나이</td>
                     </tr>`;

        function rs(value) {
          return value.id != val2;
        }
        const result = userInfo.filter(rs);

        for (i = 0; i < result.length; i++) {
          msg03 += `<tr>
                        <td>${result[i].id}</td> <td >${result[i].name}</td> <td>${result[i].age}</td>
                     </tr>`;
        }
        console.log(result.id);
        msg03 += `</table>`;
        list2.innerHTML = msg03;
      }
      function ad(asdf) {
        console.log(asdf);
      }
    </script>
  </head>
  <body onload="init()">
    <div class="list"></div>
    <button id="btnList" onclick="listFunc()">모든 회원 보기</button>
    <div>
      <hr />
      <input placeholder="input id" id="search" />
    </div>
    <div></div>
    <button id="btnSearch" onclick="searchFunc()">특정 회원 조회</button>
    <div></div>

    <div>
      <hr />
      <input placeholder="input id" id="delete" />
    </div>
    <button id="btnDelete" onclick="deleteFunc()">특정 회원 삭제</button>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

JAVASCRIPT 배열 

setTimeout(함수, 시간); : 해당하는 함수를 실행하는데 걸리는 시간 지정 (1000 = 1초)

clearTimeout(setTimeout()) : setTimeout()을 취소하는 역할

Date() : 현재 시간을 알려주는 내장 함수

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const test = () => {
        //alert("test 호출");
      };
      window.onload = () => {
        //document.write("처음 실행<br>");
        //setTimeout(test, 2000);
        //document.write("2초 대기중...<br>");
      };
      let e;
      const digClock = () => {
        let today = new Date();
        let time = today.getMonth() + 1 + "월";
        time += today.getDate() + "일";
        time += today.getHours() + "시";
        time += today.getMinutes() + "분";
        time += today.getSeconds() + "초";
        document.getElementById("clock").innerHTML = time;
        e = setTimeout(digClock, 1000);
      };
      const end = () => {
        clearTimeout(e);
      };
    </script>
    <div id="clock"></div>
    <button onclick="digClock()">시작</button>
    <button onclick="end()">종료</button>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 

setInterval(함수, 시간) : 지정한 시간이 지날때마다 함수를 반복 실행 

clearInterval() : setInterval()을 취소하는 역할

.toLocalString() : 객체에 맞춰 문자열을 반환

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let myVar;
      const start = () => {
        myVar = setInterval(myTimer, 1000);
      };
      const myTimer = () => {
        let d = new Date();
        document.getElementById("time").innerHTML = d.toLocaleString();
      };
      const stop = () => {
        clearInterval(myVar);
      };
    </script>
    <p id="time"></p>
    <button onclick="start()">start</button>
    <button onclick="stop()">stop</button>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT

.insertAdjacentHTML("afterbegin") : 앞에 내용 추가

.insertAdjacentHTML("beforeend") : 뒤에 내용 추가

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var cnt = 0;
      const inner = () => {
        cnt++;
        let msg = `내용 : ${cnt}<br>`;
        let txt = document.getElementById("txt");
        txt.innerHTML = msg;
        //txt.insertAdjacentHTML("afterbegin", msg);
        //txt.insertAdjacentHTML("beforeend", msg);
      };
    </script>
    <div id="txt">안녕하세요</div>
    <button onclick="inner()">클릭</button>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT

.setAttribute() : 속성값 설정(추가)

document.createElement() : html태그요소를 추가(설정)하는 역할

태그명.appendChild() : 태그의 자식요소에 추가하는 역할

.remove() : 해당 태그 전체 삭제

.removeChild(객체) : 먼저 삭제할 객체를 지정해서 하나씩 삭제 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let img;
      function add() {
        img = document.createElement("img");
        console.log(img);
        img.src = "image.png";
        img.setAttribute("width", "100");
        img.setAttribute("style", "height:100px border : 1px solid;");

        document.getElementById("test").appendChild(img);
      }
      function addTB() {
        let data = [
          { id: "aaa", name: "홍길동" },
          { id: "bbb", name: "김개똥" },
        ];
        let table = document.createElement("table");
        data.forEach((value) => {
          var tr = document.createElement("tr");
          var td1 = document.createElement("td");
          td1.innerHTML = value.id;
          tr.appendChild(td1);

          var td2 = document.createElement("td");
          td2.innerHTML = value.name;
          tr.appendChild(td2);

          table.appendChild(tr);
        });
        document.getElementById("test").appendChild(table);
      }
      function remove() {
        let items = document.getElementById("test");
        //document.getElementById("test").remove();
        //items.remove();
        items.removeChild(items.childNodes[0]);
        //items.removeChild(items.childNodes[items.childNodes.length - 1]);
      }
    </script>
    <p id="test"></p>
    <a href="#" onclick="addTB()">테이블 추가</a>
    <b onclick="add()">add 클릭</b>
    <b onclick="remove()">이미지 삭제 클릭</b>
  </body>
</html>

 

실행 결과

 

'javaScript' 카테고리의 다른 글

JAVASCRIPT 활용 (3)  (0) 2024.03.27
JAVASCRIPT 활용  (0) 2024.03.25
JAVASCRIPT 기초  (0) 2024.03.22

 

 

 

 

 

 

JAVASCRIPT  함수 기능 (1)

함수 생성 방법 : function 함수명() {}

함수 호출 방법 : 함수명();

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      console.log("프로그램 시작!!!");
      function test() {
        console.log("text 함수 실행");
      }
      console.log("함수 지나옴");
      test();
      console.log("프로그램 종료!!!");

      function localVal() {
        let num = 20000;
        if (true) {
          num += 10000;
          console.log("if : " + num);
        }
        console.log("localVal : " + num);
      }
      localVal();

      let num = 1234;
      function localVal01() {
        console.log("localVal01 : " + num);
      }
      function localVal02() {
        console.log("localVal02 : " + num);
      }
      localVal01();
      localVal02();
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 함수 기능 (2)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      sumFunc();
      function sumFunc() {
        const n1 = prompt("수 입력");
        const n2 = prompt("수 입력");
        const sum = Number(n1) + Number(n2);
        document.write(`${n1} + ${n2} = ${sum}<br>`);
      }
      */
      /*
      const n1 = prompt("수 입력");
      const n2 = prompt("수 입력");
      sumFunc(n1, n2);
      function sumFunc(n1, n2) {
        const sum = Number(n1) + Number(n2);
        document.write(`${n1} + ${n2} = ${sum}<br>`);
      }
      */
      const n1 = prompt("수 입력");
      const n2 = prompt("수 입력");
      const sum = op(n1, n2);
      sumFunc(n1, n2, sum);
      function op(n1, n2) {
        const sum = Number(n1) + Number(n2);
        return sum;
      }
      function sumFunc(n1, n2, sum) {
        document.write(`${n1} + ${n2} = ${sum}<br>`);
      }
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT  함수 기능 (3)

* return으로 여러개 값을 돌려주려면 배열 or object 타입 사용 가능

꺼내오는 방법 : 함수명[인덱스] or 함수명["키 값"] or 함수명.키 값

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function testFunc01() {
        let num = 95;
        let txt = "안녕하세요";
        return num, txt;
      }
      const result = testFunc01();
      document.write(result + "<hr>");

      function testFunc02() {
        let num = 95;
        let txt = "안녕하세요";
        const arr = [num, txt];
        return arr;
      }
      const result2 = testFunc02();
      document.write(result2 + "<br>");
      document.write(result2[0] + "<br>");
      document.write(result2[1] + "<hr>");

      function testFunc03() {
        let num = 95;
        let txt = "안녕하세요";
        const arr = { num: num, txt: txt };
        return arr;
      }
      const result3 = testFunc03();
      console.log(result3);
      document.write(result3["num"] + "<br>");
      document.write(result3.txt + "<hr>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVSCRIPT 함수 기능 (4)

* 함수 이름이 같으면, 인자 개수가 달라도 마지막 함수만 실행

* arguments를 통해 매개변수의 개수 제한없이 받아올 수 있다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function test01(x, y) {
        console.log("첫번째 함수 실행!!!");
      }
      function test01(x) {
        return x;
      }
      document.write("함수 호출 인자 없음 : " + test01() + "<br>");
      document.write("함수 호출 인자 1 : " + test01(10) + "<br>");
      document.write("함수 호출 인자 2 : " + test01(10, 20) + "<br>");

      function test02(x, y, z) {
        document.write(`${x}, ${y}, ${z} <br>`);
        if (z == undefined) {
          sum = x + y;
        } else {
          sum = x + y + z;
        }
        return sum;
      }
      let r1 = test02(10, 20);
      let r2 = test02(10, 20, 30);
      document.write(`매개변수 2개 : ${r1}<br>`);
      document.write(`매개변수 3개 : ${r2}<br>`);

      function test03() {
        console.log(arguments.length);
        let i,
          sum = 0;
        for (i = 0; i < arguments.length; i++) {
          sum = sum + arguments[i];
          document.write(arguments[i]);
        }
        return sum;
      }
      let r3 = test03(10, 20);
      let r4 = test03(10, 20, 30);
      document.write(`매개변수 2개 : ${r3}<br>`);
      document.write(`매개변수 3개 : ${r4}<br>`);
    </script>
  </body>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 즉시 실행 함수

즉시 실행 함수 표현식 : (function 함수명(){})();

* 즉시 실행 함수에 값을 전달해 줄 때, (값); 방식으로 전달해준다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      (function test() {
        //alert("즉시 실행 함수!!!");
      })();
      let result = (function test1() {
        return "서버로 부터 데이터를 받아와 화면에 보여줌";
      })();
      document.write(result + "<br>");

      let name = "홍길동";
      let result02 = (function test02(n) {
        let db = n + "님의 정보 입니다";
        return db;
      })(name);
      document.write(result02 + "<br>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 익명 함수

익명 함수 표현식 : let 변수명 = function(){};  또는

                      let 변수명 = () => ;   또는

              let 변수명 = () => {};

* =>표현식을 쓸 때 중괄호를 쓰게 되면 return을 추가해야 한다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function test(x, y) {
        return x + y;
      }
      document.write(test(1, 2) + "<br>");

      let sumFunc = function (x, y) {
        return x + y;
      };
      document.write(sumFunc(10, 20) + "<br>");

      let sumFunc1 = (x, y) => x + y;
      document.write(sumFunc1(100, 200) + "<br>");

      let sumFunc2 = (x, y) => {
        let num = 100;
        return x + y + num;
      };
      document.write(sumFunc2(1000, 2000) + "<br>");

      const result01 = () => {
        10 + 20
      };
      const result02 = () => 10 + 20;
      const result03 = () => (10 + 20);

      document.write("<hr>");
      document.write(result01() + "<br>");
      document.write(result02() + "<br>");
      document.write(result03() + "<br>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

Quiz01

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let input = () => {
        let num1 = Number(prompt("첫번째 수 입력"));
        let num2 = Number(prompt("두번째 수 입력"));
        const arr = { num1: num1, num2: num2 };
        return arr;
      };

      let result01 = (n1, n2) => {
        if (n1 > n2) {
          return n1;
        } else {
          return n2;
        }
      };
      let arr = input();
      document.write("큰 수 : " + result01(arr.num1, arr.num2) + "<hr>");

      let input02 = () => {
        let num1 = Number(prompt("수(홀, 짝) 입력"));
        return num1;
      };

      let result02 = (n) => {
        if (n % 2 == 0) {
          return "짝수 입니다.";
        } else {
          return "홀수 입니다.";
        }
      };

      ////////////////////////////
      let num2 = input02();
      document.write("수는 " + result02(num2) + "<hr>");

      let input03 = () => {
        let num1 = Number(prompt("수(3의 배수) 입력"));
        return num1;
      };

      let result03 = (n) => {
        if (n % 3 == 0) {
          return "3의 배수 입니다.";
        } else {
          return "3의 배수가 아닙니다.";
        }
      };
      num3 = input03();
      document.write("수는 " + result03(num3) + "<hr>");

      let input04 = () => {
        let num1 = Number(prompt("수(소수) 입력"));
        return num1;
      };

      let result04 = (n) => {
        for (i = 2; i <= n; i++) {
          if (n % i == 0) {
            if (i == n) {
              return "소수 입니다";
            } else {
              return "소수가 아닙니다";
            }
          }
        }
      };
      num4 = input04();
      document.write("수는 " + result04(num4) + "<hr>");

      let input05 = () => {
        let num1 = Number(prompt("수(절대값) 입력"));
        return num1;
      };

      let result05 = (n) => {
        return Math.abs(n);
      };
      let num5 = input05();
      document.write("수의 절대값 : " + result05(num5) + "<hr>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT event (1)

onclick="" : 클릭 할 경우 실행

ondblclick="" : 더블클릭 할 경우 실행

onmouseover="" : 마우스를 위에 올렸을 때 실행

document.getElementById(" "); : id값이 일치하는 태그값을 얻어오겠다는 뜻

* 얻어온 태그 활용 법 : id값.기능

document.getElementByClassName(" "); : 클래스명이 일치하는 태그값을 얻어오겠다는 뜻

document.querySelector(" "); : id또는 클래스기 일치하는 태그값을 얻어오겠다는 뜻

window.onload : 페이지가 호출되면 자동으로 실행

메소드.addEventListener("방식", 실행 할 메소드) : 해당 메소드를 어떤 방식을 동작 했을때 선택한 메소드 실행

.innerHTML : html 형식으로 적용

.innerText : text 문자 형식으로 적용

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #h3 {
        color: red;
      }
    </style>
  </head>
  <body>
    <script>
      //function clickEvent(){}
      const clickEvent = () => {
        //alert("클릭");
        const name = document.getElementById("name");
        console.log(name);
        /*
        name.value = "안녕하세요";
        name.style.background = "red";
        */
        const name1 = document.querySelector("#name2");
        console.log(name1);
        name1.value = name.value;
        name.value = "";
      };
      window.onload = () => {
        //alert("onload");
        //document.getElementsByClassName("btn");
        const btn = document.querySelector(".btn");
        console.log(btn);
        btn.addEventListener("click", innerTest);
      };
      const innerTest = () => {
        const txt = document.getElementById("text");
        let msg = "<h3 id='h3'>내용바꾸기</h3>";
        txt.innerHTML = msg;
        //txt.innerText = msg;
      };
    </script>
    <input type="text" id="name" placeholder="input name" /><br />
    <input type="text" id="name2" placeholder="input name" /><br />
    <input type="button" onclick="clickEvent()" value="클릭" />
    <input type="button" class="btn" value="클릭2" />
    <br />
    <label id="text">텍스트 값</label>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT event (2)

onmousedown="" : 마우스 클릭했을 때

onmouseup="" : 마우스 클릭 후 땠을 때

onmousemove="" : 마우스가 움직일 때

onmouseover="" : 마우스가 들어왔을 때

onmouseout="" : 마우스가 나갔을 때

* onload() = html 실행 후 실행된다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      const myMousedown = () => {
        document.getElementById("span").innerHTML = "마우스 DOWN";
      };
      const myMouseup = () => {
        document.getElementById("span").innerHTML = "마우스 UP";
      };
      let cnt = 0;
      const myMousemove = () => {
        cnt++;
        document.getElementById("count1").innerHTML = cnt;
      };
      const myMouseover = () => {
        cnt++;
        document.getElementById("count2").innerHTML = cnt;
      };
      const myMouseout = () => {
        document.getElementById("count2").innerHTML = "마우스 나감";
      };
    </script>
  </head>
  <body>
    <div onmousedown="myMousedown()" onmouseup="myMouseup()">
      <span id="span">이벤트 알아보기</span>
    </div>
    <div
      onmousemove="myMousemove()"
      style="background: gray; width: 100px; height: 100px"
    >
      <span id="count1">0</span>
    </div>
    <div
      onmouseover="myMouseover()"
      onmouseout="myMouseout()"
      style="background: gray; width: 100px; height: 100px"
    >
      <span id="count2">0</span>
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT event (3)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img {
        width: 100px;
        height: 200px;
      }
    </style>
    <script>
      onload = () => {
        //alert("execute");
        let img = document.getElementById("myImg");
        img.addEventListener("mouseover", changeFunc01);
        img.addEventListener("mouseout", changeFunc01);
      };
      let num = 0;
      changeFunc01 = () => {
        const arr = ["image.png", "image2.png"];
        let myImg = document.getElementById("myImg");
        let myImg02 = document.getElementById("myImg02");
        myImg.src = arr[num];
        myImg02.src = arr[num];
        //num = num == 0 ? 1 : 0;
        if (num == 0) {
          num = 1;
        } else {
          num = 0;
        }
      };
    </script>
  </head>
  <body>
    <img id="myImg" src="image.png" /><br />
    <img
      id="myImg02"
      src="image.png"
      onmousedown="changeFunc01()"
      onmouseup="changeFunc01()"
    /><br />
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

Quiz02

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
      }
      footer {
        background-color: pink;
        width: 280px;
        height: 50px;
        padding-left: 120px;
      }
    </style>
    <script>
      let num = 1;
      changeFunc = (n) => {
        let myImg = document.getElementById("myImg");
        if (n == 0) {
          num == 1 ? (num = 8) : num--;
          myImg.src = `최근상품0${num}.jpg`;
        } else {
          num == 8 ? (num = 1) : num++;
          myImg.src = `최근상품0${num}.jpg`;
        }
      };
    </script>
  </head>
  <body>
    <div>
      <img
        id="myImg"
        src="최근상품01.jpg"
        style="width: 400px; height: 400px"
      />
      <footer>
        <button onclick="changeFunc(0)">이전 사진</button>
        <button onclick="changeFunc(1)">다음 사진</button>
      </footer>
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

 

Quiz03

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>겔러리</title>
    <style>
      * {
        margin: 0;
      }
      img {
        width: 100px;
        height: 100px;
      }
      .img {
        border: 1px solid gray;
        width: 100px;
        height: 100px;
        position: relative; 
      }
      .flex {
        display: flex;
      }
      span {
        position: absolute;
        background: orange;
        top: 25px;
        left: 25px;
        width: 50px;
        height: 50px;
        text-align: center;
        line-height: 50px;
      }
    </style>
    <script type="text/javascript">
      const images = [
        "resources/images/최근상품01.jpg",
        "resources/images/최근상품02.jpg",
        "resources/images/최근상품03.jpg",
        "resources/images/최근상품04.jpg",
        "resources/images/최근상품05.jpg",
        "resources/images/최근상품06.jpg",
        "resources/images/최근상품07.jpg",
        "resources/images/최근상품08.jpg",
      ];
      window.onload = function init() {
        console.log("init");
        let msg = "<div class='flex'>";
        for (let i = 0; i < images.length; i++) {
          msg += `<div class="img" id="${i}" onMousemove="imgOver(${i})" onMouseout="imgOut(${i})">`;
          msg += `<img src="${images[i]}" >`;
          msg += "</div>";
          if (i + 1 == Number(images.length / 2))
            msg += "</div><div class='flex'>";
        }
        const wrap = document.getElementById("wrap");
        wrap.innerHTML = msg;
      };
      const imgOver = (index) => {
        const span = document.getElementById(index);
        span.innerHTML = `<span onMousemove="imgOver(${index})">선택</span>`;
      };
      const imgOut = (index) => {
        const div = document.getElementById(index);
        div.innerHTML = `<img src="${images[index]}">`;
      };
    </script>
  </head>
  <body>
    <div id="wrap"></div>
  </body>
</html>

 

실행 결과

 

'javaScript' 카테고리의 다른 글

JAVASCRIPT 활용 (3)  (0) 2024.03.27
JAVASCRIPT 활용 (2)  (0) 2024.03.26
JAVASCRIPT 기초  (0) 2024.03.22

 

 

 

 

 

JAVASCRIPT란?

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 변수

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 기능 (1)

 사용 방법 : <script></script>

* 문자열을 사용할때는 ', " 둘다 사용 가능하다

console.log() : 콘솔창에 출력

typeof 변수명 : 변수의 자료형 확인

* console.log()로 출력한 내용은 F12 → Console을 통해 확인 가능

* 자료형 제한이 없다

* 에러가 발생해도 실행은 가능하다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num = 100;
      let str = "문자열";
      let fl = 1.123;
      let bool = true;
      let arr = [1, 2, 3];
      let obj = { num: "홍길동", age: 20 };
      let test;
      console.log(num, typeof num);
      console.log(str, typeof str);
      console.log(fl, typeof fl);
      console.log(bool, typeof bool);
      console.log(arr, typeof arr);
      console.log(obj, typeof obj);
      console.log(test, typeof test);

      num = [1, 2, 3];
      console.log("--------");
      console.log("변경 후 : ", num, typeof num);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

JAVASCRIPT 기능 (2)

prompt() : 문자열 형식으로 입력한 값을 받아옴

document.write : 현재 페이지에 출력

* `(backtick)을 사용하면 ${변수명}을 사용하여 출력 가능

// : 주석

변수 타입.toString() : 문자열로 형변환

(변수 타입+ "") : 문자열로 형변환

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      let name = "홍길동";
      let age = prompt("나이입력 : ");
      document.write("학생 이름 : " + name + "<br>");
      document.write("학생 나이 : " + age + "<br>");

      document.write(`이름 : ${name}님의 나이는 ${age}살 입니다<hr>`);

      console.log(`age : ${typeof age}`);
      let num = Number(age); //자료형 변환
      console.log(`num : ${typeof num}`);
      console.log(`num : ${typeof num.toString()}`);
      console.log(`num : ${typeof (num + "")}`);
    </script>
  </head>
  <body></body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT  기능(3)

* let을 통해 변수를 만들면 다시 let을 통해 변수 생성 불가

* var를 통해 변수를 만들고, 다시 var를 통해 변수 생성 가능

const : 상수화(값 변경 불가)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let name = "홍길동";
      //let name = "김개똥";
      name = "김개똥";
      var age = 20;
      var age = 30;
      console.log(age, name);

      const key = "키키키키";
      //key = "값 변경 ?";
      document.write(key);

      const str01 =
        "안녕하세요\
      그래\
      반갑다";

      const str02 = `그래
      반가워
      서~!`;

      document.write(str01);
      document.write("<br><b>" + str02 + "</b>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz01

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let name = prompt("당신의 이름은?");
      let age = prompt("당신의 나이는??");
      let addr = prompt("당신의 주소는?");

      document.write(`
        <table border="1">
          <tr>
              <th>이름</th> <th>나이</th> <th>주소</th>
          </tr>
          <tr>
              <td>${name}</td> <td>${age}</td> <td>${addr}</td>
          </tr>
          <tr>
              <td>${name}</td> <td>${age}</td> <td>${addr}</td>
          </tr>
      </table>

        `);
      //   document.write("<table border=&quot;1&quot;>");
      //   document.write("<tr>");
      //   document.write("<th>내용1</th> <th>내용2</th> <th>내용3</th>");
      //   document.write("</tr>");

      //   document.write("<tr>");
      //   document.write(
      //     "<td>" + name + "</td> <td>" + age + "</td> <td>" + addr + "</td>"
      //   );
      //   document.write("</tr>");
      //   document.write("<tr>");
      //   document.write(
      //     "<td>" + name + "</td> <td>" + age + "</td> <td>" + addr + "</td>"
      //   );
      //   document.write("</tr>");
      //   document.write("</table>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

JAVASCRIPT 기능 (4)

Number(변수명) : 변수만 실수에서 정수로 변환

parseInt(변수명) : 변수와 값 둘다 실수에 정수로 변환

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const num01 = prompt("첫번째 수 입력 : ");
      const num02 = prompt("두번째 수 입력 : ");
      console.log(typeof num01);
      console.log(num01 + num02);
      console.log(typeof Number(num01) + " : " + Number(num01));
      console.log(typeof parseInt(num01) + " : " + parseInt(num01));

      const su01 = 10,
        su02 = 3;
      document.write("10 / 3 => " + su01 / su02 + "<br>");
      document.write("Number 10 / 3 => " + Number(su01 / su02) + "<br>");
      document.write("parseInt 10 / 3 => " + parseInt(su01 / su02) + "<br>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT 연산자

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const num1 = 10;
      const num2 = 4;
      document.write(`${num1} / ${num2} = ${num1 / num2} <br>`);
      document.write(`${num1} / ${num2} = ${parseInt(num1 / num2)} <br>`);
      document.write(`${num1} * ${num2} = ${num1 * num2} <br>`);
      document.write(`${num1} % ${num2} = ${num1 % num2} <br><hr>`);
    </script>

    <script>
      let n1, n2;
      n1 = n2 = 5;
      n1 += 1;
      document.write(`${n1}<br>`);
      n1 -= 1;
      document.write(`${n1}<br>`);
      n1 *= n2;
      document.write(`${n1}<br>`);
      n1 /= n2;
      document.write(`${n1}<br>`);
      n1 %= n2;
      document.write(`${n1}<br><hr>`);

      n1 = "3";
      n2 = 3;
      document.write((n1 == n2) + "<br>");
      document.write((n1 != n2) + "<br>");
      document.write((n1 === n2) + "<br>");
      document.write((n1 !== n2) + "<br><hr>");

      document.write((true || false) + "<br>");
      document.write((true && false) + "<br>");
      document.write(!(true && false) + "<br><hr>");

      const x = 5;
      const y = 7;
      let result;
      result = x > y ? x : y;
      document.write("큰 값 : " + result + "<br>");
      result = x > y ? x - y : y - x;
      document.write(`큰 값 - 작은 값 : ${result}`);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz02

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let n1 = prompt("수(짝/홀) 입력");
      let n2 = prompt("수(3의배수) 입력");
      let n3 = prompt("첫번째 수 입력");
      let n4 = prompt("두번째 수 입력");

      let result1 = n1 % 2;
      result1 == 0
        ? document.write(`${n1}는 짝수 입니다<br>`)
        : document.write(`${n1}는 홀수 입니다<br>`);

      let result2 = n1 % 3;
      result2 == 0
        ? document.write(`${n1}는 3의 배수 맞음 입니다<br>`)
        : document.write(`${n1}는 3의 배수 아님 입니다<br>`);

      let result3 =
        n3 > n4
          ? document.write(`${n3}이 ${n4}보다 크다<br>`)
          : document.write(`${n4}이 ${n3}보다 크다<br>`);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT   if문

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num = 10;
      let msg = "";
      if (num > 100) {
        msg = "100보다 크다";
      } else {
        msg = "100보다 작다";
      }
      document.write(msg + "<hr>");

      num = 5;
      if (num % 2 == 0) {
        msg = "num은 짝수이며<br>";
        msg += "2의 배수 입니다.";
      } else {
        msg = "num은 홀수이며<br>";
        msg += "2의 배수가 아닙니다.";
      }
      document.write(msg + "<hr>");

      const saveId = "aaa",
        savePwd = "aaa";
      const inputId = "aaa",
        inputPwd = "aaa";
      if (saveId === inputId) {
        if (savePwd === inputPwd) {
          msg = "인증 성공!!!";
        } else {
          msg = "비밀번호 틀림!!!";
        }
      } else {
        msg = "존재하지 않는 id 입니다.";
      }
      //alert(msg);
      document.write(msg + "<hr>");

      num = 70;
      msg = "";
      if (num > 100) {
        msg += `${num}은 100보다 큰 수<br>`;
      } else if (num > 80) {
        msg += `${num}은 80보다 큰 수<br>`;
      } else if (num > 60) {
        msg += `${num}은 60보다 큰 수<br>`;
      } else {
        msg += `${num}은 60보다 작은 수<br>`;
      }
      document.write(msg + "<hr>");
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT   반복문

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num = 3;
      let msg;
      switch (num) {
        case 1:
          msg = "1과 같음";
          break;
        case 1:
          msg = "1과 같음";
          break;
        default:
          msg = "그 외의 값 입력";
          break;
      }
      document.write(msg + "<hr>");

      num = "그래";
      switch (num) {
        case "안녕":
          msg = "하세요";
          break;
        case "그래":
          msg = "반갑다";
          break;
        default:
          break;
      }
      document.write(msg + "<hr>");

      repeat = 5;
      msg = "";
      for (var i = 1; i < repeat; i++) {
        msg += `<h${i}>${i}번째 반복</h${i}>`;
      }
      document.write(msg + "<hr>");

      let sum = 0;
      num = 10;
      for (var i = 1; i <= num; i++) {
        sum += i;
      }
      document.write(sum + "<hr>");

      let evenSum = 0,
        oddSum = 0;
      sum = 0;
      num = 10;
      for (var i = 1; i <= num; i++) {
        sum += i;
        if (i % 2 == 0) {
          evenSum += i;
        } else {
          oddSum += i;
        }
      }
      document.write(`1 ~ 10 까지의 총 합 : ${sum}<br>`);
      document.write(`1 ~ 10 까지의 짝수 합 : ${evenSum}<br>`);
      document.write(`1 ~ 10 까지의 홀수 합 : ${oddSum}<br>`);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

JAVASCRIPT   while문

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let i = 1,
        sum = 0;
      while (i <= 10) {
        sum += i;
        i++;
      }
      document.write(sum + "<hr>");

      i = 1;
      while (i <= 5) {
        i++;
        if (i == 3) {
          console.log("3333333");
          continue;
          //break;
        }
        console.log(i);
        //i++;
      }
      i = 1;
      let msg = "";
      let bool = true;
      while (bool) {
        if (i == 3) {
          bool = false;
        }
        msg += i + ", ";
        i++;
      }
      document.write(msg);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz03

풀이 과정 (1)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num = prompt("커피 개수 입력");
      let result = 0;
      if (num > 10) {
        for (var i = 11; i <= num; i++) {
          result += 1500;
        }
        result += 2000 * 10;
      } else {
        result = 2000 * num;
      }
      document.write(`최종 금액 : ${result}원`);
    </script>
  </body>
</html>

풀이 과정 (2)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num = prompt("usb 개수 입력");
      let result = 0;
      if (num > 100) {
        for (var i = 1; i <= num; i++) {
          result += 5000;
        }
        result *= 88 / 100;
      } else if (num > 10) {
        for (var i = 1; i <= num; i++) {
          result += 5000;
        }
        result *= 9 / 10;
      } else {
        result = 5000 * num;
      }
      document.write(`최종 금액 : ${result}원`);
    </script>
  </body>
</html>

 

실행 결과 (1)

 

실행 결과 (2)

 

 

 

 

 

 

 

 

 

 

Quiz04

 

풀이 과정 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let dan = prompt("단 입력");
      for (var i = 1; i <= 9; i++) {
        document.write(`${dan} * ${i} = ${dan * i} <br>`);
      }
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz05

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      for (var i = 1; i <= 25; i++) {
        if (i % 5 == 0) {
          document.write(`${i} <br>`);
          continue;
        }
        document.write(`${i} , `);
      }
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

Quiz06

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      for (var i = 1; i <= 5; i++) {
        for (var j = 1; j <= 5; j++) {
          document.write(`${i * j} `);
        }
        document.write("<br>");
      }
      document.write("<hr>");
    </script>

    <script>
      let num = 0;
      for (var i = 1; i <= 5; i++) {
        for (var j = 1; j <= 5; j++) {
          num++;
          document.write(`${num} `);
        }
        document.write(`<br>`);
      }
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

Quiz07

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // &quot;
      let f = prompt("아파트 층 수 입력");
      document.write(`<table border="1">`);
      for (var i = f; i >= 1; i--) {
        document.write(`<tr>`);
        for (var j = 1; j <= 4; j++) {
          document.write(`<td>`);
          document.write(`${i}0${j}호`);
          document.write(`</td>`);
        }
        document.write(`</tr>`);
      }
      document.write(`</table>`);
    </script>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

 

Quiz08

 

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      while (true) {
        let num = prompt("수 입력(10 ~ 20사이의 수)");
        let result = 0;
        if (num >= 10 && num <= 20) {
          for (var i = 1; i <= num; i++) {
            result += i;
          }
          console.log(`입력 받은 수까지의 합 : ${result}`);
          break;
        } else {
          console.log("범위를 벗어났습니다. 다시...");
          continue;
        }
      }
    </script>
  </body>
</html>

 

실행 결과

 

'javaScript' 카테고리의 다른 글

JAVASCRIPT 활용 (3)  (0) 2024.03.27
JAVASCRIPT 활용 (2)  (0) 2024.03.26
JAVASCRIPT 활용  (0) 2024.03.25

 

 

 

 

 

CSS 기능 (1)

border : 테두리선 적용

min-height : 테두리선(박스) 최소 영역

* padding: 위쪽 오른쪽 아래쪽 왼쪽 (안쪽으로 밀어냄)

* margin: 위쪽 오른쪽 아래쪽 왼쪽 (바깥으로 밀어냄)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        background: yellow;
        width: 300px;
        border: 15px solid navy;
        /* min-height: 180px;*/
        padding: 25px 50px 0 0;
        margin: 25px;
      }
    </style>
  </head>
  <body>
    <div>
      css3 박스 모델은 content, padding, border, margin으로 구성되어 있다
    </div>
    <footer style="background: maroon">footer 지역입니다</footer>
  </body>
</html>

 

실행결과

 

 

 

 

 

 

 

 

CSS shadow

text-shadow : 텍스트에 그림자 생성 (좌우, 상하, 번짐도)

box-shadow : 이미지에 그림자 생성 (좌우, 상하, 번짐도)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .title {
        text-shadow: -10px 10px 15px black;
        font-size: 70pt;
      }
      img {
        padding: 20px;
        margin: 20px;
        width: 200px;
        height: 100px;
      }
      shadow1 {
        box-shadow: 5px 5px 10px black;
      }
      shadow2 {
        box-shadow: -5px -5px 10px black;
      }
    </style>
  </head>
  <body>
    <h1 class="title">내용이 들어옵니다~~~</h1>
    <img src="image.png" class="shadow1" />
    <img src="image.png" class="shadow2" />
  </body>
</html>

 

실행결과

 

 

 

 

 

 

 

 

CSS 배치

display: flex : 가로로 나열

#아이디명 태그명:nth-child(n) : n번째 자식에게 부여

order : 자식 순서 설정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #wrap {
        width: 50%;
        height: 200px;
        border: 4px solid black;
        margin: auto;
        text-align: center;
        display: flex;
      }
      #wrap div {
        width: 33.333%;
      }
      #wrap div:first-child {
        order: 3;
        background: red;
      }
      #wrap div:nth-child(2) {
        order: 2;
        background: green;
      }
      #wrap div:nth-child(3) {
        order: 1;
        background: aqua;
      }
    </style>
  </head>
  <body>
    <div id="wrap">
      <div><h1>1</h1></div>
      <div><h1>2</h1></div>
      <div><h1>3</h1></div>
    </div>
  </body>
</html>

 

실행결과

 

 

 

 

 

 

 

 

 

 

CSS 배치 (2)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #wrap {
        width: 50%;
        height: 200px;
        border: 4px solid black;
        margin: auto;
        text-align: center;
        display: flex;
      }
      #wrap div {
        width: 33.333%;
      }

      .cl01 {
        order: 3;
        background: red;
      }
      .cl02 {
        order: 2;
        background: green;
        display: flex;
      }
      .cl03 {
        order: 1;
        background: aqua;
      }
      .h01 {
        background: lightblue;
        width: 100%;
      }
      .h02 {
        background: lightcoral;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="wrap">
      <div class="cl01"><h1>1</h1></div>
      <div class="cl02">
        <h1 class="h01">첫번째</h1>
        <h1 class="h02">두번째</h1>
      </div>
      <div class="cl03"><h1>3</h1></div>
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS position (1)

position : static : 기본값(위치 조정 불가능)

position: relative : 위치 변경 가능 (상대적)

position: absolute : 페이지를 기준으로 절대 위치 고정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        font-weight: bold;
        font-size: 12pt;
        background: gray;
      }
      .span1 {
        background: yellow;
        position: absolute;
        top: 5px;
      }
      .span2 {
        background: red;
        position: absolute;
        bottom: 30px;
      }
      .span3 {
        background: pink;
        position: absolute;
        top: -5px;
      }
      div {
        background: skyblue;
      }
    </style>
  </head>
  <body>
    <div style="background: green">position</div>
    <span class="span1">span1</span>
    <span class="span2">span2</span>
    <span class="span3">span3</span>
    <div>기본 값은 static 입니다</div>
  </body>
</html>

 

출력 결과

 

 

 

 

 

 

 

 

 

CSS position (2)

position: fixed : absolute는 페이지 기준이지만 fixed는 고정적인 위치이다

z-inex: 번호 : 겹쳐있을 때 위로 올라가게 하는 순서 지정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .sp {
        position: static;
        left: 30px;
        background: cyan;
        width: 400px;
        height: 50px;
      }
      .rp1 {
        position: fixed;
        right: 30px;
        top: 10px;
        background: orange;
        width: 400px;
        height: 50px;
        z-index: 1;
      }
      .rp2 {
        position: absolute;
        right: 60px;
        top: 20px;
        background: lightblue;
        width: 400px;
        height: 50px;
        z-index: 0;
      }
    </style>
  </head>
  <body>
    <p class="sp">정적 위치 설정</p>
    <p class="rp1">고정 위치(fixed)</p>
    <p class="rp2">정적 위치 설정(absolute)</p>

    <p class="sp">정적 위치 설정</p>
    <p class="sp">정적 위치 설정</p>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS position (3)

z-index 설정은 position이 설정되어 있는 상태에서 가능

static은 z-indix 조절되지 않는다

-1은 제일 아래에 놓겠따는 의미(default = 0)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img {
        position: absolute;
        z-index: 3;
        left: 0px;
        top: 0px;
      }
      h1 {
        position: relative;
        z-index: 4;
      }
      p {
        position: fixed;
        z-index: 2;
        left: 0px;
        top: 0px;
        color: blue;
      }
    </style>
  </head>
  <body>
    <h1><a href="#">링크가 달려있어요</a></h1>
    <img src="image.png" width="100px" height="100px" />
    <p>
      <b>z-index 설정은 position이 설정되어 있는 상태에서 가능(static안됨)</b>
    </p>
    <h3 style="margin-top: 100px">
      static는 z-index 조절 되지 않으며, -1은 제일 아래 놓겠다는 의미<br />
      기본값은 0
    </h3>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS 기능 (2)

.클래스명:focus {} : 해당 클래스를 클릭했을때 테두리 설정

.클래스명::-webkit-input-placeholder {} : 해당 클래스에 placeholder 설정

letter-spacing : placeholder간의 간격 설정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #wrap {
        height: 200px;
        width: 200px;
        margin: auto;
        border: 1px solid lightgray;
        padding: 10px;
        border-radius: 20px;
      }
      .id {
        width: 170px;
        height: 20px;
        font-size: 20px;
        border: none;
        border-bottom: 2px solid darkgray;
        margin: 10px 0;
      }
      .id:focus {
        outline: none;
      }
      .id::-webkit-input-placeholder {
        text-align: center;
        letter-spacing: 5px;
      }
      .pwd {
        border-radius: 5px;
        height: 20px;
        margin-bottom: 10px;
      }
      .btn {
        border-radius: 5px;
        width: 200px;
        height: 30px;
        background: lemonchiffon;
      }
    </style>
  </head>
  <body>
    <div id="wrap">
      <h3 style="text-align: center; border-bottom: 1px solid">
        로그인 페이지
      </h3>
      <form>
        <input class="id" type="text" placeholder="input id" /><br />
        <input class="pwd" type="text" placeholder="input password" /><br />
        <input class="btn" type="submit" value="LOGIN" /><br />
      </form>
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

CSS 부트스트랩 적용

* head 태그에 원하는 부트스트랩 링크 설정

* 원하는 태그에 클래스 적용

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
    />
  </head>
  <body>
    <table class="table table-hover">
      <thead>
        <tr>
          <th>국</th>
          <th>영</th>
          <th>수</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>10</td>
          <td>30</td>
          <td>100</td>
        </tr>
        <tr>
          <td colspan="3">
            <button class="btn btn-warning">클릭</button>
          </td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz1

 

풀이과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      header {
        background: red;
        width: 500px;
        height: 100px;
        text-align: center;
        border: 4px solid;
      }
      div {
        display: flex;
      }
      nav {
        background: yellow;
        width: 96px;
        height: 300px;
        text-align: center;
        border: 4px solid;
        position: relative;
        border-right-width: 0px;
      }
      section {
        background: green;
        width: 400px;
        height: 300px;
        text-align: center;
        border: 4px solid;
        position: relative;
      }
      footer {
        background: pink;
        width: 500px;
        height: 80px;
        text-align: center;
        border: 4px solid;
      }
    </style>
  </head>
  <body>
    <header>
      <h1>&lt;header&gt;</h1>
    </header>
    <div>
      <nav>
        <h2>&lt;nav&gt;</h2>
      </nav>
      <section>
        <h2>&lt;section&gt;</h2>
      </section>
    </div>
    <footer>
      <h2>&lt;footer&gt;</h2>
    </footer>
  </body>
</html>

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz02

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      header {
        background: red;
        width: 650px;
        height: 100px;
        text-align: center;
        border: 4px solid;
      }
      div {
        display: flex;
      }
      nav {
        background: yellow;
        width: 100px;
        height: 300px;
        text-align: center;
        border: 4px solid;
        position: relative;
      }
      section {
        background: green;
        width: 400px;
        height: 300px;
        text-align: center;
        border: 4px solid;
        position: relative;
      }
      footer {
        background: pink;
        width: 650px;
        height: 80px;
        text-align: center;
        border: 4px solid;
      }
      aside {
        width: 134px;
        background: yellow;
        border: 4px solid;
        text-align: center;
      }
      section header {
        background: skyblue;
        width: 350px;
        height: 30px;
        text-align: center;
        margin: auto;
        position: relative;
        padding-top: 10px;
      }
      section article {
        background: yellow;
        width: 350px;
        height: 30px;
        text-align: center;
        margin: auto;
        border: 4px solid;
        position: relative;
        top: 30px;
        padding-top: 10px;
      }
      section footer {
        background: pink;
        width: 350px;
        height: 30px;
        text-align: center;
        margin: auto;
        border: 4px solid;
        position: relative;
        top: 60px;
        padding-top: 10px;
      }
    </style>
  </head>
  <body>
    <header>
      <h1>&lt; header &gt;</h1>
    </header>
    <div>
      <nav>
        <h2>nav</h2>
      </nav>
      <section>
        <h2>section1</h2>
        <header>header</header>
        <article>article</article>
        <footer>footer</footer>
      </section>
      <aside>
        <h2>aside</h2>
      </aside>
    </div>
    <footer>
      <h2>&lt; footer &gt;</h2>
    </footer>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz03

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      header {
        background: red;
        width: 500px;
        height: 100px;
        border: 4px solid;
        text-align: center;
      }
      div {
        display: flex;
      }
      nav {
        background: yellow;
        width: 500px;
        height: 80px;
        text-align: center;
        border: 4px solid;
        position: relative;
      }
      section {
        background: green;
        width: 350px;
        height: 300px;
        text-align: center;
        border: 4px solid;
        position: relative;
      }
      footer {
        background: pink;
        width: 500px;
        height: 80px;
        text-align: center;
        border: 4px solid;
      }
      aside {
        background: skyblue;
        width: 142px;
        height: 300px;
        text-align: center;
        border: 4px solid;
      }
      section header {
        background: pink;
        width: 320px;
        height: 25px;
        text-align: center;
        margin: auto;
        position: relative;
      }
      section article {
        background: pink;
        width: 320px;
        height: 25px;
        text-align: center;
        margin: auto;
        border: 4px solid;
        position: relative;
        top: 10px;
      }
      section footer {
        background: pink;
        width: 320px;
        height: 25px;
        text-align: center;
        margin: auto;
        position: relative;
        top: 20px;
      }
    </style>
  </head>
  <body>
      <header>
        <h1>&lt; header &gt;</h1>
      </header>
      <nav>
        <h2>&lt; nav &gt;</h2>
      </nav>
      <div>
        <section>
          <h2>&lt; section1 &gt;</h2>
          <header>&lt; header &gt;</header>
          <article>&lt; article &gt;</article>
          <footer>&lt; footer &gt;</footer>
        </section>
        <aside>
          <h2>&lt; aside &gt;</h2>
        </aside>
      </div>
      <footer>
        <h2>&lt; footer &gt;</h2>
      </footer>
  </body>
</html>

 

실행 결과

 

 

 

'css' 카테고리의 다른 글

CSS 기초  (0) 2024.03.20

 

 

 

 

CSS 선택자 (1)

css 적용방법 : head태그 안에 style태그를 만든다

* {} : 전체 선택자

태그명 {} : 태그 선택자

# 변수명 {} : id 선택자

.클래스명 {} : 클래스 선택자

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        color: red;
        background: yellow;

        b {
          font-size: large;
        }

        #id_txt {
          background: gray;
        }

        .class_txt {
          color: black;
        }
      }
    </style>
  </head>
  <body>
    <dl>
      <dt><b>CSS</b></dt>
      <dd id="id_txt">스타일 시트 표준안</dd>
      <dd class="class_txt">
        웹 문서에 글꼴, 색상, 정렬과 각 태그의 배치 방법 등 디자인 적용
      </dd>

      <dt><b>CSS구성</b></dt>
      <dd>선택자(selector) : 디자인을 적용할 대상 지정</dd>
      <dd>속성 : 어떤 디자인을 설정할지</dd>
      <dd>속성 값 : 속성에서 선택한 디자인을 어떻게 반영할지</dd>
    </dl>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS 선택자 (2)

* id를 부여할 경우 문서내의 유일한 값으로 사용, 문서내에서 동일한 id를 부여 불가능
      * class는 다른 태그에서 사용 가능, 여러개를 동시에 부여 불가능

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #id01 {
        color: red;
      }
      #id02 {
        background: aqua;
      }
      .class01 {
        color: blue;
      }
      .class02 {
        background: aqua;
      }
    </style>
  </head>
  <body>
    <div id="id01" class="class02">
      id를 부여할 경우 문서내의 유일한 값으로 사용<br />
      문서내에서 동일한 id를 부여하면 안된다
    </div>
    <div class="class01 class02">
      class는 다른 태그에서 사용해도 된다<br />
      여러개를 동시에 부여할 수 있다
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS 선택자 활용

.클래스명 태그명 {} : 하위 선택자

.클래스명 > 태그명 {} : 자식 선택자

.클래스명 + 태그명 {} : 인접 선택자

.클래스명 ~ 태그명 {} : 형제 선택자

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box p {
        color: lime;
      }
      .box > p {
        color: orange;
      }
      .box + div {
        background: gray;
      }
      .box ~ p {
        background: green;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <p>1. 하위선택자는 특정 선택자 하위의 모든 요소를 말한다</p>
      <div>
        <p>2. 자식 선택자는 직속 자식 요소를 말한다</p>
      </div>
      <p>3.다음 내용</p>
    </div>

    <div>1. 인접 선택자는 바로 뒤에 나오는 하나의 요소</div>
    <div>2. 인접 선택자는 바로 뒤에 나오는 하나의 요소</div>
    <p>형제 선택자는 같은 계층에 있는 요소에 적용 된다</p>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS hover

태그명:hover {} : 해당 태그에 마우스가 올라가면 변하게 설정

transition: all 1.5s linear 0.5s; : 구현되는 속도를 1.5초, 마우스가 올라간 후 실행까지 0.5초로 지정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 100px;
        color: blue;
        background: green;
        opacity: 0.9;
      }
      div:hover {
        width: 400px;
        height: 50px;
        color: red;
        background: yellow;
        opacity: 0.3;
        transition: all 1.5s linear 0.5s;
      }
    </style>
  </head>
  <body>
    <h2>가상 선택자</h2>
    <div>가상 클래스를 이용한 애니메이션 효과</div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

CSS 기능 (1)

a:link {} : 웹 문서에서 사용자가 방문하지 않았던 곳
a:visited {} : 웹 문서에서 사용자가 방문한 곳
a:hover {} : 포인터가 올라갔을 경우
a:active {} : 클릭이 되는 순간

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      a:link {
        color: green;
        text-decoration: none;
      }
      a:visited {
        color: red;
      }
      a:hover {
        text-decoration: overline;
        color: black;
      }
      a:active {
        background: yellow;
      }
    </style>
  </head>
  <body>
    <a href="#">test</a> &nbsp;
    <a href="https://www.naver.com">naver</a>
    <hr />
    link : 웹 문서에서 사용자가 방문하지 않았던 곳<br />
    visited : 웹 문서에서 사용자가 방문한 곳<br />
    hover : 포인터가 올라갔을 경우<br />
    active : 클릭이 되는 순간<br />
  </body>
</html>

실행 결과

 

 

 

 

 

 

 

 

 

CSS overflow

overflow: hidden; = 상위 블록에서 설정한 값 중 넘쳐나가는 것을 방지

overflow: auto; = 정해진 사이즈에 맞게 맞춰준다. 넘어가게 되면 스크롤로 지정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .div01 {
        overflow: hidden;
        background: blue;
        height: 100px;
      }
      .div01 div {
        background: red;
        width: 200px;
        height: 200px;
      }
      .txt {
        overflow: auto;
        height: 100px;
        width: 100px;
        background: aqua;
      }
    </style>
  </head>
  <body>
    <div class="div01">
      hello
      <div>css</div>
    </div>
    <h1>다음 내용</h1>
    <div class="txt">
      제238조<br />
      회원이 지켜야할 내용이 있다면 지켜주세요<br />
      더이상 내용은 없음<br />
      그래 반갑다<br />
      즐거운 하루 되세요~^^<br />
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS 기능 (2)

margin: auto; = 전체 기준 가운데가 아니라, 부모 블록 기준으로 해당 블록을 가운데로 지정

transform: scale(1.2); : 해당 사진을 1.2배 확대 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img {
        width: 200px;
        height: 200px;
      }
      div {
        background: gainsboro;
        text-align: center;
      }
      .over {
        overflow: hidden;
        margin: auto;
        width: 200px;
        height: 200px;
      }
      img:hover {
        transform: scale(1.2);
        transition: all 1s;
      }
      .h01:hover {
        display: none;
      }
      .h02 {
        display: none;
      }
      .h01:hover + .h02 {
        display: block;
      }
    </style>
  </head>
  <body>
    <div style="height: 200px">
      <h1>Hover Effect</h1>
      <div class="h01"><img src="image.png" /></div>
      <div class="h02"><button>기사</button><button>구독</button></div>
    </div>
    <hr />
    <div>
      <h1>Hover Effect</h1>
      <div class="over">
        aaa<br />
        <img src="image.png" />
      </div>
    </div>
  </body>
</html>

 

실행 결과 

 

 

 

 

 

 

 

 

 

CSS 기능 (3)

justify-content: flex-end; = 블록 끝나는 지점에 지정
border: 1px solid orange; = 실선 박스로 표시
text-decoration: none; = 밑줄 제거

margin: 바깥쪽으로 밀어냄
padding: 안쪽으로 밀어냄

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .nav > ul {
        list-style: none;
        display: flex;
        justify-content: flex-end;
      }
      .nav ul li a {
        text-decoration: none;
        color: white;
      }
      .nav ul li a:hover {
        color: orange;
        border-bottom: 1px solid orange;
        padding-bottom: 5px;
        transition: all 0.25s;
      }
      .nav {
        background-color: black;
      }
      .nav ul li {
        padding: 10px 10px;
      }
    </style>
  </head>
  <body>
    <nav class="nav">
      <ul>
        <li><a href="">HOME</a></li>
        <li><a href="">BOARD</a></li>
        <li><a href="">MEMBERSHIP</a></li>
      </ul>
    </nav>
    <hr />
    display : flex사용시 아래내용 적용 가능<br />
    flex-start : 왼쪽 끝 정렬<br />
    flex-end : 오른쪽 끝 정렬<br />
    space-around : 요소 좌우 동일 간격 정렬<br />
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

CSS 또 다른 사용 방법

<link href="test09.css" rel="stylesheet"> = css파일을 불러오는 방식

px : 해상도에 따라 상대적으로 달라지는 단위
pt : 고정 크기
% : 부모 요소의 크기를 100%기준으로 계산
em : 부모 크기를 100% 기준으로 100분의 1단위

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link href="test09.css" rel="stylesheet" />
  </head>
  <body>
    기본 글자 크기는 16px<br />글자 크기 단위<br />
    - px : 해상도에 따라 상대적으로 달라지는 단위<br />
    - pt : 무조건 고정 크기<br />
    - % : 부모 요소의 크기를 100%기준으로 계산<br />
    - em : 부모 크기를 100% 기준으로 100분의 1단위
    <hr />
    <a href="http://pxtoem.com.au/" target="_blank">단위 변환 사이트</a>
    <div class="px">내용</div>
    <div class="pt">내용</div>
    <hr />
    <div>기본 크기 16px 크기</div>
    <div class="per">부모가 없는 기본 16px의 150% 크기</div>
    <div class="em">부모가 없는 기본 16px의 1.5em 크기</div>
    <div class="px">
      부모 크기 24px
      <div class="px">자식 24px</div>
      <div class="per">자식 150%</div>
      <div class="em">자식 1.5em</div>
    </div>
  </body>
</html>

 

실행결과

 

 

 

 

 

 

 

 

 

CSS 기능 (4)

line-height: 400px; height: 400px; = 동일하면 중앙에 배치

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .font {
        font-weight: bold;
        font-style: italic;
        line-height: 400px;
        height: 400px;
        background: red;
      }
      .color01 {
        color: red;
      }
      .color02 {
        color: blue;
      }
      .color03 {
        color: rgb(255, 100, 255);
      }
      .color04 {
        color: rgba(0, 0, 0, 0.3);
      }
    </style>
  </head>
  <body>
    <div class="color01">색상 확인</div>
    <div class="color02">색상 확인</div>
    <div class="color03">색상 확인</div>
    <div class="color04">색상 확인</div>

    <div>시작</div>
    <div class="font">볼드체</div>
    <div>끝</div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS display

display: inline; = 글자크기만큼 들어온다
display: block; = 블록 크기만큼 들어온다
display: inline-block; = 사이즈가 조정가능하다
display: none; = 숨겨진다

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        background: skyblue;
        display: inline-block;
        width: 200px;
        text-align: center;
      }
      span {
        background: olive;
        display: block;
      }
      .visible:hover ~ .none {
        display: inline;
      }
      .none {
        display: none;
        background: yellowgreen;
      }
    </style>
  </head>
  <body>
    <div>div-01</div>
    <div>div-02</div>
    <span>span-01</span>
    <span>span-02</span>
    <h1 class="visible">마우스를 올려 주세요</h1>
    <h1 class="none">내용</h1>
    즐거운 날~~~~
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

CSS 기능 (5)

vertical-align : 인라인 블록 등을 포함한 모든 인라인요소의 수직 정렬을 위해 사용

display: table-cell; : 요소(td)처럼 표현

border-radius: 10px; = 각진 input창을 둥그렇게 바꿔줌

<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
      .in-block {
        background: orange;
        width: 200px;
        height: 50px;
        display: inline-block;
        line-height: 50px;
        text-align: center;
        text-decoration: none;
      }
      div {
        background: aqua;
        width: 300px;
        height: 300px;
        /*line-height: 100px;*/
        display: table-cell;
        vertical-align: middle;
      }
      label {
        height: 30px;
        background: red;
        width: 100px;
        display: inline-block;
        line-height: 30px;
      }
      input {
        width: 300px;
        height: 30px;
        border-radius: 10px;
      }
    </style>
  </head>
  <body>
    <a href="#" class="in-block">1홈으로 이동</a>
    <a href="#" class="in-block">2홈으로 이동</a>
    <a href="#" class="in-block">3홈으로 이동</a>
    <div>여러줄<br />가운데<br />정령<br />되나요</div>
    <label>아이디 입력</label><input />
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz1

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #main {
        background: gray;
      }
      #warp {
        width: 300px;
      }
      h2:hover ~ #main > h2 {
        color: aqua;
      }
      p:hover {
        background: white;
      }
    </style>
  </head>
  <body>
    <div id="warp" style="width: 300px">
      <h2>오늘의 할 일</h2>
      <div id="main">
        <h2>12월 31일 할 일</h2>
        <ul>
          <b><li>오전 10시</li></b>
          <p>아침밥 먹기</p>
          <b><li>낮 12시</li></b>
          <p>아침밥 먹기</p>
          <b><li>오후 4시</li></b>
          <p>아침밥 먹기</p>
        </ul>
      </div>
    </div>
  </body>
</html>

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz2

풀이 과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 50px;
        background: red;
        text-align: center;
        color: white;
        margin-left: 10px;
        padding-top: 25px;
      }
      div:hover {
        background: gray;
      }
      section {
        background-color: pink;
        width: 450px;
        height: 320px;
        padding-top: 15px;
      }
    </style>
  </head>
  <body>
    <section>
      <div>Home</div>
      <div>Profile</div>
      <div>Board</div>
      <div>Contact</div>
    </section>
  </body>
</html>

실행 결과

'css' 카테고리의 다른 글

CSS 활용  (0) 2024.03.21

 

HTML 기능(1)

<head> : 설정 및 타이틀 지정
<title> : 웹 창 제목

<h1> : 글자 크기 조정 (1 > 2 > ... > 5) (블록)

<p> : 한줄 공백 (블록)

<div> : 영역을 나눌때 사용 (블록)

<span> : 구문 콘텐츠에 스타일이나 속성의 범위를 적용하기 위해 감싸주는 태그 (인라인)

<label> : UI 요소의 라벨을 정의할 때 사용 (인라인)

<body text="white" bgcolor="black"> : 글자색 = 흰색, 배경색 = 검정색으로 지정

<h1 style="background: red;"> : 해당하는 태그에 배경색 지정

* 블록은 새 줄에서 시작하며, 자동으로 앞뒤에 공백을 추가 및 차지

* 인라인은 새 줄에서 시작되지 않으며, 필요한 너비만큼 차지

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body text="white" bgcolor="black">
    https://validator.w3.org
    <h3><span>블럭 태그 안에 인라인 태그 사용</span></h3>
    <span><h3>블럭 태그 안에 인라인 태그 사용</h3></span>
    <hr>
    <h1 style="background: red;">블록 요소</h1>
    <p style="background: beige;">블록 요소</p>
    <div style="background: skyblue;">블록 요소</div>

    <span style="background: silver;">인라인</span>
    <label style="background: aqua;">내용 들어옴</label>
</body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

HTML 기능(2)

<hr> : 주제가 바뀔 때 사용할 수 있는 수평 가로선

<br> : 줄바꿈 역할

<font size = "7"> : 글자 크기 지정 (default = 3)

<font face="궁서체"> : 글자체 지정

<em> : 강조하고 싶은 텍스트. 기울임체
<strong> : 중요한 텍스트, 굵은 글씨
<mark> : 주의 깊게 볼 텍스트, 노란색 표시
<b> : 단순 굵은 글씨
<small> : 주의 사항. 법적 제한, 저작권 등을 정의하는 태그
<sup> : 위첨자
<sub> : 아래첨자

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>문서의 제목(큰수부터 작은수로 작성)</h1>
    <h2>문서내의 작은 숫자를 사용 후 큰수를 사용하지 않음</h2>
    <h3>문서의 제목</h3>
    <h4>문서의 제목</h4>
    <h5>문서의 제목</h5>
    <h6>문서의 제목</h6>

    <hr>

    <font>기본 글자 크기는 size=3</font><br>
    <font size = "7">size = 7</font><br>
    <font size = "6">size = 6</font><br>
    <font size = "5">size = 5</font><br>
    <font size = "4">size = 4</font><br>
    <font size = "3">size = 3</font><br>
    <font size = "2">size = 2</font><br>
    <font size = "1">size = 1</font><br>
    <font face="궁서체" color="blue">궁서체</font>

    <hr>
    <em>강조하고 싶은 텍스트. 기울임체</em>
    <strong>중요한 텍스트, 굵은 글씨</strong>
    <mark>주의 깊게 볼 텍스트, 노란색 표시</mark>
    <b>단순 굵은 글씨</b>
    <small>주의 사항. 법적 제한, 저작권 등을 정의하는 태그</small>
    <sup>위첨자</sup><sub>아래첨자</sub>
</body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

HTML Table

<mark> : 형광펜으로 칠한 것처럼 하이라이트된 텍스트

<table> : 표를 정의할 때 사용하는 태그

<thead> : 테이블의 제목 부분
<tbody> : 테이블의 내용 부분
<tr>, : 하나의 행을 나누기 위한 태그
<th> : 제목 부분을 넣을 때 사용하는 태그 (thead와 함께 사용)
<td> : 내용 부분을 넣을 때 사용 (tbody와 함께 사용)

<table border="10"> : 테이블 테두리선 굵기 지정
<table align="center"> : 테이블을 중앙으로 정렬
<table height="200" width="300" bgcolor="khaki"> : 테이블 사이즈 및 배경색 지정
<td colspan="2"> : 가로 방향으로 병합
<td rowspan="2"> : 세로 방향으로 병합

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>테이블 - 표를 정의할 때 사용하는 태그</h1>
    <mark>테이블 태그</mark>
    <br />
    <p>thead : 테이블의 제목 부분</p>
    <p>tbody : 테이블의 내용 부분</p>
    <p>tr : 하나의 행을 나누기 위한 태그</p>
    <p>th : 제목 부분을 넣을 때 사용하는 태그(thead와 함께 사용)</p>
    <p>td : 내용 부분을 넣을 때 사용(tbody와 함께 사용)</p>
    <hr />
    <table border="1" align="center" height="200" width="300" bgcolor="khaki">
      <thead>
        <tr bgcolor="yellow">
          <th>월</th>
          <th>화</th>
          <th>수</th>
        </tr>
      </thead>
      <tbody>
        <tr height="100" align="right">
          <td width="150">영어</td>
          <td>수학</td>
          <td>국어</td>
        </tr>
        <tr>
          <td>영어</td>
          <td>수학</td>
          <td>국어</td>
        </tr>
      </tbody>
    </table>

    <hr />

    <table border="1">
      <tr>
        <td colspan="2">111</td>
        <td>333</td>
      </tr>
      <tr>
        <td rowspan="2">111</td>
        <td>222</td>
        <td>333</td>
      </tr>
      <tr>
        <td>111</td>
        <td>333</td>
      </tr>
    </table>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

HTML 기능(3) 및 List

<pre> : 미리 정의된 형식의 텍스트를 정의

noshade : 음영 효과 제거

<a href="http://www.naver.com"> : 이동하고자 하는 경로
<a href="http://www.naver.com" target="_blank"> : 새탭으로 열린다
<a href="http://www.naver.com" title="네이버 이동"> : 마우스를 가져가면 설명내용
<a href="mailto:xodud5080@naver.com"> : 메일도 가능

<img src="image1.png" alt="이미지를 불러올 수 없음"> : 이미지가 없을때 대체말

* a태그 안에 img태그 사용 가능

<ol> : 순서가 있는 리스트
<ul> : 순서가 없는 리스트

<li> : 리스트 나열 뿐만 아니라 메뉴등을 만들때도 사용

<dl> : 용어와 그에 대한 설명을 리스트 형식으로 정의

    <dt> : dl태그에 대한 제목
    <dd> : dl태그에 대한 내용

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <pre>
    공백을      넣오세요 
        아무    거  나      숑
    </pre>

    <hr />
    두께
    <hr size="10" />
    음영효과
    <hr size="10" noshade />
    길이, 색, 위치
    <hr width="50%" align="center" color="red" />
    <hr width="300px" align="center" />
    <p align="center" style="background: blue">내용</p>
    <div align="right" style="background: red">내용</div>
    <label align="center" style="background: green">내용</label>

    <h3>a 태그</h3>
    - 다른 문서로 이동하거나 이메일 주소에 링크를 지정<br />
    - 블록, 인라인 요소를 포함할 수 있다<br />
    - 단, 다른 링크로 연결되는 태그를 포함할 수 없다(&lt;a&gt; &lt;button&gt;
    등)<br />
    - 속성 <br />
    - href : 이동하고자 하는 경로<br />
    - target : _blank를 사용하여 새탭으로 페이지를 열어준다<br />
    - title : 마우스를 올렸을 경우의 내용 표현<br />
    <a href="http://www.naver.com" target="_blank">네이버</a><br />
    <a href="http://www.naver.com" title="네이버 이동">네이버</a><br />
    <a href="mailto:xodud5080@naver.com">xodud메일 쓰기</a>
    <hr />
    <h3>img</h3>
    - src속성에 이미지의 경로<br />
    - alt속성은 이미지를 참지 못하는 경우 설명으로 대체<br />
    - <strong>alt 속성은 필수 항목이다</strong>
    <hr />
    <img src="image.png" width="150px" height="150px" border="10" /> <br />
    <img
      src="image1.png"
      alt="이미지를 불러올 수 없음"
      width="150px"
      height="150px"
      border="10"
    />
    <br />
    <a href="http://www.naver.com" title="네이버 홈피 이동">
      <img src="image.png" width="150px" height="150px" border="10" />
    </a>
    <hr />
    <ol type="i">
      <li>aaaa</li>
      <li>aaaa</li>
      <li>aaaa</li>
    </ol>
    <ul>
      <li>aaaa</li>
      <li>aaaa</li>
      <li>aaaa</li>
    </ul>
    <hr />
    <ul>
      <li>
        <b>교육과정</b>
        <ol>
          <li><a href="#">HTML</a></li>
          <li><a href="#">CSS</a></li>
          <li><a href="#">JAVASCRIPT</a></li>
        </ol>
      </li>
    </ul>

    <dl>
      <dt><b>HTTP</b></dt>
      <dd>HTML를 전달한느 프로토콜.<br />URL은 "http://도메인 주소"로 사용</dd>
    </dl>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

HTML Input

<input> : 사용자로부터 입력을 받을 수 있는 입력 필드를 정의

    type : 태그 종류 지정
    value : 직접 값을 넣어줌
    placeholder : 반투명 값을 넣어줌
    name : radio타입에서 하나로 묶어주는 역할, 변수 역할

* reset, submit은 form태그 안에 있으면 작동한다

<textarea> : 여러 줄의 텍스트를 입력할 수 있는 텍스트 입력 영역을 정의

<fieldset> : 테두리를 만들어줌
    legend : fieldset 태그에서 제목 역할
<select> : 선택 창 
    size : select 태그에서 한번에 몇개를 보여줄지 지정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h3>input</h3>
    <input type="button" value="버튼" /><br />
    <input type="submit" value="서브밋" /><br />
    <input type="reset" value="리셋" /><br />
    <input type="image" src="image.png" width="50" alt="???" /><br />
    <input type="file" /><br />
    <hr />
    <input type="text" value="내용 입력" size="10" maxlength="7" /><br />
    <input type="password" placeholder="input password" /><br />
    <input type="email" placeholder="ex@co.kr" /><br />
    <input type="search" value="갑 입력 시 x버튼 활성화" /><br />
    <input type="tel" value="010-1234-1234" /><br />
    <input type="number" min="1" max="10" /><br />
    <hr />
    <input type="color" /><br />
    <input type="range" /><br />
    <input type="radio" /><br />
    <input type="checkbox" /><br />
    <input type="hidden" value="내용 숨김" /><br />

    <hr />
    10대 <input type="radio" name="age" /> 20대
    <input type="radio" name="age" checked /> 30대
    <input type="radio" name="age" /> 40대 <input type="radio" name="age" />
    <hr />
    첵1<input type="checkbox" checked /> 첵2<input type="checkbox" checked />
    첵3<input type="checkbox" checked />
    <hr />
    <form>
      <input type="text" placeholder="input name" /><br />
      <input type="text" placeholder="input address" /><br />
      <textarea rows="6" cols="50"></textarea><br />
      <fieldset style="width: 200px">
        <legend>취미 조사</legend>
        <input id="id" /><br />

        <label for="h1">책 읽기</label>
        <input type="checkbox" id="h1" />
        <label>멍 타기</label>
        <input type="checkbox" /><br />

        <label for="id">아이디 입력</label>
      </fieldset>
      <select size="1" name="test_5">
        <option selected>사과</option>
        <option>배</option>
        <option>복숭아</option>
      </select>
      <input type="reset" value="초기화" />
      <input type="submit" value="전송" />
      <input type="button" value="버튼" />
    </form>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Get : 입력한 내용을 경로와 함께 넘기는 방식 (URL뒤에 파라미터를 붙여서 전달)
Post : HTTP Body에 담아서 데이터 전송, 많은 양, 보안상 우위

required : form태그 안 input태그 안 공백시 알림창
pattern : form태그 안 input태그 안 양식 지정, 어길시 알림창
readonly : form태그 안 input태그 안 읽기전용 창
disabled : form태그 안 input태그 안 비활성화

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form action="ex06.html">
      <input
        type="text"
        name="test_id"
        placeholder="아이디 입력"
        required
      /><br />
      <input
        type="tel"
        placeholder="ex) 010-xxxx-xxxx"
        pattern="\d{3}-\d{4}-\d{4}"
        name="test_num"
        required
      /><br />
      <input type="text" readonly value="쓸 수 없습니다." /><br />
      <input type="submit" value="전송" /><br />
      <input type="button" value="버튼" disabled />
      <button type="button">버튼</button>
    </form>
    <hr />
    <div style="background-color: pink">웹 브라우저 전체 공간에 대해 분할</div>
    <div style="background-color: skyblue">블록(block)형식으로 분할</div>
    <hr />
    <span style="background-color: peru">웹 브라우저의 일부 영역만 분할</span>
    <span style="background-color: tan">인라인(inline) 형식으로 분할</span>
    <div style="background-color: hotpink">
      div영역
      <span style="background-color: peru">span 첫 번째 영역</span> div영역
      <span style="background-color: red">span 두 번째 영역</span>
    </div>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

HTML 영역(1)

header : 헤더 영역 (제목, 네비게이션, 검색)
section : 유형, 주제 별 그룹 (h2 ~ h6 많이 쓰임)
footer : 바닥글, 저작권, 작성자
nav : 메인 메뉴, 목차
article : 독립적인 뉴스기사, 블로그
aside : 프로젝트와 관련 없는 광고, 왼쪽 또는 오른쪽에 배치

<audio> : 오디오 관련 태그

<video> : 비디오 관련 태그

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <h1>주 제목이 들어온다</h1>
      <div>
        <a href="#">공지사항</a>
        <a href="#">회사소개</a>
        <a href="#">이벤트</a>
      </div>
    </div>
    <div>
      <section>
        특정 컨텐츠 영역 : 웹 페이지로 보여줄 하나의 정보 덩어리
      </section>
      <div>특정 컨텐츠 영역 : 웹 페이지로 보여줄 하나의 정보 덩어리</div>
      <article>주요기사 : 오른쪽 또는 왼쪽 영역에 배치</article>
      <aside>광고 : 오른쪽 또는 왼쪽에 배치</aside>
    </div>
    <footer>
      <address>서울 특별시 / 010-1234-1234</address>
      <b><i>&copy;</i></b
      >test.com
    </footer>
    <hr />
    <h3>오디오 재생</h3>
    <audio src="" controls loop autoplay></audio>
    <h3>비디오 재생</h3>
    <video src="" muted="muted" loop autoplay width="300" height="300"></video>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

HTML 영역(2)

href = "#top" : 맨 위로 이동

&nbsp; : 공백 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <header style="background: red">
      <h2>&lt; 책갈피 기능 &gt;</h2>
      <nav>
        <a href="#user">[이름]</a> &nbsp; &nbsp;
        <a href="#user1">[이름1]</a> &nbsp; &nbsp;
        <a href="#user2">[이름2]</a> &nbsp; &nbsp;
      </nav>
    </header>
    <section>
      <p>이름</p>
      <a name="user">이름 이동</a>
      <a href="#top">top 이동</a>
      <hr />
      <p>이름</p>
      <a name="user1">이름1111 이동</a>
      <a href="#top">top 이동</a>
      <hr />
      <p>이름</p>
      <a name="user2">이름2222 이동</a>
      <a href="#top">top 이동</a>
      <hr />
    </section>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz1

풀이 과정(1)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>table/tr/td/th 태그</title>
  </head>
  <body>
    <form action="company.html">
      <table>
        <tr>
          <td colspan="2">
            다음
            <span style="background-color: peru"><b>내용에 맞게 입력</b></span>
            하시오.
          </td>
          <td rowspan="5">
            <img src="test.jpg" width="200px" height="150px" />
          </td>
        </tr>

        <tr>
          <td colspan="2">
            <label>전공 분야를 입력하세요.</label>
            <select size="1" name="test_5">
              <option value="Software">소프트웨어</option>
              <option value="Robot">로봇</option>
              <option value="System">시스템</option>
              <option value="Service">서비스</option>
              <option value="Education">교육</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>이름</td>
          <td><input type="text" /></td>
        </tr>
        <tr>
          <td>아이디</td>
          <td><input type="text" /></td>
        </tr>
        <tr>
          <td>비밀번호</td>
          <td><input type="text" /></td>
        </tr>
        <tr>
          <td colspan="3">
            <fieldset style="width: 500">
              <legend>성별 조사</legend>
              여성 <input type="radio" name="gender" checked /> 남성
              <input type="radio" name="gender" />
            </fieldset>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <fieldset style="width: 500">
              <legend>취미 조사</legend>
              책읽기 <input type="checkbox" /> 공부하기
              <input type="checkbox" /> 책 읽으며 공부하기
              <input type="checkbox" /> 컴퓨터 <input type="checkbox" />
            </fieldset>
          </td>
        </tr>

        <tr>
          <td colspan="3">
            <fieldset style="width: 500">
              <legend>하고 싶은 말</legend>
              <textarea name="test_6" rows="3" cols="60"></textarea>
            </fieldset>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <input type="submit" value="완료" /><input
              type="reset"
              value="다시작성"
            />
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>

풀이 과정(2)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>table/tr/td/th 태그</title>
  </head>
  <body bgcolor="skyblue">
    <h1>HTML 연습<br /></h1>
    <table align="center" bgcolor="khaki" width="700">
      <tr>
        <th colspan="3">
          <font size="7" color="blue" face="궁서">회사 소개</font>
          <hr color="hotpink" align="center" width="300" />
        </th>
      </tr>
      <tr>
        <td width="200">
          <ul>
            <li><a href="#">네이버</a></li>

            <li><a href="#">구글</a></li>

            <li><a href="#">다음</a></li>
          </ul>
        </td>
        <td>
          <h3>
            <dl>
              <dt><font size="5">-회사소개-</font></dt>
              <dd>
                <i>
                  <p>안녕하세요</p>
                  <p>HTML 회사 입니다</p>
                  환영 합니다.
                </i>
              </dd>
            </dl>
          </h3>
        </td>
        <td align="right">
          <a href="#" title="naver연결">
            <img src="test.png" width="100" height="100" />
          </a>
        </td>
      </tr>
      <tr>
        <td colspan="3">
          <small>
            회사소개 · 광고안내 · 검색등록 · 제휴문의 · 인재채용 · 서비스약관 ·
            청소년보호 정책 · 개인 정보처리방침 · 웹접근성안내 · 고객센터
            <b
              ><em>Copyright &copy; CARE LAB. All rights reserved.</em></b
            ></small
          >
        </td>
      </tr>
    </table>
  </body>
</html>

풀이 과정(3)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>table/tr/td/th 태그</title>
  </head>
  <body>
    <table border="1" align="center">
      <thead>
        <tr>
          <th colspan="5">IT 시간표</th>
        </tr>

        <tr>
          <th></th>
          <th>401호</th>
          <th>402호</th>
          <th>403호</th>
          <th>404호</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><b>09:00-12:00</b></td>
          <th rowspan="4">공<br />사<br />중</th>
          <td>PYTHON 기 초</td>
          <td rowspan="2">네트워크보안<br />실무자 양성</td>
          <td>
            보충훈련 과정<br />
            (OS/네트워크)
          </td>
        </tr>
        <tr>
          <td><b>12:30-15:30</b></td>
          <td>JAVA</td>
          <td>보충훈련 과정<br />(언어계열)</td>
        </tr>
        <tr>
          <td><b>15:30-18:30</b></td>
          <td>C언어</td>
          <td rowspan="2">
            가상화 시스템<br />
            엔지니어 실무자 양성
          </td>
          <td>리눅스</td>
        </tr>
        <tr>
          <td><b>19:00-22:00</b></td>
          <td>PYTHON_WEB</td>
          <td>서버</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

 

실행 결과

 

 

 

 

 

 

 

 

 

 

Quiz2

풀이과정

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Insert title here</title>
  </head>
  <body>
    <div style="width: 800px">
      <header>
        <h2 align="center" style="color: pink">B &nbsp; l &nbsp; o &nbsp; g</h2>
      </header>
      <nav>
        <hr />
        <span style="color: green"><b>전체</b></span> &nbsp; 인테리어 &nbsp;
        어학 &nbsp; 자동차 &nbsp; 만화
        <hr />
      </nav>
      <section>
        <article style="float: right">
          <video
            src="resources/media/video.m4v"
            controls
            loop
            autoplay
            width="300"
            height="200"
          ></video>
        </article>
        <article>
          <table border="0">
            <tr>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test1.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test2.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test3.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test4.jpg"
                />
              </td>
            </tr>
            <tr>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test5.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test6.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test7.jpg"
                />
              </td>
              <td>
                <img
                  width="100px"
                  height="100px"
                  src="resources/images/test8.jpg"
                />
              </td>
            </tr>
            <tr>
              <td colspan="4"><a href="#top">[위로 이동]</a></td>
            </tr>
          </table>
        </article>
        <br />
        <hr />
        <article>
          <div style="float: right">
            <img
              width="100px"
              height="100px"
              src="resources/images/맛집01.jpg"
            />
          </div>
          <div>
            id : 컴퓨터<br />
            <h3>겨울 제주도 여행 천백고지 부터 우도맛집 총정리!</h3>
            <p>
              안녕하세요!! 제주도 여행 정말 즐거웠습니다. 겨울 제주도 여행을
              12월쯤에 다녀 왔습니다.!! 내년에 또 다녀 오겠습니다.!!!^^<br /><br />
              <a href="#top">[위로 이동]</a>
            </p>
          </div>
        </article>
        <hr />
      </section>
      <footer>
        <small>
          &nbsp;&nbsp;
          <span style="color: green"
            ><i><b>CARE LAB</b></i></span
          ><i> Copyright &copy; AllRights Reserved</i> &nbsp;&nbsp; &nbsp;&nbsp;
          &reg; 1999 | 회사소개 | TEL : 777-777
        </small>
      </footer>
    </div>
  </body>
</html>

 

실행 결과

 

+ Recent posts