SyntaxHighlighter.all(); 게을러지고 싶어 부지런한 개발자 :: 게을러지고 싶어 부지런한 개발자

https://www.w3schools.com/jquery/default.asp  

이 사이트서 jQuery Tutorial을 공부한 뒤 메소드명과 정의에 대해서만 정의하고자 함 

- 각 메소드를 사용하는 예제소스는 https://www.w3schools.com/jquery/jquery_examples.asp 이곳에 가서 찾아볼 것 

 

jQuery란?  

- 자바스크립트 라이브러리

 

jQuery 사용방법

- 직접 다운로드 (https://jquery.com/download/)  또는 CDN 사용 

- 나는 구글에서 제공하는 CDN을 사용하기 위해 아래 태그를 추가함 

 

==========================================================

 

<< 정리 순서 >> 

1. jQuery Selectors

2. jQuery Events 

-click, dbclick, mouseenter, mouseleave, mousedown, mouseup, hover, keypress, keydown, keyup, submit,change, focus, blur, scroll, resize

3. jQuery Effects

-hide, show, toggle, fadeIn, fadeOut, fateToggle, fadeTo, slideDown, slideUp, slideToggle

4. jQuery HTML & CSS 관련 효과 

-text, html, val, attr, append, prepent, attr, before, remove, empty, addClass, removeClass, toggleClass, css, width, height, innerWidth, innerHeight, outerWidth, outerHeight

5. jQeury Traversing 

-parent, parents, parentsUtil, children, find, siblings, next, nextAll, nextUntil, prev, prevAll, prevUntil, first, last, eq, filter, not 

 

 

1. jQuery Selectors 

https://www.w3schools.com/jquery/jquery_ref_selectors.asp

selectors reference 모음집이다. 여기를 들어가서 확인해보는게 빠름! 

 

jQuery Selectors

jQuery Selectors jQuery Selectors Use our jQuery Selector Tester to demonstrate the different selectors. Selector Example Selects * $("*") All elements #id $("#lastname") The element with id="lastname" .class $(".intro") All elements with class="intro" .cl

www.w3schools.com

2. jQuery Events 

브라우저가 사용자의 행동에 따라 반응할 수 있도록 하는 것 

Mouse Events Keyboard Events Form Events Document/Window Events 
click() : 마우스 클릭시  keypress(): 키보드 키 누르면 submit(): 폼태그 input 정보를 submit 할 때  scroll(): 화면을 스크롤 할 때
dbclick(): 마우스 더블클릭 keydown(): 키보드 키 눌러져있는 상태일 때  change(): input정보를 변경후 마우스 커서를 input 밖으로 클릭시 resize(): 화면의 크키를 변경할 때 

mouseenter(): 마우스 가져다댈 때 

keyup(): 키보드 키 눌러져있다가 때어졌을 때  focus(): input태그안에 마우스 클릭시 (예시있음)   
mouseleave(): 마우스 가져다댄 뒤 땠을 때   blur(): input태그안에 마우스 클릭후 땠을때 (예시있음)  
mousedown(): 마우스 가져다댄 뒤 마우스 클릭시      
mouseup(): 마우스 가져다댄 뒤 마우스 클릭하고 땔 때      

hover(): mouseenter & mouseleave의 효과를 함께 낼 수 있음 (예시있음) 

     

hover() 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("#p1").hover(function(){
    alert("You entered p1!");
  },
  function(){
    alert("Bye! You now leave p1!");
  }); 
});
</script>
</head>
<body>
<p id="p1">This is a paragraph.</p>
</body>
</html>

 

focus() & blur() 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("input").focus(function(){
    $(this).css("background-color""yellow");
  });
  $("input").blur(function(){
    $(this).css("background-color""green");
  });
});
</script>
</head>
<body>
 
Name: <input type="text" name="fullname"><br>
Email: <input type="text" name="email">
 
</body>
</html>

on ()  : 

-선택한 요소에 대해 한 개 이상의 이벤트 헨들러 등록 원할 때 사용 

$("p").on("click", function(){
  $(this).hide();
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("p").on({
    mouseenter: function(){
      $(this).css("background-color""lightgray");
    },  
    mouseleave: function(){
      $(this).css("background-color""lightblue");
    }, 
    click: function(){
      $(this).css("background-color""yellow");
    }  
  });
});
</script>
</head>
<body>
<p>Click or move the mouse pointer over this paragraph.</p>
</body>
</html>

 

3. jQuery Effects

Hide/Show

* $(selector).hide() : 숨겨버림 (태그도 없애므로 공간도 사라짐)                                               
- $(selector).hide(speed) : speed("slow"/"fast/"/ milliseconds ex)1000)

* $(selector).show() : 숨겨진 요소를 다시 보이도록                                 
-$(selector).show(speed)  : speed("slow"/"fast/"/ milliseconds)     

* $(selector).toggle() : 클릭시 보여주기 & 또다시 클릭시 숨기기 왔다갔다 (예시있음)
-$(selector).toggle(speed)  : speed("slow"/"fast/"/ milliseconds)   

Fade

* $(selector).fadeIn() : 선택한 요소 나타나도록                                                             
 - $(selector).fadeIn(speed)  : speed("slow"/"fast/"/ milliseconds) 
 

$(selector).fadeOut() : 선택한 요소 사라지도록 
- $(selector).fadeOut(speed)  : speed("slow"/"fast/"/ milliseconds)

* $(selector).fadeToggle() : 선택한 요소 사라지기(fadeOut) & 나타나기(fadeIn) 반복
-
$(selector).fadeToggle(speed)  : speed("slow"/"fast/"/ milliseconds)

* $(selector).fadeTo(speed, opacity) : 투명도를 유지한채로 fadeOut 됨 (예시있음) 
(speed : "slow"/"fast/"/ milliseconds )   (opacity : 0~1까지의 투명도. 0에 가까울수록 투명함)

Slide

* $(selector).slideDown() 선택한 요소 슬라이드 하며 내려오도록                                                 
- $(selector).slideDown(speed, callback)  : speed("slow"/"fast/"/ milliseconds)

* $(selector).slideUp()선택한 요소 슬라이드 하며 올라가도록   
- $(selector).slideUp(speed, callback)  : speed("slow"/"fast/"/ milliseconds)

* $(selector).slideToggle() : 선택한 요소 slideDown과 slideUp 반복 
- $(selector).slideToggle(speed)  : speed("slow"/"fast/"/ milliseconds)

Animate

* $(selector).animate({params}, speed) : css속성을 움직이게 하는 등 여러 애니메이션 효과를 줌      

< animate()으로 가능한 기능들 > (각자 예시 있음)   

 - 하나의 css 속성만 animate 시킴

 - 하나이상의 css 속성 동시에 animate 시킴

 - 하나이상의 css 속성 순서에 맞춰(하나 다음에 하나실행) animate 시킴 

Stop

* $(selector).stop() : effes 또는 animation이 끝나기전, 그 해당 효과를 멈추게 함

(ex. 슬라이딩 되는 효과 도중에 슬라이딩 효과를 멈추게 하는 것) 

$(document).ready(function(){
    $("#flip").click(function(){
       $("#panel").slideDown(5000);
    });
    $("#stop").click(function(){
       $("#panel").stop();
    });
});

Callback

Callback: 현재 effect가 끝난 다음에서야 다음 function이 실행됨 (아래예시: hide효과먼저, 그 다음 alert)

1
2
3
4
5
6
7
$("button").click(function(){
  $("p").hide("slow"function(){
    alert("The paragraph is now hidden");
  });
});

Non-callback : 원치않는 순서로 나올 수 있다는 단점  (아래예시: alert 먼저, 그 다음 hide효과) 

1
2
3
4
5
$("button").click(function(){
  $("p").hide(1000);
  alert("The paragraph is now hidden");
});
Chaining

한 번에 여러 메소드들 체인처럼 연결해서 사용 가능 

ex)   $("#p1").css("color", "red").slideUp(2000).slideDown(2000);

혹은 이런 방식의 format도 가능하다..
$("#p1").css("color", "red")
  .slideUp(2000)
  .slideDown(2000);

 

toggle() 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").toggle();
  });
});
</script>
</head>
<body>
<button>Toggle between hiding and showing the paragraphs</button>
 
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</body>
</html>

 

toggleTo() 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").fadeTo("slow"0.15);
    $("#div2").fadeTo("slow"0.4);
    $("#div3").fadeTo("slow"0.7);
  });
});
</script>
</head>
<body>
 
<p>Demonstrate fadeTo() with different parameters.</p>
 
<button>Click to fade boxes</button><br><br>
 
<div id="div1" style="width:80px;height:80px;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>
 
</body>
</html>

 

animate() 예시  : 하나의 css 속성만 animate 시킴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function(){
  $("button").click(function(){
    
$("button").click(function(){
    $("div").animate({left: '250px'});
  });
});
</script>
</head>
<body>
 
<p>Demonstrate fadeTo() with different parameters.</p>
 
<button>Click to fade boxes</button><br><br>

<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>

<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
 
</body>
</html>

 

animate() 예시  : 하나이상의 css 속성 동시에 animate 시킴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({
      left: '250px',
      opacity: '0.5',
      height: '150px',
      width: '150px'
    });
  });
});
</script> 
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, 
remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
 
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>

 

animate() 예시  : 하나이상의 css 속성 순서에 맞춰(하나 다음에 하나실행) animate 시킴 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
<head>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    var div = $("div");
    div.animate({height: '300px', opacity: '0.4'}, "slow");
    div.animate({width: '300px', opacity: '0.8'}, "slow");
    div.animate({height: '100px', opacity: '0.4'}, "slow");
    div.animate({width: '100px', opacity: '0.8'}, "slow");
  });
});
</script> 
</head>
<body>
 
<button>Start Animation</button>
 
<p>By default, all HTML elements have a static position, and cannot be moved. 
To manipulate the position, remember to first set the CSS position property 
of the element to relative, fixed, or absolute!</p>
 
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>

 

4. jQuery HTML (DOM manipulation)& CSS 관련 효과

HTML

Get/Set

text() : html안의 텍스트글자만 그대로 get
text("내용") : html안의 텍스트글자만 그대로 set

html() : html안의 텍스트글자 그대로 get (with HTML markup)
html("<b>내용</b>") : "내용" 글자를 set

val() : form의 input 필드의 값 get
val("내용") : form의 input 필드의 값 set

attr("속성") : 속성의 값 get
  ex) alert($("#w3s").attr("href"));
attr("속성", "바꾸려는 값") : 속성의 값 set  ( {}형식으로 여러개 set도 가능) 
  ex) $("w3s").attr("href", "http://naver.com");    <-- 기존의 href속성 가진 요소의 값이 w3school.com였다면... 이 값을 naver.com로 변경 
==================================================
text(), html, val 셋 다 callback 함수로도 쓰임가능. 이럴 땐 파라미터 2개 들어감

ex)   (i는 index, orgText는 기존 쓰여있던 텍스트) 
 $("#btn1").click(function(){
      $("#test1").text(function(i, origText){
         return "Old text: " + origText + " New text: Hello world! (index: " + i + ")"; 
      });
  });

Add

$(selector).append("해당 요소")  : selector를 해당 요소 맨 마지막에 붙임
ex) $("p").append("<b>Appended text.</b>");

$(selector).prepend("해당 요소") : selector를 해당 요소 맨 앞에 붙임 

$(selector).after("해당 요소") selector를 해당 요소 바로 다음에 붙임 

$(selector).before("해당 요소") selector를 해당 요소 바로 이전에 붙임 

Remove

remove() : 공간과 함께 선택한 요소 없애기
remove("요소선택") : 없앨 요소를 filter해서 지움
ex) $("p").remove(".test");   <-- <p>태그를 가진 요소 중 class명이 test인 요소 지우기 
ex) $("p").remove(".test, .test2"); <--<p>태그 가진 요소 중 class명이 test, test2인 요소 지우기 

empty() : 공간은 남기고 내용(text)만 없애기 (즉, 자식요소만 없앰)

CSS CSS Classes

addClass("클래스명") : 클래스명 넣음으로써 클래스 추가 

removeClass("클래스명") : 빼려는 클래스명 쓰기 

toggleClass("클래스명") : addClass & removeClass 번갈아가면서 

CSS()

<여러 역할>

1) css("속성명") :  CSS 속성 반환 받음(get)  

2) css("속성명", "속성값") : 하나의 CSS 속성 변경(set)
3) css({"속성명": "속성값", "속성명": "속성값", "속성명": "속성값", ...}) :여러개의 CSS속성 설정 

Dimensions 

width() / height() : element만 포함된 width/height 가져옴(get)
( 괄호 안에 ex. 100px 넣으면 width/height를 해당 사이즈 픽셀로 set 하는거)

innerWidth() / innerHeight() : padding 포함 (ex. innerWidth = width + padding) 

outerWidth() / outerHeight() : padding & border 포함된 width/height 가져옴

outerWidth(true) / outerHeight(true)padding & border & margin 포함된 width/height 가져옴(get) 

 

5. jQuery Traversing

 

Ancestors

parent() :direct 부모 선택

parents() : 자신 위 모두 선택

parentsUtil(): 선택요소부터 다음 선택요소까지 다 선택(아래 ex: span태그부터 div태그 직전까지 모두 선택)

1
$("span").parentsUntil("div");
Descendants

children() : direct 자식 선택
children("선택") : direct 자식 중에서 또다시 특정 자식 선택할 수있음 
(ex. $("div").children("p.first");

find("선택") :  자신의 자식들 중 선택요소에 해당하는 것 모두 선택 
find("*") :  자신의 자식 모두 선택 

(ex. $("div").find("span");  <-- returns all <span> elements that are descendants of <div> ) 

Siblings

(동일한

부모를 공유)

siblings() :동일한 부모를 가진 모든 siblings 선택 
siblings("선택") : 동일한 부모를 가진 모든 siblings 중에서 또다시 특정 siblings 선택 

next() : next sibling 선택 

nextAll() : all next siblings 선택 

nextUntil() : all next sibling between two given elements 선택
ex) $("h2").nextUntil("h6").css({"color": "red", "border": "2px solid red"});
--> h1부터 h6가 있다고 치면 h3, h4, h5가 선택됨 

prev() : next()의 반대 

prevAll()nextAll()의 반대 

prevUntil() nnextUntilext()의 반대 

Filtering

first() : 1st element of the specified elements (
ex) $("div").first().css("background-color", "yellow");  <-- div 태그들 중 첫 번째 div태그(및 하위요소)선택
 

last() : last element of the specified elements

eq(인덱스) : element with a specific index number of the selected elements
 ex) $("p").eq(1).css("background-color", "yellow");   <-- p 태그들 중 1번쨰 인덱스 요소 선택 


filter() : () <- 요 안에 넣은 요소에 해당하는 태그들 선택 
ex) $("p").filter(".intro").css("background-color", "yellow");  <-- p태그 중에서 class명이 intro인 요소 모두선택
 

not() : filter의 반대 

6. jQuery AJAX

*형식:  $.ajax({name : value, name : value, name : value, ...});

*name 종류: (밑줄 친게 자주 쓰이는 속성) 

-async, beforeSend, cache, complete, contentType, context, data, dataFilter, dataType, error, global, password, processData, scriptCharset, success, timeout, traditional, type, url, username, xhr

이클립스 상단에 Window > Preferences > "encoding"이라고 아래와같이 쳐보자 (왼쪽 상단에 typing)

 

 진한 글씨로 된 곳에 모두 UTF-8로 지정하면 됨 

 

( Content Types > Java Class File > Default encoding 란에 "UTF-8" 입력 > Update)

( Content Types > Text > Default encoding 란에 "UTF-8" 입력 > Update)

( Workspace > 아래 쪽에 Text file encoding타입 "UTF-8" 선택 ) 

(나머지  Web과 관련된 Files 들: 클릭 > Encoding > "UTF-8" 선택 ) 

글꼴 및 폰트 사이즈 관련 속성 

*font-family: 글꼴

  -여러 개 넣을 수 있는데, 제일 첫번째 지정한 폰트를 쓰되, 만약 컴퓨터에 해당 글꼴이 없으면 다음번 지정한 글꼴을 찾아 지정. 모두 없다면 디폴트 서체로 지정됨. 

*font-size: 글꼴의 크기 

*font-style: 이탈릭체 등 스타일 속성 

*font-weight: 글꼴 굵기;   bold(굵게), normal(보통), lighter(얇게), 또는 직접 굵기를 숫자로 지정 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>font-family 사용예제</title>
    <style>
        div {
            width:800px;
            margin:0 auto;
            padding:20px;
        }
 
        div:nth-child(1) {       
            font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        }
 
        div:nth-child(2) {
            font-family:MingLiU_HKSCS-ExtB;
        }
 
        div:nth-child(3) {
            font-family:'MingLiU_HKSCS-ExtB';
            font-size:32px;
        }
 
        div:nth-child(4) {
            font-family:'Bernard MT';
            font-size:1.0em;
        }
    </style>
</head>
<body>
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
</body>
</html>
 

line-height

-텍스트 가운데 세로 정렬 

-박스의 세로 길이와 동일하게 line-height 지정해야 함 

글자에 대한 정렬과 간단한 글꼴모양의 속성 

- text-align: 글자를 어느 위치에 정렬할지 (left, center, right) 

- text-decoration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>text-align, text-decoration 사용예제</title>
    <style>
       div {
           width:800px;
           margin:0 auto;
           overflow:hidden;
           border:1px solid #cccccc;
           padding:10px;
           box-sizing:border-box;
       }
 
       div p:nth-child(1) {
           font-size:2.0em;
           text-align : center;
           height:100px;
           line-height:100px;
           text-decoration:underline;
       }
 
       div p:nth-child(2) {
           font-size:1.2em;
           text-align : left;
       }
 
       div p:nth-child(4) {
           font-size:1.2em;
           text-align : right;
       }
 
       div p:nth-child(6) {
           height:50px;
           line-height:50px;
           font-size:1.5em;
           text-align : center;
       }
 
       div p:nth-child(6) a {
           text-decoration:none;
       }
 
    </style>
</head>
<body>
    <div>
        <p>HTML5, CSS3 Document</p>
        <p>To. all member</p>
        <p>재미있게 HTML5과 CSS3를 배워봅시다!!아자아자아자아</p>
        <p>From. 누구누구</p>
        <hr />
        <p><a href="http://naver.com target="_blank">네이버로 이동</a></p>
    </div>
</body>
</html>

position

- 태그요소의 위치를 설정해주는 요소 

 

1) position: absolute  : 자신을 직접 감싸고 있는 상하,좌우를 기준으로 두는 절대적 위치.

- 주로 사용자는 top, left 속성을 함께 넣어 위치를 지정함 

- 브라우저 움직이면 같이 움직임 

2) position: fixed  : 브라우저의 스크롤바에 영향을 안받고, 화면상 그 위치 그대로 움직이지 않고 고정됨

3) position: static  : position에 아무런 속성이 없다면 default로 갖는 속성임 (있으나 없으나 같음) 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title> absollute, fixed 사용예시 </title>
    <style>
        div {
            width:100px; height:100px;
            opacity:0.7;
        }
 
       div:nth-child(1) {
           background-color:#ff0000;
           position:fixed;  /* fixed 라서 브라우저에서 스크롤바 내려도 위치 그대로 고정 */
           top:0;
           left:0;
       }
 
       div:nth-child(2) {
           background-color:#00ff00;
           position:absolute;  /* absolute 라서 브라우저에서 스크롤바 내리면 함께 움직임 */
           top:50px;
           left:50px;
       }
 
       div:nth-child(3) {
           background-color:#0000ff;
           position:absolute;
           top:100px;
           left:100px;
       }
 
       #wrap {
           width:300px; height:300px;
           position:fixed;
           top:300px; left:300px;
           background-color:yellow;
           opacity:1.0;
       }
 
       #wrap .content {
           width:100px; height:100px;
           position:absolute;
           top:100px; left:100px;
           background-color:red;
           opacity:1.0;
       }
    </style>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
 
    <div id="wrap">
        <div class="content"></div>
    </div>
</body>
</html>

아래는 position: relative를 사용한 예시입니다

(z-index는 우선순위를 부여하는 것) 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
 
    <style>
        #contain {
            width:800px;
            margin:0 auto;
            border:1px solid #cccccc;
        }
 
        #header {
            height:50px;
            background-color:#cccccc;
        }
 
        #wrap {
            height:200px;
            position:relative;
        }
        #content1 {
            width:100px; height:100px;
            background-color:red;
            border:2px dashed green;
            position:absolute;  /* 얘를 감싸는 바깥요소인 wrap의 position이 relative면, 안쪽요소들은 absolute */
            top:10px; left:10px;  /* 얘를 감싸는 wrap의 position이 relative라서 wrap 안에서 위 10px, 왼쪽 10px에 위치함 */
            z-index:20;  /*z-index 20은 10보다 크므로 더 위에 올라감*/
        }
        
        #content2 {
            width:100px; height:100px;
            background-color:yellow;
            border:2px dashed green;
            position:absolute;
            top:50px; left:50px;
            z-index:10;
        }
 
        #footer {
            height:50px;
            background-color:#cccccc;
        }
    </style>
 
</head>
<body>
    <div id="contain">
        <div id="header">HEADER</div>
        <div id="wrap">
            <div id="content1">content1</div>
            <div id="content2">content2</div>
        </div>
        <div id="footer">FOOTER</div>
    </div>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

HashMap을 사용할 때 알아두면 유용한 메소드를 오늘 새로 하나 배웠다. 

 

 

getOrDefault() : 찾는 키가 존재하면 해당 키의 값을 반환하고, 없으면 기본값을 반환함 

 

 

map.put(키, 값) 

--> map.put(a라는 키, a의 값이 존재하면 a의 값을 넣어주고 없다면 0)  , 그리고 + 1 

 

 

margin 및 padding 속성

-margin: 원래의 height, width 이상으로 바깥으로 더 커짐 

-padding: 이 속성을 주게 되면, 내용(contnents)은 원래의 height, width에 맞춰 들어가지만, 내용의 background는 padding 준 정도만큼 커져있음 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        body {
            margin:0;
        }
        div {
            width:200px; height:200px;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        #content1 {
            background-color:red;
        }
 
        #content2 {
            background-color:green;
            margin:10px 10px 10px 10px; /* 내용물 밖으로 10px씩 늘어나서 공간을 차지 */
        }
 
        #content3 {
            background-color:blue;
            padding:10px 10px 10px 10px; /* 깔려있는 background가 10px씩 넓어짐 */
        }
 
         #content4 {
            background-color:orange;
            margin:10px 10px 10px 10px;
            padding:10px 10px 10px 10px;
        }
    </style>
</head>
<body>
    <div id="content1"> 200*200 </div>
    <div id="content2"> 200*200 <br /> margin </div>
    <div id="content3"> 200*200 <br /> padding </div>
    <div id="content4"> 200*200 <br /> margin <br /> padding</div>
</body>
</html>
cs

box-sizing 속성

- box-sizing을 이용하면 전체 사이즈의 크기를 지정

1) box-sizing: border-box;  : 박스를 밖으로 나가지 않도록 사이즈 형성됨  (박스를 inside로)

2) box-izing: content-box;  : 박스가 밖으로 밀려나가서 사이즈 형성됨 (박스를 outside로)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        body {
            margin:0;
            background-color:#dddddd;
        }

        div {
            width:100px;
            height:100px;
            margin:10px;
            padding:10px;
            border:10px solid #ff8d00;
        }

        div:nth-child(1) {
            margin:0;
            border:0;
            padding:0;
            background-color:#ff0000;
        }

        div:nth-child(2) {       
            background-color:#00ff00;
            box-sizing:border-box;
            
        }

        div:nth-child(3) {     
            background-color:#0000ff;
            box-sizing:content-box;
        }
    </style>
</head>
<body>
    <div>100*100</div>
    <div>100*100</div>
    <div>100*100</div>
</body>
</html>

border 속성

-박스의 두께를 주는 것 

/*
border-width:10px;      
border-style:dashed;   
border-color:#00ff21;  
이렇게 세개로 나눠서 쓰면 코드량이 많아지고 번잡해지므로 아래와 같이 한 번에 씀 
*/
border: 10px dashed #00ff21; 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        div:nth-child(1) {
            width:150px;
            height:150px;
            text-align:center;
            border-width:5px;
            border-style:solid;
            border-color:#ff6a00;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }

        div:nth-child(2) {
            width:150px;
            height:150px;
            text-align:center;
            border-width:10px;
            border-style:dashed;
            border-color:#00ff21;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }

        div:nth-child(3) {
            width:150px;
            height:150px;
            text-align:center;
            border:15px solid #c20b75;
            border-radius:10px 10px 0 0;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }
    </style>
</head>
<body>
    <div>테스트</div>
    <div>테스트</div>
    <div>테스트</div>
</body>
</html>

url() 속성

-Background-img속성의 속성값으로 많이 사용됨. 

 

1
background-image:url('http://www.test.jpg');

 

display 속성

-화면에 어떻게 보이는지를 설정하는 속성 

-다양한 속성값이 있지만 display 속성으로 주로 몇 가지만 많이 사용됨

 

1) display: block  : 위아래 정렬  (블록을 쌓는 것처럼 개행이 저절로 되어 아래로 붙는 요소)

    (ex. <div>, <p>, <li> ) 

2) display: inline : 옆정렬 (옆으로 붙여짐); 높이는 최소값 

   (ex. <span>, <img> )

3) display: inline-block : inline 처럼 옆정렬도 되지만, block이 가지는 높이 속성도 함께 가짐 

4) display: none : 화면에서 보이지 않게 함(공간차지도 없음)

    (visibility: hidden : 화면에서는 안보이지만 공간은 그대로 차지) 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        body div:nth-child(1) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(2) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(3) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(4) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(5) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;  /* block 요소인 div태그를 inline 요소로 바꿈 */
            margin:10px 10px 10px 10px;
        }
 
        body div:nth-child(6) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;  /* block 요소인 div태그를 inline 요소로 바꿈 */
        }
        body div:nth-child(7) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:none;  /* none: 화면에서 날려보내기 (공간마저도 없앰) */
        }
        body div:nth-child(8) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;    /* block 요소인 div태그를 inline 요소로 바꿈 */
        }
        body div:nth-child(9) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline-block; /*inline-block으로 하면 옆정렬이 되면서 & block요소로써 갖는 100px의 height 속성 */
        }
    </style>
</head>
<body>
 
    <div>
        content1
    </div>
    <div>
        content2
    </div>
    <div>
        content3
    </div>
 
    <div>
        content4
    </div>
    <div>
        content5
    </div>
    <div>
        content6
    </div>
    <div>
        content7
    </div>
    <div>
        content8
    </div>
    <div>
        content9
    </div>
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

opacity 속성

-투명도를 나타냄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<style>
        ul li {
            display:inline-block;  /*옆정렬시킴. 이 속성이 없다면 위아래 정렬 되었을것*/
            width:200px; height:100px;
            text-align:center;
            background-color:#dddddd;
        }
 
        ul li:nth-child(2) {
            background-color:#dddddd;
            opacity:0.7;
        }
 
        ul li:nth-child(3) {
            background-color:#dddddd;
            opacity:0.4;  /* 낮을수록 투명도 높아짐 */
        }
    </style>
</head>
<body> 
    <ul>
        <li>우리나라 만세!!</li>
        <li>대한민국 만세!!</li>
        <li>KOREA FIGHTING!!</li>
    </ul>
</body>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

선택자란, 특정 택를 선택하여 해당 태그의 속성을 변경하는 목적 (css의 목적이기도 함)

 

태그선택자

- 속성 변경하고자 하는 태그를 선택 가능 

ex) p { } 

ex) li { } 

ex) div { } 

전체선택자(*)

* {

     /*여기에 css 속성 넣으면 해당 스타일시트에 모두 적용 됨 */

}

 

 id(#)와 class(.)선택자

-id: 스타일을 지정할 때 한 가지만 지정해서 쓰는 이름 (표기방식은 #이름)

-class: 그룹으로 묶어서 스타일을 지정할 때 쓰는 이름  (표기방식은 .이름)

 

태그, id, class 혼합선택자

- ul li.menu {}   : ul 태그 중, li 태그 안에 menu라는 클래스 가진 태그만 선택 

 

 

속성선택자

-tag의 속성을 선택하여 css의 속성을 설정할 수 있음 

 

 

후손 및 자손선택자

*자손선택자: 내 바로 밑에 태그들만 선택

  ex) div > li { }     <-- div안 바로 다음에 위치한 li태그들만 선택

 

*후손선택자: 내 밑 모든 태그들 선택   

  ex) div li { }       <- div안에 있는 li태그들 모~두 선택(li의 위치가 얼마나 안에 있던지 상관x) 

 

 

 

동위선택자

-태그의 동등한 위치를 판단하여 css속성을 설정 
ex) h3~div : h3과 동등한 위치에 있는 div를 전부다 선택 (h3 나 자신은 제외) 
ex) h3+div : h3과 동등한 위치에 있는 div중에 내 바로 밑에 태그 하나만 선택 (h3 나 자신은 제외) 

 

 

반응선택자

-마우스의 반응에 따른 속성을 설정 (hover) 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style>
        ul > li {
            font-size: 20px;
            font-weight: bold;
            color: coral;
        }
 
        li:hover {
            color:blue;
        }
    </style>
</head>
<body>
    <div>
        <ul>
            <li>menu1</li>
            <li>menu2</li>
            <li>menu3</li>
            <li>menu4</li>
            <li>menu5</li>
        </ul>
    </div>
</body>
</html>
 

↑마우스를 올리는 곳에 폰트색상이 블루로 변함

상태 선택자

-상태 선택자란 상태에 따라 css속성이 변하는 설정을 할 수 있음 

 

-focus: 마우스로 해당 form태그의 input에 눌렀을 때 해당하는 곳 

-enabled: disabled로 지정하지 않은 곳 

-disabled: 서버에서 값을 미리 설정하여 변경 못하도록 

 

 

구조선택자  

-구조에 따라서 css속성이 변하는 설정을 할 수 있음

ex) ul li:nth-child(1) <-- 첫번째 자식만 선택

ex) ul li:nth-chuld(2) <-- 두번째 자식만 선택 

ex) ul li:nth-child(2n)     <-- 짝수만 선택

ex) ul li:nth-child(0n+1)     <-- 홀수만 선택

 

 

문자선택자 

-특정 문자 또는 문자열을 선택하여 css속성을 설정 할 수 있음 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
 
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
 
        #wrap {
            width:800px;
            margin:0 auto;
        }
 
        #header {
            border-bottom:1px solid #cccccc;
        }
 
        #content p:first-child::selection {  /* p태그들 중 첫번째 자식의 경우, 마우스로 드래그하여 선택한 부분만 속성 지정 */
            background-color:blue;
            color:yellow;
        }
 
        #history2::first-letter, #history1::first-letter{ /* #history2와 histroy1의 첫번째 글자 */
            font-size:2em;
        }
        
        #history2::first-line, #history1::first-line{ /* #history2와 histroy1의 첫번째 줄 */
            font-weight:bold;
            color:#2160d1;
        }
 
    </style>
</head>
<body>
    <div id="wrap">
 
        <div id="header">
            <h1>설립개요</h1>
        </div>
 
        <div id="content">
            <p>
                중소기업 지원업무의 전문성과 효율성을 확보하고 중소기업에 대한 기술, 경영, 인력 등의 종합지원체계를 구축함으로.....
            </p>
            <p id="history2">
                2014 04월 09일<br />서울산업진흥원 사명변경06월 30일 서울산업진흥원 상암DMC 이전
            </p>
            <p id="history1">
                2013 01월 12일<br />다누리 시민청 개관05월 09일 꿈꾸는청년가게 명동점 개관05월 10일 큐비드 광화문 개관06월 21일 다누리 강남점 개관07월 20일 서울크리에티브랩 개관08월 27일 다누리 성북점 개관
            </p>
        </div>
 
    </div>
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

아래는 브라우저 화면

링크선택자

문서에서 링크(href)되어 있는 문자를 선택하여 css 속성을 설정 할 수 있음 

- a태그가 걸려있는 것들 찾아서 뒤에 어떤 속성을 지정하고 싶을 때 사용 

 

 

 

 

부정선택자

나를 제외한 모든 태그에 css 속성을 적용할 수 있음 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
//이전 순열
public class Baekjoon10973 {
 
    public static void main(String[] args) throws NumberFormatException, IOException {
    
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        
        int arr[] = new int[N];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 0; i < N; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        
        if(prePermutation(arr)) {
            for (int i = 0; i < N; i++) {
                System.out.print(arr[i] + " ");
            }
            System.out.println();
        } else {
            System.out.println("-1");
        }
    }    
 
    public static boolean prePermutation(int[] arr) {
        
        //뒤에서부터 탐색해서 a-1가 a보다 큰 경우 찾음
        int a = arr.length - 1;
        while(a > 0 && arr[a-1<= arr[a]) a--;
        if (a <= 0return false;
        
        //다시 뒤에서부터 탐색하며 a-1가 b보다 큰 경우 찾음
        int b = arr.length - 1;
        while(arr[a-1<= arr[b]) b--;
        
        //a-1와 b를 swap
        int tmp = arr[a-1];
        arr[a-1= arr[b];
        arr[b] = tmp;
        
        //a부터 끝까지 내림차순 정렬 (swap이용) 
        int start = a;
        int end = arr.length - 1;
        while(start < end) {
            tmp = arr[start];
            arr[start] = arr[end];
            arr[end] = tmp;
            start++;
            end--;
        }
        return true;
    }
}

+ Recent posts