jjinny_0609
냐냥
jjinny_0609
전체 방문자
오늘
어제
  • 분류 전체보기 (249)
    • IT (18)
      • Eclipse (1)
      • 라즈베리파이 (8)
      • 정보처리기사 (2)
      • 팀 프로젝트 (5)
      • 자료구조 (1)
      • CS 지식 (0)
    • 프로그래밍 언어 (75)
      • Java (33)
      • 파이썬 (4)
      • Node.js (38)
    • 프론트엔드(Frontend) (83)
      • HTML (7)
      • CSS (8)
      • JavaScript (10)
      • jQuery (2)
      • React (50)
      • Vue.js (6)
    • 백엔드(Backend) (62)
      • 네트워크 (1)
      • 데이터베이스 (49)
      • Spring (6)
      • JSP (6)
    • 협업 도구 (6)
      • Git & GitHub (6)
    • 리뷰 (1)
      • 향수 (1)
    • Game Engine (2)
      • 언리얼 엔진5 (1)
      • Unity (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • 블로그관리 홈
  • 글쓰기
  • 글관리

공지사항

인기 글

hELLO · Designed By 정상우.
jjinny_0609

냐냥

CSS3 박스 모델과 응용 #3
프론트엔드(Frontend)/CSS

CSS3 박스 모델과 응용 #3

2023. 1. 5. 20:15
728x90

테이블 스타일

표를 꾸밀때 사용
(id나 class를 이용해 수정도 가능)

속성
border 테이블의 경계선
border-collapse 이웃한 셀의 경계선을 합칠 것인지 여부
      -separate 이웃한 셀의 경계선을 합치지 않고 분리하여 표시한다(기본값)
width 테이블의 가로 길이
height 테이블의 세로 길이
border-spacing 테이블 셀 사이의 거리
empty-cells 공백 셀을 그릴 것인지 여부
table-align 테이블 셀의 정렬 설정

vertical-align 수직정렬 상(top) 중(middle) 하(bottom) 지정

테이블 예제


nth-child

n번째 자식 선택자

:nth-child(N)= 부모안에 모든 요소 중 N번째 요소
<옵션>
odd : 홀수 선택
even : 짝수 선택
2n :두번째 마다 선택
2n + 1 : 2번째마다 선택 첫번째 요소부터 
-2n + 5 : 첫번째요소부터 5번째 요소까지 2개마다 선택
n + 5 : 5번째 부터 모두 선택

A:nth-of-type(N)= 부모안에 A라는 요소 중 N번째 요소
:first-child= 부모안에 모든 요소 중 첫번째 요소
:last-child= 부모안에 모든 요소 중 마지막 요소
A:first-of-type= 부모안에 A라는 요소 중 첫번째 요소
A:last-of-type= 부모안에 A라는 요소 중 마지막 요소

 

nth-child 예제

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- 1번 스타일 -->
<style type="text/css">
	#list1{
		font-family: "Trebuchet MS",sans-serif;
		width: 100%;
	}
	#list1 td, #list th{
		border:1px dotted gray;
		text-align: center;
	}
	#list1 th{
		background-color: blue;
		color:white;
	}
	#list1 tr:nth-child(2n+1) {
		background-color: yellow;
	}
	/* #list1 tr:nth-child(odd) {
		background-color: yellow;
	} */
</style>

<!--2번 스타일-->
<style type="text/css">
	#list{
		font-family: "Trebuchet MS",sans-serif;
		width: 100%;
	}
	#list td, #list th{
		border:1px dotted gray;
		text-align: center;
	}
	#list th{
		background-color: blue;
		color:white;
	}
	#list tr.alt td{
		background-color: yellow;
	}
</style>
</head>
<!-- body태그는 동일 -->
<body>
	<table id="list1">
		<tr>
			<th>이름</th>
			<th>이메일</th>
		</tr>
		
		<tr>
			<td>김철수</td>
			<td>chul@google.com</td>
		</tr>
		
		<tr>
			<td>김영희</td>
			<td>young@google.com</td>
		</tr>
		
		<tr>
			<td>홍길동</td>
			<td>hong@google.com</td>
		</tr>
		
		<tr>
			<td>김수진</td>
			<td>sujin@google.com</td>
		</tr>
	</table>
</body>
</html>

확인해보면 결과는 같다.

nth-child 참고한 블로그 : https://lalacode.tistory.com/6

 

[CSS]css 가상 선택자 정리 및 비교 (nth-child, nth-of-type)

CSS 선택자 정리 :nth-child(N) = 부모안에 모든 요소 중 N번째 요소 A:nth-of-type(N) = 부모안에 A라는 요소 중 N번째 요소 :first-child = 부모안에 모든 요소 중 첫번째 요소 :last-child = 부모안에 모든 요소 중

lalacode.tistory.com

 

끝.

728x90

'프론트엔드(Frontend) > CSS' 카테고리의 다른 글

CSS3 레이아웃 #2  (0) 2023.01.09
CSS3 레이아웃 #1  (0) 2023.01.05
CSS3 박스 모델과 응용 #2  (0) 2023.01.04
CSS3 박스 모델과 응용 #1  (0) 2023.01.04
CSS3 스타일 시트 기초 #2  (0) 2023.01.03
    jjinny_0609
    jjinny_0609
    뉴비 개발자의 학습 내용을 정리한 블로그입니다.

    티스토리툴바