top、right、bottom、left は、ボックスの表示位置を指定するプロパティです。
この表示位置の指定は、position プロパティで relative、absolute、fixed を指定している場合に有効です。
div {
position: absolute;
top: 10px;
left: 30%;
}
| top | 上からの距離を指定します |
|---|---|
| right | 右からの距離を指定します |
| bottom | 下からの距離を指定します |
| left | 左からの距離を指定します |
それぞれ 数値+単位(px、他)か %(割合)で指定します。
※デフォルトは auto(自動)です。(例:left: auto)
<html>
<head>
<title>TAG index Webサイト</title>
<style type="text/css">
<!--
div {
width: 300px;
height: 100px;
background-color: #85b9e9;
position: absolute;
}
#example1 {
top: 50px;
left: 150px;
}
#example2 {
top: 200px;
left: 50px;
}
-->
</style>
</head>
<body>
<div id="example1">ボックス1</div>
<div id="example2">ボックス2</div>
</body>
</html>
▼これをブラウザで見ると次のように表示されます