CSS독학3(배경)
요소의 위치 설정
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>여백 설정하기</title>
<style>
div{width:300px;height:100px;background-color:skyblue;border:2px groove #ff0000;border-radius:10px;padding:50px}
</style> 굵기 선스타일 색값
</head>
<body>
<div>
</div>
</body>
</html>
1.외곽선 주기 div{border: 굵기 선스타일 색값}
선스타일
- solid : 그냥 한줄
- dotted : 점으로 표현.
- dashed : 점선으로 표현.
- double : 두 줄로 표현.
- groove : 입체감 있게 표현.
- ridge : 볼록하게 표현.
- inset : 들어가 보이게 표현
- outset : 튀어나오게 표현
2.모서리를 둥굴게 하기 div{border-radus:값}
값이 클수록 더 둥근모양으로 변한다.
3.이미지를 배경으로 넣기 div{background-image:url('주소');}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>배경꾸미기</title>
<style>
div{width:500px;height:300px;
background-image:url('star.jpg');
border:2px groove #ff0000;border-radius:10px}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>여백 설정하기</title>
<style>
div{width:1000px;height:700px;
background-image:url('maltese.jpg');
background-repeat:no-repeat;
border:2px groove #ff0000;
border-radius:10px;
background-position:center center}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
4.이미지 반복 설정 div{background-repeat:값}
- repeat:가로와 세로로 계속 반복
- no-repeat: 한번만 나타남
- repeat-x:가로 방향으로 반복
- repeat-y:세로 방향으로 반복
5.백그라운드 위치 설정
div{background-position:가로값 세로값}
- 가로값 : left center right %
- 세로값: top center botton %
6.스크롤바 생성시키기(text가 길때)
div{overflow:값}
- scroll:스크롤바 생김
- hidden:넘어가는 부분 표현되지 않고 숨김으로 변함
7.배경이미지를 고정 여부 컨트롤
div{background-attachment:값}
- scroll 스크롤하면 배경그림도 스크롤
- fixed 스크롤해도 배경이 그대로 그 위치에 있음
배경에 그라디언트 효과 적용
- background:linear-gradient(시작하는 색,끝나는 색)
- background:radial-gradient(시작하는 색,끝나는 색)
linear-gradient
<body>
<div style="background:linear-gradient(skyblue,hotpink);width:300px;height:100px"></div>
</body>
<body>
<div style="background:radial-gradient(skyblue,hotpink);width:300px;height:100px"></div>
</body>
박스에 그림자 전용
box-shadow:가로 세로 번짐 효과 그림자색
<body>
<div style="background:radial-gradient(skyblue,hotpink);
width:300px;height:100px;
box-shadow:10px 10px 10px lightpink"></div>
</body>
visibility
- visibility:visible(표시)
- visibility:hidden(숨김)
- visibility:inherit(부모 태그의 값)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>visibility</title>
<style>
b{visibility:hidden}
</style>
</head>
<body>
<b>b tag - pinkcoding</b>
<p>p tag - pinkcoding</p>
</body>
</html>
hidden vs none
hidden에서 b태그는 보이지 않지만 레이아웃에 영향미침
none에서 b태그는 보이지 않고 레이아웃에 영향 미치치 않음
외곽선 border:선굵기 선스타일 색
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>외곽선</title>
- <style>
- div{width:200px;height:50px;margin-top:10px}
- .solid{border:4px solid #cccccc}
- .dotted{border:4px dotted #cccccc}
- .dashed{border:4px dashed #cccccc}
- .double{border:4px double #cccccc}
- .groove{border:4px groove #cccccc}
- .ridge{border:4px ridge #cccccc}
- .inset{border:4px inset #cccccc}
- .outset{border:4px outset #cccccc}
- </style>
- </head>
- <body>
- <div class="solid">solid</div>
- <div class="dotted">dotted</div>
- <div class="dashed">dashed</div>
- <div class="double">double</div>
- <div class="groove">groove</div>
- <div class="ridge">ridge</div>
- <div class="inset">inset</div>
- <div class="outset">outset</div>
- </body>
- </html>
input 태그 외곽선 없애기 input{outline:none}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS의 outline속성 적용</title>
<style>
input{outline:none}
</style>
</head>
<body>
<input type="text" value="input" />
</body>
</html>
흐름조정
float:right
float:left
float:none
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>float</title>
- <style>
- div{float:left;width:50px;height:50px;margin:10px;border:1px solid #000000}
- </style>
- </head>
- <body>
- <div>box 1</div>
- <div>box 2</div>
- <div>box 3</div>
- </body>
- </html>
흐름조정 없애기 clear
- clear:left float 속성값이 left가 적용된 박스 아래에 위치
- clear:right float 속성값이 right가 적용된 박스 아래에 위치
- clear:both left,right 상관없이 적용된 박스 아래에 위치
<style>
div{float:right;width:50px;height:50px;margin:10px;border:1px solid #000000}
.box2{clear:left}
</style>
<body>
<div>box 1</div>
<div class="box2">box 2</div>
<div class="box3">box 3</div>
</body>

<style>
div{float:right;width:50px;height:50px;margin:10px;border:1px solid #000000}
.box2{clear:right}
</style>
<style>
div{float:both;width:50px;height:50px;margin:10px;border:1px solid #000000}
.box2{clear:left}
</style>

CSS리셋
- @charset "UTF-8";
- body,button,dd,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,input,legend,li,ol,p,select,table,td,textarea,th,ul{margin:0;padding:0}
- body,button,input,select,table,textarea{font-size:12px;font-family:Dotum,'돋움',Helvetica,"Apple SD Gothic Neo",sans-serif}
- button,input{border-radius:0}
- fieldset,img{border:0}
- ol,ul{list-style:none}
- address,em{font-style:normal}
- a{text-decoration:none}
- a:hover{text-decoration:underline}
- iframe{overflow:hidden;margin:0;padding:0;border:0}
네이버에서 가져온 리셋 코드
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>텍스트 사이즈 조정</title>
<link rel="stylesheet" href="reset.css">
<style>
p{font-size:50px}
</style>
</head>
<body>
<p> hello world </p>
</body>
</html>
원래 margin값이 설정
reset.css로 인해 margin,padding값이 0으로 되었다.
CSS애니메이션
- 선택자{animation:키프레임 이름, 시간, 반복 횟수}
- @keyframes 키프레임 이름{
- from{시작할 CSS 속성 값)
- to{끝날 CSS 속성 값}
- }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS 애니메이션 </title>
<link rel="stylesheet" href="reset.css">
<style>
.move{width:100px;height:50px;background:pink;position:relative;
animation: move 3s 1}
@keyframes move {
from{
left:0
}
to{
left:1000px
}
}
</style>
</head>
<body>
<p class="move"> hello world </p>
</body>
</html>
- 선택자{animation:키프레임 이름, 시간, 반복 횟수}
- @keyframes 키프레임 이름{
- from{시작할 CSS 속성 값)
- 10%{10% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 20%{20% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 30%{30% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 40%{40% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 50%{50% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 60%{60% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 70%{70% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 80%{80% 정도의 진행 상황에 적용할 CSS 속성과 값}
- 90%{90% 정도의 진행 상황에 적용할 CSS 속성과 값}
- to{끝날 CSS 속성 값}
- }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS 애니메이션 </title>
<link rel="stylesheet" href="reset.css">
<style>
.move{width:100px;height:80px;border-radius:20px;background:pink;position:relative;
animation: move 3s infinite}
@keyframes move {
from{
left:0
}
10%{width:100px;height:100px;left:100px}
35%{width:200px;height:200px;left:200px}
60%{width:300px;height:300px;left:300px}
75%{width:200px;height:200px;left:200px}
95%{width:100px;height:100px;left:100px}
to{
left:0px
}
}
.move p{float:left;width:100%;text-align:center;margin:20px 0 0 0;font-size:30px;color:#fff;
font-weight:bold}
</style>
</head>
<body>
<div class="move"> <p>animation</p></div>
</body>
</html>
각도조정 transform:rotate(각도deg)
transform:rotateX(값) 또는 rotateY(값)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>박스 각도 변경</title>
<link rel="stylesheet" href="./cssReset.css">
<style>
.transform{width:100px;height:100px;margin:50px;background:pink;transform:rotate(40deg)}
</style>
</head>
<body>
<div class="transform"> rotate(40deg) </div>
</body>
</html>
기울이기 선택자{transform:skew(가로 기울기 각도, 세로 기울기 각도)}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>기울이기</title>
<link rel="stylesheet" href="./cssReset.css">
<style>
.box{float:left;width:100px;height:100px;margin:10px;background:skyblue}
.box1{transform:skew(30deg, 0deg)}
.box2{transform:skew(0deg, 30deg)}
.box3{transform:skew(30deg)}
</style>
</head>
<body>
<div class="box box1"> skew(30deg,0deg) </div>
<div class="box box2"> skew(0deg,30deg)</div>
<div class="box box3"> skew(30deg)</div>
</body>
</html>
트랜지션
선택자{transition:적용할 CSS 속성, 지속 시간, 표현효과종류}
선택자:hover{transition에 사용할 속성}
표현효과종류
- linear:일정한 속도
- ease: 느리게 -> 빠르게 -> 느리게
- ease-in : 시작 시 느리게
- ease-out : 종료 시 느리게
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>트랜지션</title>
<link rel="stylesheet" href="reset.css">
<style>
.transform{width:100px;height:100px;margin:50px;background:pink;transform:rotateX(0deg);transition:all 5s linear}
.transform:hover{transform:rotateX(50deg)}
</style>
</head>
<body>
<div class="transform"> transition </div>
</body>
</html>
- <style>
- .transform{width:100px;height:100px;margin:50px;background:pink;
- transform:rotateX(0deg);transition:width 5s linear}
- .transform:hover{transform:rotateX(50deg);width:400px}
- </style>
all: hover에 작성된 모든 속성이 바뀜
width:100px -> 400px 5s
<style>
.transform{width:100px;height:100px;margin:50px;background:pink;
transform:rotateX(0deg);transition:width 5s linear, background 8s ease-in}
.transform:hover{transform:rotateX(50deg);width:400px;background:blue}
</style>
width:100px -> 400px 5s
background :pink -> blue 8s
display
p태그 :block방식 태그
b태그 :inline방식 태그
display:값
- block
- inline
- inline-block
- none
display:block
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>inline block</title>
<link rel="stylesheet" href="Reset.css">
<style>
b{background:pink;display:block}
</style>
</head>
<body>
<b> b태그(inline) ->display:block </b>
<b> b태그(inline) ->display:block </b>
<b> b태그(inline) ->display:block </b>
</body>
</html>
display:inline
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>inline block</title>
<link rel="stylesheet" href="reset.css">
<style>
p{background:blue;display:inline;margin:0 10px;width:100px;height:100px}
</style>
</head>
<body>
<p> p태그(block) ->display:inline </p>
<p> p태그(block) ->display:inline </p>
<p> p태그(block) ->display:inline </p>
</body>
</html>
자신의 크기만 차지하므로 width , height 속성 적용 X
display:inline-block
inline 자신의 크기를 가지면서도 width,height속성이 설정되어 있는 경우 block과 마찬가지로 크기를 따름
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>inline block</title>
<link rel="stylesheet" href="reset.css">
<style>
p{background:blue;display:inline-block;margin:0 10px;width:100px;height:8px}
</style>
</head>
<body>
<p> p태그(block)->display:inline-block </p>
<p> p태그(block)->display:inline-block </p>
<p> p태그(block)->display:inline-block </p>
</body>
</html>
width,height적용O
none
해당 태그 X ,레이아웃에 영향 X
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>inline block</title>
<link rel="stylesheet" href="reset.css">
<style>
p{background:blue;display:none}
</style>
</head>
<body>
<p> p태그(block)->display:none </p>
<p> p태그(block)->display:none </p>
<p> p태그(block)->display:none </p>
<b> display:none으로 b태그만 있음 </b>
</body>
</html>