본문 바로가기

HTML

HTML(12) - 요소 배치/관계를 고려한 배치/float 제거/overflow 발생/넘치는 요소 다 출력/요소의 중첩 처리/표 너비 설정/표 테두리 처리/표 꾸미기/투명도 조절/가시성/보이는 형식의 변환/배경 이미..

position.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>요소 배치</title>
<style type="text/css">
.sp1 {
	position: static;
	width: 300px;
	height: 50px;
	background-color: cyan;
	left: 50px;/*static은 위치이동이 불가하기 때문에 위치를 지정해주어도 의미가 없다*/
}
.sp2 {
	position: static;
	width: 300px;
	height: 50px;
	background-color: orange;
}
.sp3 {
	position: relative;/*원래 있어야할 위치에서부터 어떻게 스타일 적용할지~*/
	width: 300px;
	height: 50px;
	background-color: lightgreen;
	left: 20px;/*왼쪽으로 부터 px만큼 이동하라*/
	top: 50px;/*위로부터 px만큼 이동하라*/
}
.sp4 {
	position: absolute;
	width: 300px;
	height: 50px;
	background-color: navy;
	right: 10px;
	top: 500px;
}
.sp5 {
	position: fixed;
	width: 300px;
	height: 50px;
	background-color: pink;
	right: 20px;
	bottom: 10px;
}
</style>
</head>
<body>
<!-- 다양한 요소를 배치할 때 사용하는 속성
	주요 속성값
	static : 기본값. 웹 문서의 흐름에 따라 배치
	relative : 상대 위치로 설정. 기본 위치에서 상대적으로 얼마나 떨어져 있는지~
	absolute : 절대 위치로 설정. top, right, bottom, left로 설정
	fixed : 절대 위치로 설정하되, 스크롤에 영향을 받지 않는다 
 -->
<h2>정적 위치(static)</h2>
<p class="sp1">정적 위치 설정 적용1</p>
<div class="sp2">정적 위치 설정 적용 2</div>
<p class="sp3">상대 위치 설정 적용</p>
<p class="sp4">절대 위치 설정 적용</p>
<p class="sp5">고정 위치 설정 적용</p>
</body>
</html>

 

 

 

 

 

float.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>관계를 고려한 배치</title>
<style type="text/css">
img {
	float: left;
	margin: 0px 10px 10px 0px;
}
</style>
</head>
<body>
<!-- float
	요소 간의 관계를 고려하여 각 요소를 배치
	속성 값
	left : 요소를 왼쪽에 배치
	right : 요소를 오른쪽에 배치
	none : float 속성을 적용하지 않음
	inherit : 부모 요소의 속성을 그대로 적용
 -->
<p>float 속성은 웹 문서의 레이아웃을 설계하는 과정에서 많이 사용하는 속성입니다</p>
<p>
<img alt="image" src="images/aladin.jpg" width="140" height="140">
float 속성은 특정 요소를 떠 있게 해줍니다. 
여기서 '떠 있다'라는 말의 의미는 특정 요소가 
기본 레이아웃에서 벗어나 웹 문서의 왼쪽이나 
오른쪽에 이동하는 것을 말합니다. 
float 속성은 복잡한 형태의 레이아웃을 
구성하는 데 필요한 핵심 속성으로, 특정 요소가 
주변 요소와 자연스럽게 어울리도록 해줍니다. 
주의할 점은 float 속성을 사용할 때 요소의
위치가 고정되면 안 되기 때문에 position 속성의 
absolute를 사용하면 안 됩니다.
</p>

</body>
</html>

 

 

 

 

 

 

clear.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>float 제거</title>
<style type="text/css">
.div1 {
	float: left;
	width: 100px;
	height: 50px;
	margin: 10px;
	border: 3px solid green;
}
.div2 {
	border: 1px solid red;
}
.div3 {
	float: left;
	width: 100px;
	height: 50px;
	margin: 10px;
	border: 3px solid green;
}
.div4 {
	border: 1px solid red;
	clear: both;
}
hr {
	clear: both;
}
</style>
</head>
<body>
<!-- clear 속성
	float 속성이 적용되지 않기를 원하는 요소에 사용.
	float 속성을 초기화 시킴
	clear: left; | clear: right;
	clear: both; (둘다 취소)
 -->
<h3>clear 없이 사용</h3>
<div class="div1">div1</div>
<div class="div2">div2 - div1 뒤에 있는 영역</div>
<p/>
<hr>
<h3>clear 사용</h3>
<div class="div3">div3</div>
<div class="div4">div4 - div3 뒤에 있는 영역</div>
<hr>

<!-- clearfix
	overflow 속성
	
 -->
</body>
</html>

 

 

 

 

 

 

 

overflow.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>오버플로우 발생</title>
<style type="text/css">
.div1 {
	background-color: gray;
	width: 200px;
	height: 50px;
	border: 1px dotted black;
	overflow: visible;
}
.div2 {
	background-color: gray;
	width: 200px;
	height: 50px;
	border: 1px dotted black;
	overflow: hidden;
}
.div3 {
	background-color: gray;
	width: 200px;
	height: 50px;
	border: 1px dotted black;
	overflow: scroll;/* 내용이 영역을 벗어나지 않아도 스크롤바가 무조건 생김*/
}
.div4 {
	background-color: gray;
	width: 200px;
	height: 50px;
	border: 1px dotted black;
	overflow: auto;/* 내용이 영역을 벗어나게 되면 스크롤바가 자동으로 생김*/
}
.clearfix {
	width: 100%;
	overflow: auto;
}
</style>
</head>
<body>
<!-- overflow 속성
	특정 요소가 너무 커서 영역과 맞지 않을 때
	내용을 제어하는 속성
	속성 값
	1. visible : 기본값. 내용이 모두 출력됨. 영역을 벗어나게 됨.
	2. hidden : 벗어난 요소의 일부를 화면에서 제거
	3. scroll : 벗어난 요소의 일부를 화면서에 제거하고 영역에 스크롤바를 추가
	4. auto : 내용이 모두 출력되도록 영역의 크기를 조정. 
 -->
<h3>Overflow 기본 </h3>
<div class="div1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla libero diam, imperdiet sit amet sagittis a, accumsan non risus. Nunc ut suscipit tellus. Vivamus diam augue, feugiat sit amet urna vel, sodales pellentesque orci. Nunc in orci quis erat b</div><br><br><br><br><br><br><br><br><br>
<div class="div2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla libero diam, imperdiet sit amet sagittis a, accumsan non risus. Nunc ut suscipit tellus. Vivamus diam augue, feugiat sit amet urna vel, sodales pellentesque orci. Nunc in orci quis erat b</div><br><br><br><br><br>
<div class="div3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla libero diam, imperdiet sit amet sagittis a, accumsan non risus. Nunc ut suscipit tellus. Vivamus diam augue, feugiat sit amet urna vel, sodales pellentesque orci. Nunc in orci quis erat b</div><br>
<div class="div3">Lorem ipsum</div><br><br><br><br><br>
<div class="div4">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla libero diam, imperdiet sit amet sagittis a, accumsan non risus. Nunc ut suscipit tellus. Vivamus diam augue, feugiat sit amet urna vel, sodales pellentesque orci. Nunc in orci quis erat b</div><br>
<div class="div4">Lorem ipsum</div><br><br><br><br><br>
<hr>
<h3>overflow를 사용하여 이미지 다 보이게 하기</h3>
<div class="clearfix">
	<img class="img1" alt="image" src="images/aladin.jpg" width="170">
	Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla libero diam, imperdiet sit amet sagittis a, accumsan non risus. Nunc ut suscipit tellus. Vivamus diam augue, feugiat sit amet urna vel, sodales pellentesque orci. Nunc in orci quis erat b
</div>
</body>
</html>

 

 

 

 

 

 

 

overflow-auto.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>넘치는 요소 다 출력</title>
<style type="text/css">
div {
	border: 3px solid green;
	padding: 5px;
	clear: both;
}
.over {
	overflow: auto;/* 영역의 세로길이가 지정되어 있지 않을 경우 가장 큰 요소의 크기로 영역의 크기가 결정됨. */
}
.img1 {
	float: left;
	margin-right: 10px;
}
</style>
</head>
<body>
<div>
	<img class="img1" src="images/aladin.jpg" width="150px">
	Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
</div>

<div class="over">
	<img class="img1" src="images/aladin.jpg" width="150px">
	Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
</div>
</body>
</html>

 

 

 

 

 

 

 

z-index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>요소의 중첩 처리</title>
<style type="text/css">
#box1 {
	position: absolute;
	top: 0;
	left: 0;
	width: 100px;
	height: 100px;
	background-color: red;
	z-index: 3;
}
#box2 {
	position: absolute;
	top: 30px;
	left: 30px;
	width: 100px;
	height: 100px;
	background-color: green;
	z-index: 2;
}
#box3 {
	position: absolute;
	top: 60px;
	left: 60px;
	width: 100px;
	height: 100px;
	background-color: blue;
	z-index: 1;
}
#box2:hover {/* 마우스 올라가면 맨위로 올라가게끔 z-index 숫자 크게 지정해주기*/
	z-index: 10;
}
</style>
</head>
<body>
<!-- 중첩된 요소의 계층화
	z축 정렬을 위한 속성 : z-index
	z-index의 값이 크면 위로, 값이 작으면 밑으로 깔림.
 -->
<div id="box1">박스 1번</div>
<div id="box2">박스 2번</div>
<div id="box3">박스 3번</div>
</body>
</html>

 

hover시에 박스2번 맨앞으로 옴

 

 

 

 

 

table-layout.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표 너비 설정</title>
<style type="text/css">
th, td{
	border: 1px solid black;
}
#tb1{
	border: 2px solid red;
	table-layout: auto;
}
#tb2{
	border: 3px dotted teal;
	table-layout: fixed;
}
</style>
</head>
<body>
<!-- table-layout 속성
	셀의 너비를 조절하는 속성 : auto, fixed
	(기타 : initial, inherit)
 -->
<h3>table-layout auto</h3>
<table id="tb1">
  <tr>
    <th>table-layout auto</th>
    <td>내용 분량에 따라 자동으로 조절</td>
    <td>내용 분량에 따라 자동으로 조절</td>
    <td>내용 분량에 따라 자동으로 조절</td>
  </tr>
</table>
<p/>
<table id="tb2" width="500px">
  <tr>
    <th>table-layout fixed</th>
    <td>내용 분량에 상관없이 고정</td>
    <td>내용 분량에 상관없이 고정</td>
    <td>내용 분량에 상관없이 고정</td>
  </tr>
</table>
</body>
</html>

 

 

 

 

 

 

 

table-collapse.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표 테두리 처리</title>
<style type="text/css">
td, th {
	border: 2px solid black;
}
#tb1 {
	border: 3px solid red;
	border-collapse: separate;
}
#tb2 {
	border: 3px solid orange;
	border-collapse: collapse;
}
#tb3 {
	border: 3px solid blue;
	border-spacing: 10px;/* 상하좌우 */
}
#tb4 {
	border: 2px solid green;
	border-spacing: 20px 40px;/* 좌우 상하*/
}
</style>
</head>
<body>
<!-- table=collapse 속성
	표와 셀 테두리를 별개로 처리할지, 하나도 처리할 지에 대한 설정.
 -->
<!-- table-spacing -->
<table id="tb1" width="600px">
  <tr>
    <th>table-collapse</th>
    <td>separate 적용</td>
  </tr>
</table>
<p/>
<table id="tb2" width="600px">
  <tr>
    <th>table-collapse</th>
    <td>collapse 적용</td>
  </tr>
</table>
<p/>
<table id="tb3" width="600px">
  <tr>
    <th>table-spacing fixed</th>
    <td>10px</td>
  </tr>
</table>
<p/>
<table id="tb4" width="600px">
  <tr>
    <th>table-layout fixed</th>
    <td>20px 40px spacing 적용</td>
  </tr>
</table>
</body>
</html>

 

 

 

 

 

 

 

table-basic.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표 꾸미기</title>
<style type="text/css">
table, th, td {
	border: 1px solid black;	
}
table {
	width: 100%;
	border-collapse: collapse;
}
/* 셀별 세로 길이 지정 */
th {
	height: 50px;
	/*text-align: left;*/
}
td {
	height: 60px;
	text-align: center;/* 수평 정렬*/
	vertical-align: top;/* 수직 정렬 top|bottom */
	padding: 10px;/* 안쪽 여백 */
	
}
</style>
</head>
<body>
<table>
  <tr>
    <th>성</th>
    <th>이름</th>
    <th>적립금</th>
  </tr>
  <tr>
    <td>김</td>
    <td>철수</td>
    <td>100원</td>
  </tr>
  <tr>
    <td>박</td>
    <td>명수</td>
    <td>150원</td>
  </tr>
  <tr>
    <td>이</td>
    <td>길동</td>
    <td>200원</td>
  </tr>
  <tr>
    <td>강</td>
    <td>아지</td>
    <td>50원</td>
  </tr>
</table>

</body>
</html>

 

 

 

 

 

 

table-styling.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표 꾸미기</title>
<style type="text/css">
table {
	width: 100%;
	border-collapse: collapse;	
}
/* 수평선으로 행 구분 */
th, td {/*표의 수평줄에만 테두리 주기*/
	padding: 5px;
	text-align: left;
	border-top: 1px solid #ddd;
	border-bottom: 1px solid #ddd;
}
tr:hover {
	background-color: #f5f5f5;
}
th:nth-child(even) {
	background-color: #f2f2f2;
}
th {
	background-color: #4caf50;
}
</style>
</head>
<body>
<table>
  <tr>
    <th>Column 1 Heading</th>
    <th>Column 2 Heading</th>
    <th>Column 3 Heading</th>
    <th>Column 4 Heading</th>
  </tr>
  <tr>
    <td>Row 1: Col 1</td>
    <td>Row 1: Col 2</td>
    <td style="border-left: 1px solid #ddd;">Row 1: Col 3</td><!-- 셀 좌우로도 보더 설정 가능 -->
    <td>Row 1: Col 4</td>
  </tr>
  <tr>
    <td>Row 2: Col 1</td>
    <td>Row 2: Col 2</td>
    <td>Row 2: Col 3</td>
    <td>Row 2: Col 4</td>
  </tr>
  <tr>
    <td>Row 3: Col 1</td>
    <td>Row 3: Col 2</td>
    <td>Row 3: Col 3</td>
    <td>Row 3: Col 4</td>
  </tr>
  <tr>
    <td>Row 4: Col 1</td>
    <td>Row 4: Col 2</td>
    <td>Row 4: Col 3</td>
    <td>Row 4: Col 4</td>
  </tr>
</table>

</body>
</html>

 

 

 

 

 

 

 

opacity.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>투명도 조절</title>
<style type="text/css">
body {
	background-color: powderblue;
}
img {
	opacity: 0.5;
}
img:hover {
	opacity: 1.0;
}
</style>
</head>
<body>
<!-- opacity 속성 
	요소의 투명도를 조절하는 속성
	0 ~ 1 사이의 값으로 조절
-->
<img alt="image" src="images/aladin.jpg" width="400">
</body>
</html>

 

 

 

 

 

 

visibility.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>가시성</title>
<style type="text/css">
.v1 {
	border: 1px dotted red;
	visibility: hidden;/* visibility : 브라우저에서 자리는 유지하되 이미지 안보이게 됨. */
}
.v2 {
	border: 1px dotted red;
	visibility: visible;/*기본값*/
}
.v3 {
	border: 1px dotted red;
	display: none;/* display : 브라우저에서도 요소의 공간 자체가 아예 없어지게 함 -> hover효과를 쓸 수 없음 */
}
</style>
</head>
<body>
<!-- visibility, display 속성
	화면상에서 요소를 보이게 하거나 숨기는 속성
 -->
<div class="v1">
	<img alt="image" src="images/aladin.jpg" width="200">이미지1
</div>
<div class="v2">
	<img alt="image" src="images/aladin.jpg" width="200">이미지2
</div>
<div class="v3">
	<img alt="image" src="images/aladin.jpg" width="200">이미지3
</div>
<div class="v2">
	<img alt="image" src="images/aladin.jpg" width="200">이미지4
</div>

</body>
</html>

 

 

 

 

 

 

 

 

display.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>보이는 형식의 변환</title>
<style type="text/css">
span.a {
	display: inline;/*span은 기본값이 inline*/
	width: 100px; height: 100px;/*inline 효과때문에 가로세로 스타일 안먹음*/
	padding: 5px;
	border: 1px solid blue;
	background-color: yellow;
}
span.b {
	display: inline-block;/* block 요소로 변경되서 표현됨 */
	width: 100px; height: 100px;/* inline 효과때문에 가로세로 스타일 안먹는 단점을 보완할 수 있음 -> 가로세로 크기 지정 가능*/
	padding: 5px;
	border: 1px solid blue;
	background-color: yellow;
}

</style>
</head>
<body>
<!-- display 속성 
	보여지는 형식을 변환하는 속성.
	1. none : 화면에서 요소를 제거(자리도 같이 제거)
	2. block : 요소를 블록 요소로 변경
	3. inline : 요소를 인라인 요소로 변경
	4. inline-block : 요소를 인라인 요소로 변경하면서 블록 형식도 같이 가지도록 지정.
-->
<h1>The display Property</h1>
<h2>display: inline</h2>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. <span class="a">Aliquam</span> <span class="a">venenatis</span> gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet. </div>
<h2>display: inline-block</h2>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. <span class="b">Aliquam</span> <span class="b">venenatis</span> gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet. </div>
<h2>display: block</h2>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. <span class="c">Aliquam</span> <span class="c">venenatis</span> gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet. </div>

</body>
</html>

 

 

 

 

 

 

background-image.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배경 이미지</title>
<style type="text/css">
body {
	background-image: url("images/salmon.jpg"), url("images/aladin.jpg"); /* 기본으로 바둑판 배열됨. 두장 이상의 이미지를 배경으로 설정 가능 */
	background-repeat: no-repeat, repeat;
	/* 	repeat, repeat-x(x축으로만 이미지 반복), repeat-y, no-repeat */
	background-position: right top, left bottom; /* 백그라운드 이미지 위치 설정*/
	background-attachment: fixed, scroll; /* 스크롤 시에 백그라운드 위치 고정여부 */
}
</style>
</head>
<body>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
<h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1><h1>a</h1>
</body>
</html>

 

 

 

 

 

 

 

test-exam.html (실습 예제)
<!DOCTYPE HTML>
<html>
<head>
<meta charset = "utf-8">
<title>예제</title>
<style>
header {
	background-color: yellow;
	width: 100%;
	border: 2px solid blue;
	padding: 25px 2px;
}
nav {
	float: right;
	background-color: green;
	border: 1px solid red;
	width: 400px;
}
aside {
	background-color: orange;
	width: 150px;
	float: right;
	margin-top: 10px;
}
section {
	background-color: gray;
	border: 1px solid black;
	margin-top: 10px;
	margin-right: 30px;
	width: 600px;
	padding: 20px;
}
article {
	background-color: powderblue;
	width: 560px; height: 60px;
	margin: 10px;
	padding: 40px 10px 5px 10px;
	vertical-align: middle;
	border: 1px solid black;
	border-radius: 10px 10px 10px 10px;
}
footer {
	background-color: yellow;
	width: 100%;
	position: fixed;
	border: 1px dashed blue;
	bottom: 1px;
}
</style>
</head>
<body>
	<header>
		<h2>머리말 입니다.</h2>
		<nav>내비게이션 영역, 이전, 이후, 홈</nav>
	</header>
	<aside>광고입니다. 계란 사세요, 계란~~</aside>
	<section>
		<article>첫 번째 기사</article>
		<article>두 번째 기사</article>
		<article>세 번째 기사</article>
	</section>
	<footer>꼬리말 입니다. 회사 연락처 등</footer>
</body>
</html>