그리드 레이아웃이란 ?

- 페이지를 여러 주요 영역으로 나누거나, 크기와 위치 및 문서 계층 구조의 관점에서 HTML 기본 요소로 작성된 컨트롤 간의 관계를 정의하는데 아주 탁월하다.

- 테이블과 마찬가지로 그리드 레이아웃은 세로 열과 가로 행을 기준으로 요소를 정렬할 수 있다.

- 테이블과 달리 CSS 그리는 다양한 레이아웃을 훨씬 더 쉽게 구현할 수 있다. 

 

 

 

grid-template-rows

grid-template-columns

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	/* 명시적으로 행/열의 크기를 지정 */	
	grid-template-rows: 100px auto 100px; /* 총 3행 / 1, 3행은 100px를 줌 */
	grid-template-columns: 100px auto; /* 총 2열 / 1열은 100px를 줌 */
}

.item {
	font-weight: 900; font-size: 25px;
	border: 1px solid #333;
	border-radius: 3px;
	
	display: flex;
	align-items: center; /* 수직의 가운데 */
	justify-content: center;
}

.item1 { background: rgb(255,100,77); }
.item2 { background: rgb(255,165,0); }
.item3 { background: rgb(50,205,50); }
.item4 { background: rgb(255,105,180); }
.item5 { background: rgb(30,145,255); }
.item6 { background: rgb(169,169,169); }

</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

grid-template-areas

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	/* 영역 이름을 참조해 템플릿 생성 */
	grid-template-rows: 100px auto 100px; /* 총 3행 / 1, 3행은 100px를 줌 */
	grid-template-columns: 100px auto; /* 총 2열 / 1열은 100px를 줌 */
	grid-template-areas: 
		"header  header"
		"nav body"
		"footer footer";
	
	font-weight: 900;
	font-size: 25px;
}

.header {
	grid-area : header;
	border: 1px solid blue;
	background: #99e9f2;
	display: flex;
	margin: 5px 5px;
	justify-content: center;
	align-items: center;
}

.nav {
	grid-area : nav;
	border: 1px solid blue;
	background: #99e9f2;
	display: flex;
	margin: 5px 5px;
	justify-content: center;
	align-items: center;
}

.body {
	grid-area : body;
	border: 1px solid blue;
	background: #99e9f2;
	display: flex;
	margin: 5px 5px;
	justify-content: center;
	align-items: center;
}

.footer {
	grid-area : footer;
	border: 1px solid blue;
	background: #99e9f2;
	display: flex;
	margin: 5px 5px;
	justify-content: center;
	align-items: center;
}

</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<header class="header">HEADER</header>
	<nav class="nav">NAV</nav>
	<article class="body">BODY</article>
	<footer class="footer">FOOTER</footer>
</div>

</body>
</html>

 

grid-template

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	grid-template: repeat(3, auto) / repeat(2, auto);
	/* grid-template: repeat(3, 200) / repeat(2, 300); */
	/* 행 수가 3개 width는 auto, 열 수가 2개 height는 auto */
	gap: 10px; /* row-gap: 10px; column-gap: 10px; */
	/* 요소와 요소 사이의 공간 */
}

.item {
	font-weight: 900; font-size: 25px;
	border: 1px solid #333;
	border-radius: 3px;
	
	display: flex;
	align-items: center; /* 수직의 가운데 */
	justify-content: center;
}

.item1 { background: rgb(255,100,77); }
.item2 { background: rgb(255,165,0); }
.item3 { background: rgb(50,205,50); }
.item4 { background: rgb(255,105,180); }
.item5 { background: rgb(30,145,255); }
.item6 { background: rgb(169,169,169); }

</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

grid-auto-rows

grid-auto-columns

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	/* 명시적으로 2개의 행과 2개의 열 크기 명시 */
	grid-template-rows: 200px 200px;
	grid-template-columns: 150px 150px;
	/* 암시적인 행, 열의 크기를 정의 */
	grid-auto-rows: 100px;
	grid-auto-columns: 100px;
}

.item {
	font-weight: 900; font-size: 25px;
	border: 1px solid #333;
	border-radius: 3px;
	
	display: flex;
	align-items: center; /* 수직의 가운데 */
	justify-content: center;
}

.item1 { background: rgb(255,100,77); }
.item2 { background: rgb(255,165,0); }
.item3 { background: rgb(50,205,50); }
.item4 { background: rgb(255,105,180); }
.item5 { background: rgb(30,145,255); }
.item6 { background: rgb(169,169,169); }

/* item요소들 중에 5번째 요소 */
.item:nth-child(5) { /* 아이템 배치 */
	grid-row: 3/4; /* start-line / end-line */
	grid-column: 3/4;
}

/* .item :nth-child / item의 자손요소중 5번째 요소*/

</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

repeat, fr

grid-auto-flow

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	grid-template-rows: repeat(3, 1fr); /* 1/3 의 의미 */
	grid-template-columns: repeat(3, 1fr);
	grid-auto-flow: row dense; /* 각 행 축을 따라 차례로 배치. 빈 영역을 메움 */
	/* grid-auto-flow: column dense; */
}

.item {
	font-weight: 900; font-size: 25px;
	border: 1px solid #333;
	border-radius: 3px;
	
	display: flex;
	align-items: center; /* 수직의 가운데 */
	justify-content: center;
}

.item1 { background: rgb(255,100,77); }
.item2 { background: rgb(255,165,0); }
.item3 { background: rgb(50,205,50); }
.item4 { background: rgb(255,105,180); }
.item5 { background: rgb(30,145,255); }
.item6 { background: rgb(169,169,169); }

.item:nth-child(2) {
	grid-column:span 3; /* 3칸에 출력 */	
}
</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

grid-row

grid-column

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 600px; height: 600px; margin: 50px;
	background: #fff;
	border: 10px solid #ddd;
	border-radius: 10px;
	
	display: grid;
	
	grid-template-rows: repeat(4, 1fr);
	grid-template-columns: repeat(3, 1fr);
}

.item {
	font-weight: 900; font-size: 25px;
	border: 1px solid #333;
	border-radius: 3px;
	
	display: flex;
	align-items: center; /* 수직의 가운데 */
	justify-content: center;
}

.item1 { background: rgb(255,100,77); }
.item2 { background: rgb(255,165,0); }
.item3 { background: rgb(50,205,50); }
.item4 { background: rgb(255,105,180); }
.item5 { background: rgb(30,145,255); }
.item6 { background: rgb(169,169,169); }
.item7 { background: rgb(169,80,255); }
.item8 { background: rgb(95,95,95); }
.item9 { background: rgb(240,0,0); }

.item1 {
	grid-column:1/4;
}
.item2 {
	grid-row:2/4;
}
.item3 {
	grid-column:2/span2; /* 2열부터 두 칸 */
}
.item6 {
	grid-column:1/span3; /* 1열부터 세 칸 */
}

</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

 

auto-fill

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	box-sizing: border-box; /* width 안에 border과 padding이 포함됨 */
}

.container {
	width: 800px;  /* 이게 없으면 알아서 조정 */
	margin: 50px;
	border-radius: 10px;
	
	padding: 20px;
	border: 1px solid #99e9f2;
	background: #e3fafc;
	
	display: grid;
	grid-gap: 40px;
	
	grid-template-rows: minmax(100px, auto);
	grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	/* auto-fill: 행열의 개수를 자동으로 조정. 남는 공간은 그대로 유지 */
	grid-auto-flow: dense;
}

.container .item {
	border: 1px solid blue;
	border-radius: 3px;
	background: #99e9f2;
	font-size: 250%;
	color: #fff;
	
	display: flex;
	align-items: center;
	justify-content: center;
}

.container .item:nth-child(1) {
	grid-row-end: span 2;
}

.container .item:nth-child(2) {
	grid-row-end: span 3;
}

.container .item:nth-child(4) {
	grid-row-end: span 3;
}

.container .item:nth-child(5) {
	grid-column-end: span 2;
}


</style>

</head>
<body>

<h3>grid layout</h3>

<div class="container">
	<div class="item item1">1</div>
	<div class="item item2">2</div>
	<div class="item item3">3</div>
	<div class="item item4">4</div>
	<div class="item item5">5</div>
	<div class="item item6">6</div>
</div>

</body>
</html>

 

방법-1

display:block을 사용한다.

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	padding: 0; margin: 0;
}

header {
	position: fixed;
	top: 0; left: 0; right: 0; 
	/* right 0은 오른쪽 끝까지 간다는 뜻아니면 width 100% 로 줘도됨! */
	
	color: white;
	background: darkblue;
}

header>nav>ul>li {
	list-style: none;
	display: inline-block;
}

header>nav>ul>li>a {
	display: block;
	text-decoration: none;
	padding: 10px 20px;
	color: white;
	font-weight: 700;
}

header>nav>ul>li>a:hover {
	background: #03f;
	font-weight: 700;
}

main {
	min-height: 1500px;
	padding-top: 40px;
}

footer {
	height: 50px;
	line-height: 50px;
	text-align: center;
}

</style>

</head>
<body>

<header>
	<nav>
		<ul>
			<li><a href="#">홈</a></li>
			<li><a href="#">메뉴-1</a></li>
			<li><a href="#">메뉴-2</a></li>
		</ul>
	</nav>
</header>

<main>
	<h3>display:flex를 사용하지 않고 메뉴바를 화면에 고정</h3>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
</main>

<footer>
	<p>footer 영역</p>
</footer>

</body>
</html>

 

방법-2

float:left 를 사용한다.

더보기

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
* {
	padding: 0; margin: 0;
}

header>nav {
	width: 100%;
	background: darkblue; 
	position: fixed;
}

header>nav>ul {
	list-style: none;
}

header>nav>ul>li {
	width: 100px; height: 50px; line-height: 50px;
	text-align: center;
	float: left;
}

header>nav>ul>li>a {
	color: white;
	text-decoration: none;
}
header>nav>ul>li:hover, header>nav>ul>li:active {
	background: blue;
}

main {
	min-height: 1100px;
	clear: both;
	padding-top: 55px;
}

footer {
	height: 50px;
	line-height: 50px;
	text-align: center;
}

</style>

</head>
<body>

<header>
	<nav>
		<ul>
			<li><a href="#">홈</a></li>
			<li><a href="#">메뉴-1</a></li>
			<li><a href="#">메뉴-2</a></li>
		</ul>
	</nav>
</header>

<main>
	<h3>display:flex를 사용하지 않고 메뉴바를 화면에 고정</h3>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
</main>

<footer>
	<p>footer 영역</p>
</footer>

</body>
</html>

 

'쌍용강북교육센터 > 9월' 카테고리의 다른 글

0924_Javascript : 개요  (0) 2021.09.25
0923_CSS : Grid Layout  (0) 2021.09.23
0923_CSS : flex 속성  (0) 2021.09.23
0923_CSS : columns 다단  (0) 2021.09.23
0923_CSS : clip  (0) 2021.09.23
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.flex-container {
	width: 350px;
	padding: 10px;
	margin: 30px;
	border: 3px dotted gray;
}

.flex {
	display: flex;
}

.inline-flex {
	display: inline-flex;
}

.box {
	width: 80px;
	height: 50px;
	line-height: 50px;
	text-align: center;
	margin: 5px;
	border: 1px solid blue;
}

</style>
</head>
<body>

<h3>flex</h3>

<p>플렉스 레이아웃을 적용하지 않은 경우</p>
<div class="flex-container">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

<p>display:flex, 수직으로 쌓는다.</p>
<div class="flex-container flex">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<div class="flex-container flex">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

<p>display:inline-flex, 수평으로 쌓는다.</p>
<div class="flex-container inline-flex">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<div class="flex-container inline-flex">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

</body>
</html>

 

flex-direction

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.flex-container {
	width: 350px;
	padding: 10px;
	margin: 30px;
	border: 3px dotted gray;
	
	display: flex;
}

.row { flex-direction: row; }
.row-reverse { flex-direction: row-reverse; }
.column { flex-direction: column; }
.column-reverse { flex-direction: column-reverse; }

.box {
	width: 80px;
	height: 50px;
	line-height: 50px;
	text-align: center;
	margin: 5px;
	border: 1px solid blue;
}

</style>
</head>
<body>

<h3>flex-direction : 아이템 주측 방향 설정</h3>

<p>기본값</p>
<div class="flex-container">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

<p>flex-direction:row</p>
<div class="flex-container row">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>
<p>flex-direction:row-reverse</p>
<div class="flex-container row-reverse">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

<p>flex-direction:column</p>
<div class="flex-container column">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>

<p>flex-direction:column-reverse</p>
<div class="flex-container column-reverse">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<hr>

</body>
</html>

 

flex-wrap

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.flex-container {
	width: 200px;
	padding: 10px;
	margin: 20px;
	border: 3px dotted gray;
	
	display: flex;
}

.nowrap { flex-wrap: nowrap; }
.wrap { flex-wrap: wrap; }

.box {
	width: 60px;
	height: 100%;
	padding: 10px;
	text-align: center;
	
	border: 1px solid blue;
}

</style>
</head>
<body>

<h3>flex-wrap:강제로 한줄로 배치할 것인지, 영역을 벗어나지 않고 여러 줄로 배치할 것인지 지정</h3>

<p>기본값</p>
<div class="flex-container">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
</div>
<div class="flex-container">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
	<div class="box">D</div>
	<div class="box">E</div>
	<div class="box">F</div>
	<div class="box">G</div>
	<div class="box">H</div>
	<div class="box">I</div>
</div>
<hr>

<p>nowrap</p>
<div class="flex-container nowrap">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
	<div class="box">D</div>
	<div class="box">E</div>
	<div class="box">F</div>
	<div class="box">G</div>
	<div class="box">H</div>
	<div class="box">I</div>
</div>
<div class="flex-container nowrap">
	<div class="box">ITEM A</div>
	<div class="box">ITEM B</div>
	<div class="box">ITEM C</div>
	<div class="box">ITEM D</div>
	<div class="box">ITEM E</div>
	<div class="box">ITEM F</div>
</div>
<hr>

<p>wrap</p>
<div class="flex-container wrap">
	<div class="box">A</div>
	<div class="box">B</div>
	<div class="box">C</div>
	<div class="box">D</div>
	<div class="box">E</div>
	<div class="box">F</div>
	<div class="box">G</div>
	<div class="box">H</div>
	<div class="box">I</div>
</div>
<div class="flex-container wrap">
	<div class="box">ITEM A</div>
	<div class="box">ITEM B</div>
	<div class="box">ITEM C</div>
	<div class="box">ITEM D</div>
	<div class="box">ITEM E</div>
	<div class="box">ITEM F</div>
</div>
<hr>

</body>
</html>

 

display:flex를 이용한 수직 수평 가운데 정렬

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.parent {
	width: 500px; height: 350px;
	border: 1px solid blue;
	
	display: flex;
	align-items: center; /* 수직 가운데. display: flex 에서 가능 */
	justify-content: center; /* 주축 정렬. display: flex 에서 가능 */
}
.box {
	width: 350px;
	border: 1px solid orange;
	background: yellow;
}

h3 { text-align: center; }

</style>
</head>
<body>

<div class="parent">
	<div class="box">
		<h3>display:flex를 이용한 수직 수평 가운데 정렬</h3>
	</div>
</div>

</body>
</html>

 

justify-content: space-between

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
header {
	height: 55px; padding: 1rem; color: white; background: darkblue;
	font-weight: bold;
	
	display: flex;
	justify-content: space-between; /* 첫번째는 왼쪽 두번째는 오른쪽 배치*/
	align-items: center;
}

nav > span {
	cursor: pointer;
	padding: 10px;
}

main {
	min-height: 1100px;
}

footer {
	height: 50px;
	line-height: 50px;
	text-align: center;
}

</style>
</head>
<body>

<header>
	<h1>스터디</h1>
	<nav>
		<span>메뉴-1</span>
		<span>메뉴-2</span>
		<span>메뉴-3</span>
	</nav>
</header>

<main>
	<h3>고정되지 않는 메뉴</h3>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
</main>

<footer>
	<p>footer 영역</p>
</footer>

</body>
</html>

 

위 코드에서 메뉴영역이 스크롤을 내려도 위에 고정되어있게 하려면 position: fixed; 를 준다.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<style type="text/css">
header {
	position: fixed; /* 자리를 차지 하지 않음. 공중에 떠있음. */
	top: 0; left: 0; right: 0;
	
	height: 55px; padding: 1rem; color: white; background: darkblue;
	font-weight: bold;
	
	display: flex;
	justify-content: space-between; /* 첫번째는 왼쪽 두번째는 오른쪽 배치*/
	align-items: center;
}

nav > span {
	cursor: pointer;
	padding: 10px;
}

main {
	min-height: 1100px;
	padding-top: 60px;
}

footer {
	height: 50px;
	line-height: 50px;
	text-align: center;
}

</style>
</head>
<body>

<header>
	<h1>스터디</h1>
	<nav>
		<span>메뉴-1</span>
		<span>메뉴-2</span>
		<span>메뉴-3</span>
	</nav>
</header>

<main>
	<h3>메뉴를 상단에 고정</h3>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
	<p>메인 영역</p>
</main>

<footer>
	<p>footer 영역</p>
</footer>

</body>
</html>

 

'쌍용강북교육센터 > 9월' 카테고리의 다른 글

0923_CSS : Grid Layout  (0) 2021.09.23
0923_CSS : display:flex를 사용하지 않고 메뉴 상단 고정  (0) 2021.09.23
0923_CSS : columns 다단  (0) 2021.09.23
0923_CSS : clip  (0) 2021.09.23
0923_CSS : Z-index  (0) 2021.09.23

columns 속성

- 요소의 다단 레이아웃 열수 및 열 너비를 설정

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box1 {
	columns: 3; /* 단 */
	margin: 30px;
}

.box2 {
	columns: 200px; /* 단의 최소 크기 */
	margin: 30px;
}

.box3 {
	columns: 200px 5; /* 단의 최소 크기 및 단의 최대 개수 */
	margin: 30px;
}

</style>


</head>
<body>

<h3>columns : 다단</h3>

<h3>3단</h3>
<div class="box1">
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
</div>
<hr>

<h3>단의 최소 크기 지정</h3>
<div class="box2">
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
</div>
<hr>

<h3>단의 최소 크기 및 최대 단수 지정</h3>
<div class="box3">
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
	html css javascript jquery node.js react vue.js java oracle mysql bigdata maven spring spring-security mybatis 
</div>
<hr>

</body>
</html>

 

'쌍용강북교육센터 > 9월' 카테고리의 다른 글

0923_CSS : display:flex를 사용하지 않고 메뉴 상단 고정  (0) 2021.09.23
0923_CSS : flex 속성  (0) 2021.09.23
0923_CSS : clip  (0) 2021.09.23
0923_CSS : Z-index  (0) 2021.09.23
0923_CSS : 포지셔닝 position  (0) 2021.09.23

Clip 속성

- 요소의 어느 부분이 보이는지를 정의한다.

- position: absolute 또는 position: fixed 요소에만 적용된다.

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 300px; height: 200px; padding: 10px; margin: 30px;
	border: 2px dotted gray;
}

.img {
	position: absolute;
	top: 80px; left: 420px;
	clip: rect(20px, 220px, 220px, 20px); /* top, right, bottom, left */
}
</style>
</head>
<body>

<div class="box"><img src="../img/img2.png" width= "300" height="200"></div>
<div class="box"><img src="../img/img2.png" class="img"></div>



</body>
</html>

'쌍용강북교육센터 > 9월' 카테고리의 다른 글

0923_CSS : flex 속성  (0) 2021.09.23
0923_CSS : columns 다단  (0) 2021.09.23
0923_CSS : Z-index  (0) 2021.09.23
0923_CSS : 포지셔닝 position  (0) 2021.09.23
0916~0917_CSS : Cascading Style Sheets(CSS)  (0) 2021.09.22

Z-index 속성

- position 속성이 설정된 요소 중 static이 아닌 요소와 그 자손 요소의 Z축 순서를 지정한다. 즉, Z축 순서를 지정하기 위해서는 position 속성을 설정 한 후 Z-index 속성을 지정해야한다.

- 더  Z-index 값을 가진 요소가 작은 값의 요소 위를 덮는다.

- Z-index를 명시하지 않으면 문서에 가장 먼저 삽입된 요소가 Z-index:1 값을 가지며, 그 후 요소는 점점 커진다.

 

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 150px;
	height: 150px;
	border: 3px dotted gray;
}

.absolute-box {
	width: 100px;
	height: 100px;
	position: absolute;
}

.yellow {
	background: yellow;
	z-index: 1000;
}

.orange {
	background: orange;
	left: 100px;
	top: 100px;
	z-index: 100;
}

.green {
	background: green;
	left: 150px;
	top: 150px;
	z-index: 500;
}

.blue {
	background: blue;
	left: 180px;
	top: 100px;
	z-index: 10;
}


</style>


</head>
<body>

<h3> z-index : position 속성이 static이 아닌 요소와 그 자손의 z축 순서 지정</h3>

<div class="box yellow">static:z-index 적용안됨</div>
<div class="absolute-box orange"></div>
<div class="absolute-box green"></div>
<div class="absolute-box blue"></div>


</body>
</html>

 

CSS 포지셔닝?

- CSS를 이용해서 HTML 엘리먼트 들의 위치를 제어하는 방법을 의미한다.

 

position: static

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 150px; height: 150px; margin: 30px;
	border: 3px dotted gray;
	background: orange;
}

.default-box {
	background: #333; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

.static-box {
	position: static;
	background: #333; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

</style>


</head>
<body>

<h3>position:static - 기본, 일반적인 문서 흐름에 따라 배치 </h3>

<div class="box"> <div class="default-box">default</div></div>
<div class="box"> <div class="static-box">static</div></div>
<div class="box" style="padding: 10px;"> <div class="default-box">default</div></div>


</body>
</html>

 

position:relative

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 150px; height: 150px; margin: 30px;
	border: 3px dotted gray;
	background: orange;
}

.default-box {
	background: #333; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

.relative-box {
	position: relative;
	left: 5px;
	top: 5px;
	background: green; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

</style>


</head>
<body>

<h3>porision:relative - 일반적인 문서 흐름에 따라 배치하며, 위치를 지정할 수 있다.  </h3>

<div class="box"> <div class="relative-box">relative</div></div>
<div class="box"> <div class="default-box">default</div></div>


</body>
</html>

position 오타 ㅎㅎ...

 

position:absolute

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 150px; height: 150px; margin: 30px;
	border: 3px dotted gray;
	background: orange;
}

.default-box {
	background: #333; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

.absolute-box {
	position: absolute;
	width: 150px;
	height: 150px;
	left: 50px;
	top: 50px;
	background: green; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

</style>


</head>
<body>

<h3>position:absolute - 일반적인 문서 흐름에 따르지 않으며, 페이지 레이아웃 공간도 배정하지 않음.  </h3>

<div class="box"> <div class="absolute-box">parent:div</div></div>
<div class="absolute-box">parent:body</div>


</body>
</html>

 

position:fixed

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.box {
	width: 100%; height: 2500px;
	background: yellow;
}

.fixed-box {
	position: fixed;
	width: 150px;
	height: 150px;
	left: 100px;
	top: 100px;
	background: green; color: #eee; font-weight: bold; 
	text-align: center; line-height: 150px;
}

</style>


</head>
<body>

<h3>position:fixed - 일반적인 문서 흐름에 따르지 않으며, 페이지 레이아웃 공간도 배정하지 않음.  </h3>

<div class="box">
 요소가 문서의 일반적인 흐름을 따르지 않고, 페이지 레이아웃에 공간을 배정하지 않는다.<br>
 부모 요소와 관계없이 viewport를 기준으로 좌표 프로퍼티를 사용하여 위치를 이동 시킨다.<br>
 스크롤이 되더라도 화면에 사라 지지않고 항상 같은 곳에 위치한다.
</div>

<div class="fixed-box">fixed-box</div>


</body>
</html>

 

위의 폼과 같게 만드시오.

1. table 태그를 사용하여 만들 것 >>

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
/* 테이블 태그를 사용해서 회원가입 폼 만들기*/
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	font-size: 14px;
	font-family: "맑은 고딕", 나눔고딕, 돋움, sans-serif;
	font-weight: 500;
}

button {
	color: #333;
	border: 1px solid #333;
	background-color: #fff;
	padding: 2px 10px;
	border-radius: 4px;
	font-weight: 500;
	vertical-align: middle;
}

button:hover, button:active, button:focus {
	background-color: #e6e6e6;
	border-color: #adadad;
	color: #333;
}

.memberForm {
	width: 600px;
	min-height: 450px;
	margin: 30px auto;
}

.title {
	padding: 30px 0 15px;
	text-align: left;
}

.form {
	width: 100%;
	border-spacing: 0;
	border-collapse: collapse;
}

.form th, .form td {
	padding: 10px 10px;
}

.form tr {
	border-bottom: 1px solid #ccc;
}

.form tr:first-child {
	border-top: 2px solid #4641D9;
}

.form tr:last-child {
	border-bottom: 2px solid #4641D9;
}

.contents {
	padding: 10px;
	width: 120px;
	height: 25px;
	background-color: #e6e6e6;
}

.footer {
	text-align: center;
	padding: 5px 2px;
	margin: 0px auto;
}


</style>
</head>
<body>

	<form>
		<div class="memberForm">
			<h3 class="title">| 회원 가입</h3>
			<table class="form">
				<tr>
					<td class="contents">아 이 디</td>
					<td><input type="text" name="userId"></td>
				</tr>
				<tr>
					<td class="contents">패스워드</td>
					<td><input type="password" name="userPwd"></td>
				</tr>
				<tr>
					<td class="contents">패스워드 확인</td>
					<td><input type="password" name="userPwd1"></td>
				</tr>
				<tr>
					<td class="contents">이  름</td>
					<td><input type="text" name="userName"></td>
				</tr>
				<tr>
					<td class="contents">생년월일</td>
					<td><input type="date" name="birth"></td>
				</tr>
				<tr>
					<td class="contents">이 메 일</td>
					<td><select name="selectEmail">
							<option value="">선 택</option>
							<option value="gmail">gamil.com</option>
							<option value="naver">naver.com</option>
							<option value="daum">daum.net</option>
							<option value="기타">기타</option>
					</select> <input type="text" name="email1" style="width: 100px">
						@ <input type="text" name="email2" style="width: 100px"></td>
				</tr>
				<tr>
					<td class="contents">전화번호</td>
					<td><select name="tel1">
							<option value="">선 택</option>
							<option value="010">010</option>
							<option value="011">011</option>
							<option value="018">018</option>
							<option value="070">070</option>
					</select> <input type="text" name="tel2"  style="width: 70px"> - <input type="text"
						name="tel3"  style="width: 70px"></td>
				</tr>
				<tr>
					<td class="contents">우편번호</td>
					<td><input type="number" name="zip"> <button type="button">우편번호검색</button></td>
				</tr>
				<tr style="border-bottom: 0px;">
					<td class="contents" >주  소</td>
					<td><input type="text" name="addr1" style="width: 350px; padding: 2px;"></td>
				</tr>
				<tr>
					<td class="contents"></td>
					<td colspan="2"><input type="text" name="addr2" style="width: 350px; padding: 2px;"></td>
				</tr>
				<tr>
					<td class="contents">직  업</td>
					<td><input type="text" name="job"></td>
				</tr>
			</table>
			<div class="footer">
			<p>
				<button type="submit" name="sendBtn">회원가입</button>
				<button type="reset">다시입력</button>
				<button type="button">가입취소</button>
			</p>
			</div>
		</div>
	</form>

</body>
</html>

 

2. ul, li 태그를 사용하여 만들 것 >>

더보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
/* ul, li태그를 사용해서 회원가입 폼 만들기*/

* {
	padding: 0; margin: 0;
	box-sizing: border-box;
}

body {
	font-size: 14px;
	font-family: "맑은 고딕", 나눔고딕, 돋움, sans-serif;
	font-weight: 500;
}

button {
	color: #333;
	border: 1px solid #333;
	background-color: #fff;
	padding: 2px 10px;
	border-radius: 4px;
	font-weight: 500;
	vertical-align: middle;
}

button:hover, button:active, button:focus {
	background-color: #e6e6e6;
	border-color: #adadad;
	color: #333;
}

.memberForm {
	width: 600px;
	min-height: 450px;
	margin: 30px auto;
}

.title {
	width: 100%;
	padding: 30px 0 15px;
	text-align: left;
}

.form ul {
	list-style: none;
	clear: both;
	height: 35px;
}

.form li {
	float: left;
	height: 45px;
	line-height: 45px;
	text-align: left;
	padding: 0 10px;
}

.form ul:first-child li {
	border-top:2px solid #4641D9;
}

.form ul:last-child li {
	border-top:1px solid #ccc; 
	border-bottom:2px solid #4641D9;
	
}

.form ul li {
	border-bottom:1px solid #ccc; 
}

.form .content {width: 120px; background-color: #e6e6e6;}
.form .contents {width: 480px; }

.footer {
	text-align: center;
	margin: 0px auto;
}

.footer .footer-paging {
	padding: 15px;
}


</style>
</head>
<body>

<div class="memberForm">
	<div>
		<h3 class="title">| 회원 가입</h3>
	</div>
	<div class="form">
		<ul>
			<li class="content">아 이 디</li>
			<li class="contents"><input type="text" name="userId"></li>
		</ul>
		<ul>
			<li class="content">패스워드</li>
			<li class="contents"><input type="password" name="userPwd"></li>
		</ul>
		<ul>
			<li class="content">패스워드 확인</li>
			<li class="contents"><input type="password" name="userPwd1"></li>
		</ul>
		<ul>
			<li class="content">이  름</li>
			<li class="contents"><input type="text" name="userName"></li>
		</ul>
		<ul>
			<li class="content">생년월일</li>
			<li class="contents"><input type="date" name="birth"></li>
		</ul>
		<ul>
			<li class="content">이 메 일</li>
			<li class="contents"><select name="selectEmail">
							<option value="">선 택</option>
							<option value="gmail">gamil.com</option>
							<option value="naver">naver.com</option>
							<option value="daum">daum.net</option>
							<option value="기타">기타</option>
					</select> <input type="text" name="email1" style="width: 100px">
						@ <input type="text" name="email2" style="width: 100px"></li>
		</ul>
		<ul>
			<li class="content">전화번호</li>
			<li class="contents"><select name="tel1">
							<option value="">선 택</option>
							<option value="010">010</option>
							<option value="011">011</option>
							<option value="018">018</option>
							<option value="070">070</option>
					</select> <input type="text" name="tel2" style="width: 70px"> - <input type="text"
						name="tel3"  style="width: 70px"></li>
		</ul>
		<ul>
			<li class="content">우편번호</li>
			<li class="contents"><input type="number" name="zip"> <button type="button">우편번호검색</button></li>
		</ul>
		<ul>
			<li class="content" style="border-bottom: 0;">주  소</li>
			<li class="contents" style="border-bottom: 0;"><input type="text" name="addr1" style="width: 350px; padding: 2px;"></li>
		</ul>
		<ul>
			<li class="content"></li>
			<li class="contents"><input type="text" name="addr2" style="width: 350px; padding: 2px;"></li>
		</ul>
		<ul>
			<li class="content">직  업</li>
			<li class="contents"><input type="text" name="job"></li>
		</ul>
	</div>
	<div class="footer">
		<div class="footer-paging">
			<p>
				<button type="submit" name="sendBtn">회원가입</button>
				<button type="reset">다시입력</button>
				<button type="button">가입취소</button>
			</p>
		</div>
	</div>
</div>


</body>
</html>

 

+ Recent posts