positionプロパティ-相対、絶対、fixed
position Property
static position
👉 例
💻 html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='out_box'>
<div class='in_box'>static position</div>
</div>
</body>
💻 css.out_box {
background-color: greenyellow;
width: 400px;
height: 400px;
position: static;
margin: 30px auto;
}
.in_box {
background-color: red;
width: 200px;
height: 200px;
position: static;
}
👀 結果relative position
👉 例
💻 html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='out_box'>
<div class='in_box'>relative position</div>
</div>
</body>
💻 css.out_box {
background-color: greenyellow;
width: 400px;
height: 400px;
position: static;
margin: 30px auto;
}
.in_box {
background-color: red;
width: 200px;
height: 200px;
position: relative;
top: 50px;
left: 30px;
}
👀 結果absolute position
👉 例
💻 html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='out_box'>
relative position
<div class='in_box'>absolute position</div>
</div>
</body>
</html>
💻 css.out_box {
background-color: greenyellow;
width: 400px;
height: 400px;
position: relative;
margin: 30px auto;
}
.in_box {
background-color: red;
width: 200px;
height: 200px;
position: absolute;
bottom: 50px;
right: 30px;
}
👀 結果fixed position
👉 例
💻 html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='out_box'>
relative position
<div class='in_box'>absolute position</div>
</div>
<div class='fixed_box'>
fixed position
</div>
</body>
</html>
💻 css.out_box {
background-color: greenyellow;
width: 400px;
height: 400px;
position: relative;
margin: 30px auto;
}
.in_box {
background-color: red;
width: 200px;
height: 200px;
position: absolute;
bottom: 50px;
right: 30px;
}
.fixed_box {
background-color: skyblue;
width: 100px;
height: 70px;
position: fixed;
top: 0;
right: 0;
}
👀 結果Reference
この問題について(positionプロパティ-相対、絶対、fixed), 我々は、より多くの情報をここで見つけました https://velog.io/@gigymi2005/position속성-relative-absolute-fixedテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol