2. CSS

CSS margin 마진 사방에 적용하기

도피디 2024. 11. 17. 20:16
반응형

1. 

<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
html {
background-color: tomato;
}
body {
margin: 20px;
background-color: thistle;
}
div {
margin-left: 50px;
height: 150px;
width: 150px;
background-color: whitesmoke;
}
</style>
</head>
<body>
<div></div>
</body>
</html>

 

margin을 하나만 적으면 사방에 적용된다.

 

 

 

결과

 

 

 


 

 

2.

<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
html {
background-color: tomato;
}
body {
margin: 20px 10px;
background-color: thistle;
}
div {
margin-left: 50px;
height: 150px;
width: 150px;
background-color: whitesmoke;
}
</style>
</head>
<body>
<div></div>
</body>
</html>

 

마진 값을 두개 넣으면 

상하 / 좌우 값으로 설정된다.

 

 

 

결과

 

 

 

반응형