자주 쓰이는 CSS 연습하기
2023. 2. 19. 18:34ㆍsparta_codingclub
728x90
1. 자주 쓰이는 CSS 연습하기
「연습할 것들: h1, h5, background-image, background-size, background-position color, width, height, border-radius, margin, padding」
• 로그인 페이지 만들기

• margin과 padding 헷갈리지 않기
- margin은 바깥 여백을, padding은 내 안쪽 여백을 의미함
• 완성 코드
<!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>
.mytitle {
background-color: green;
width: 300px;
height: 200px;
border-radius: 10px;
color: white;
text-align: center;
padding: 30px 0px 0px 0px;
background-image: url('https://www.ancient-origins.net/sites/default/files/field/image/Agesilaus-II-cover.jpg');
background-position: center;
background-size: cover;
}
</style>
</head>
<body>
<div class="mytitle">
<h1>로그인 페이지</h1>
<h5>아이디, 비밀번호를 입력하세요</h5>
</div>
<p>ID : <input type="text" /></p>
<p>PW : <input type="text" /></p>
<button>로그인하기</button>
</body>
</html>
2. 만들어둔 로그인 화면을 가운데로 가져오려면?
- 박스 씌우고 양쪽 여백 조정하기. 즉, 전체 div를 만들고, width를 주고 margin: auto 사용하기

• 완성 코드
<!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>
.mytitle {
background-color: green;
width: 300px;
border-radius: 10px;
color: white;
text-align: center;
padding: 30px 0px 0px 0px;
background-image: url('https://www.ancient-origins.net/sites/default/files/field/image/Agesilaus-II-cover.jpg');
background-position: center;
background-size: cover;
}
.wrap {
width: 300px;
margin: 20px auto 0px auto;
}
</style>
</head>
<body>
<div class="wrap">
<div class="mytitle">
<h1>로그인 페이지</h1>
<h5>아이디, 비밀번호를 입력하세요</h5>
</div>
<p>ID : <input type="text" /></p>
<p>PW : <input type="text" /></p>
<button>로그인하기</button>
</div>
</body>
</html>
'sparta_codingclub' 카테고리의 다른 글
주석 (0) | 2023.02.22 |
---|---|
구글 폰트 사용하기 (0) | 2023.02.22 |
CSS 기초 (0) | 2023.02.19 |
HTML과 CSS (0) | 2023.02.18 |
웹 브라우저 원리 (0) | 2023.02.16 |