CSS 스타일 입히기

Cascading : 계단식, 덧칠하기식, HTML태그의 원래 스타일을 Cascading

CSS 속성 : 스타일을 입힐 수있는 가지수 ? 속성수 ?

              배경/경계선/폰트/색상/마진-left,top/패딩/박싱/박스라운드-img,color,repeat

대상선별 : 선택자(selector)사용

선택자 기본요소 : id, class , element

 


  • a  :  <a></a> 태그
  • .a  :  <*class ="a">
  • *#a  또는  #a  :  <*id="a">
  • aside.a  :  <aside class="a">

 

 

 

선택자

  • #a{color: green;} : a라는 id를 가지는 엘리먼트에 색상을 적용
  • .a{color: green;} : a라는 class에 포함된 엘리먼트에 색상을 적용
  • a{color: green;} : a라는 태그를 대상으로 색상을 적용

연산자

  • A B : 공백자체가 연산을 의미. A안에 포함된 모든B.
  • A>B : A안에 B자식들만 모두선택
  • A+B : B의 형제 바로 밑동생
  • A~B : A의 동생들 중에 B만 적용

 

#aa+nav+section : nav의section만 고른것


셀럭터를 이용한 엘리먼트  선택

 

.h1{ color:red; } 

class 명이 h1인 태그들을 레드로 적용 

 

 

aside.h1{ color:red; }

class 명이 h1이면서 aside태그를 가지고있는것 레드로 적용

 

 

h1{ color : red; } 

h1의 모든태그에 빨간색 적용

*h1{ color ; red; }와 같다.

 

 

 

section h1{ color : red; }

section안에 포함된 h1 모두를 찾는다.

 

 

 

section > h1 {color: red; }

section태그의 h1자식만 적용

 

 

 

a.first + span : 바로 밑동생으로서의 span 없음

 

 

 

h1 : 범위가 넓으므로 우선권이없음

.h1 , #h2 범위가 좁혀져 우선권생김

우선순위가 같다면 나중에 적용한게 결과로나온다

 

 

 

h1.h1보다 복합연산자가 더높다 
태그명이 속성을 가질땐 우선순위높다

 

 

 

h1{ } :기본 태그이므로 가장 우선순위낮음

.h1{ } : h1클래스로 좁혀짐

h1[lang="ko"] {} : <*lang="ko"> 특정랭귀지속성을 가진 h1태그 , h1에 랭귀지속성 한정사가 한번더 들어가서 우선선위높음

 

 


HTML

a[href^="#"]

  • ^ 시작 의미
  • #으로시작하는것

 

  • dir

    ltr : left to right   왼쪽부터 쓰기
    rtl  : right to left  오른쪽부터 쓰기
      a[dir='rtl']
    이 속성에다가도 스타일을 입힐수있다

/* Links with "example" anywhere in the URL */
a[href*="example"] { background-color: silver; }
example이 포함된것들만 비교가능

 

/* Links with "insensitive" anywhere in the URL,

   regardless of capitalization */
a[href*="insensitive" i] { color: cyan;}
i : 대소문자구별하지않겠다

 

/* Links with "cAsE" anywhere in the URL,
with matching capitalization */
a[href*="cAsE" s] { color: pink;}
s : 대소문자를 가린다.

/* Links that end in ".org" */

a[href$=".org"] { color: red;}
.org로 끝나는것

/* Links that start with "https" and end in ".org" */
a[href^="https"][href$=".org"] { color: green;}
"https" &".org"
두가지속성만족시

 

 

 

 


연습

  • A B : 공백자체가 연산을 의미. A안에 포함된 B의 하위요소. A의 자손만 (B의 자식)

Descendant selector

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .aa div{
            color : red;
        }
    </style>
</head>

<body>
    <div class="aa">
        <p>자식1</p>
        <div>
            <p>aa의 자손</p>
        </div>
        <p>자식2</p>
        <div>
            <p>자손2</p>
            <ul>
                <li>자손3</li>
                <li>자손3</li>
                <li>자손3</li>
            </ul>
        </div>    
    </div>
</body>
</html>

 

  •  A안에 B자식만 선택

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        section>p{
            color : red;
        }
    </style>
</head>

<body>
    <div class="aa">
        <p>Child 1</p>
        <div>
            <p>Descendant1</p>
            <section>
                <p>Descendant2</p>
                <ul>
                    <li>Descendant3</li>
                    <li>Descendant3</li>
                    <li>Descendant3</li>
                </ul>
            </section>   
        </div>
        <p>Child 2</p>
        <section>
            <p>Descendant2</p>
            <ul>
                <li>Descendant3</li>
                <li>Descendant3</li>
                <li>Descendant3</li>
            </ul>
        </section>    
    </div>
</body>
</html>
더보기
    • A+B : B의 형제 바로
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div+p{
            color : red;
        }
    </style>
</head>

<body>
    <div class="aa">
        <p>Child 1</p>
        <div>
            <p>Descendant1</p>
            <section>
                <p>Descendant2</p>
                <ul>
                    <li>Descendant3</li>
                    <li>Descendant3</li>
                    <li>Descendant3</li>
                </ul>
            </section>   
        </div>
        <p>Child 2</p>
        <p>Child 3</p>
        <section>
            <p>Descendant2</p>
            <ul>
                <li>Descendant3</li>
                <li>Descendant3</li>
                <li>Descendant3</li>
            </ul>
        </section>    
    </div>
</body>
</html>

 

복습

  • 버퍼를 이용한 입출력은 다양한 장치에서도 동일하다.
  • System.in : 콘솔입력
  • System.out : 콘솔출력
  • FileInputStream fis = new FileInputStream("파일경로"); // new연산자를 통해 객체를 만듦
  • fis.read(); 를 사용했다면 문자하나씩 읽어옴
  • next(); 단어단위, 공백전까지
  • nextLint() 문자열단위, 줄단위
  • 모든 함수는 객체를 통해서 사용
  • Scanner scan = new Scanner(fis); App -> Scanner -> fis -> 파일이용

 

산술연산

산술연산

*산술 연산시 출력절차 주의

print(x+y)로 쓰면 x+y로만 보이지만
print(3+y)
print(7)
print('7')로 출력되는 절차가있다.

print(x+y)로 쓰면 x+y로만 보이지만
print(3+4.0)
print(7.0)
print('7.0')로 출력되는 절차가있다.

 

*연산자와 자료형

10/3 -> 3 : 정수/정수는 정수
10/3.0 ->3.3333 : 정수/실수는 실수

*나머지연산자 : 반복적인계산 할때자주쓰임

반드시 암기

 

 

 

단항 연산자

단항 연산자
전위식과 후위식 예제

  • kor++; 후위식 연산자의 의미 :
    kor = kor+1; 
  • 단항연산자 ++,--는 앞뒤로 쓸 수 있다.
  • 후위식은 세미콜론(;)지나고 증가한다.

 

 

비교/논리 연산자

==같다

= 대입연산자와 주의

 

 

관계 연산자

범위가 갈라질때는 ||

한범위안에 들을때는 &&

 

 

 

 

비트 논리 연산자

비트연산자
& and (교집합) 모든 비트가 1일때만 1
^ xor (차집합) 모든 비트가 같으면 0,하나라도 다르면1
| or (합집합) 모든비트중 한 비트라도 1이면 1
~ not (부정) 각 비트의 부정, 0면 1,1이면 0

 

 

 

쉬프트 연산자

 

연산자암기할것

 

 


FileInputStream 과 FileOutputStream 사용

메모장에 데이터를 적은 뒤 저장.

 

메모장 데이터 저장모습

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

class Hello {
	public static void main(String[] args) throws IOException {
		int kor, eng, math;
		int total;
		float avg;

		kor = 0;
		eng = 0;
		math = 0;
		
		//여기에 성적을 입력하는 코드를 작성하시오
		//data.txt파일에서 국어,영어,수학성적을 입력받으시오
		// 1.파일 입력 스트림 객체를 fis라는 이름으로 만든다.
		FileInputStream fis = new FileInputStream("C:\\Users\\yh\\git\\repository3\\JavaPrj\\data.txt"); 
		// 2. fis를 Scanner로 포장해서 사용한다.
		Scanner scan1 = new Scanner(fis);				
		kor = scan1.nextInt(); //파일에서 성적을 불러온다.
		eng = scan1.nextInt();
		math = scan1.nextInt(); 
		scan1.close(); // Scanner먼저닫기
		fis.close(); // FileInputStream 닫기
		
				
		
		FileOutputStream fos = new FileOutputStream("C:\\Users\\yh\\git\\repository3\\JavaPrj\\data.txt"); 
		// 2. fis를 Scanner로 포장해서 사용한다.
		PrintStream fout = new PrintStream(fos);
		kor = kor +1; //파일에서 성적을 불러오면서 숫자 1증가
		eng = eng +1; 
		math = math +1; 
				
		fout.printf("%d %d %d", kor,eng,math); 
		fout.close();
		fos.close();
		
		
		total = kor + eng + math;
		avg = total / 3.0f;
				
		//System.out.printf("total is %d\n", total);
		
		System.out.println("┌─────────────────────────────────────────┐");
		System.out.println("│                 성적 출력                 │");
		System.out.println("└─────────────────────────────────────────┘");
		System.out.printf("국어 : %d\n",kor);
		System.out.printf("영어 : %d\n",eng);
		System.out.printf("수학 : %d\n",math);
		
		System.out.printf("총점 : %d\n",total);
		System.out.printf("평균 : %5.2f\n",avg); 
		System.out.println("──────────────────────────────────────────");

	
		}
}

콘솔출력
변경된 메모장내역

FileInputStream fis = new FileInputStream("파일경로");

  • FileInputStream : 입력스트림,파일을 불러오기 위해 사용
  • fis : 연산자 new를 통해 객체 fis생성
  • File관련 스트림은 에러가 발생하므로 예외처리해준다.

Scanner scan = new Scanner(fis);

  • Scanner : java.util에있는 클래스
  • fis를 매개변수로 받고Scanner의 객체 scan 생성
  • import 처리

kor = scan.nextInt();

  • scan을 통해 입력받은 정수값을 kor에 저장한다.

scan.close();

  • 안쪽에있는 Scanner를 먼저 닫아준다.

fis.close();

  • 다음 FileInputStream을 닫아준다. 닫지않으면 계속 파일을 열어둔것과 같음.

FileOutputStream fos = new FileOutputStream("파일경로");

  • FileOutputStream : 출력스트림, 파일을 출력하기 위해 사용

  • fos : 연산자 new를 통해 객체 fos 생성

  • File스트림은 에러가 발생하므로 예외처리해준다.

  • File관련 스트림은 에러가 발생하므로 예외처리해준다.

PrintStream fout = new PrintStream(fos);

  • PrintStream : 출력클래스
  • fos를 매개변수로 받고 PrintStreamd의 객체 fout을 생성
  • 메모장출력은 없는 함수이므로 새로운 객체생성

kor = kor + 1;

  • 입력받은 kor에 숫자 1을 더하고 kor에 저장

fout.printf("%d %d %d",kor,eng,math);

  • four통해 출력을 하되, 메모장에 출력한다.
  • 메모장에 각각 1이 더한값이 출력된다.

fout.close();

  • 안쪽에있는 PrintStream을 먼저 닫아준다.

fos.close();

  • 다음 FileOutputStream을 닫아준다.

System.out.printf("국어: %d", kor);

  • System.out은 PrintStream에 이미 포함되어있어 바로 사용가능
  • (연산자 new를 통해 객체만들 필요 없다)
  • printf()에 서식문자열 %d를 넣어 kor를 불러온다.

 

 

 

+ Recent posts