position relativeのの正しい使い方を把握できていないため重なってしまったり。理想的な場所に配置されません。適用されておりません。
行いたいことは
main-rightの中の
box-a
box-b
box-c
を綺麗に配置させたいです。
3つのboxは色形right40px left60px空けるまでは同じです。
aは上から40px空けたところ
bはaから10px空けたところ
cはbから10px空けたところかつ下から40px空けたところに配置したいです。
よろしくおねがいします。
HTML
<!DOCTYPE html> <html lang="ja" > <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="reset.css"> </head> <body> <div class="wrapper"> <div class="header"></div> <div class="main clearfix"> <div class="main-left"> </div> <div class="main-right clearfix"> <div class="box-a box"></div> <div class="box-b box"></div> <div class="box-c box"></div> </div> </div> <div class="footer"></div> </div> </body> </html>
CSS
body { margin: 0; } .wrapper { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 400px; height: 450px; margin: auto; } .clearfix::after { content: ""; display: block; clear: both; } .header { background-color: #141f40; height: 100px; width: 400px; } .main { height: 250px; width: 400px; } .main-left { height: 250px; width: 150px; background-color: #80bfa8; float: left; } .main-right { height: 250px; width: 250px; background-color: #8c2727; float: left; } .box{ background-color: #ff863f; width: 140px; height: 40px; position: relative; left: 40px; right: 60px; border-style: solid; border-width: 5px; border-color: #FFFFFF; } .box-a{ position: relative; top: 40px; bottom: 160px; } .box-b{ position: relative; margin: 10px 0px; } .box-c{ position: relative; top: 10px; bottom: 40px; } .footer { height: 100px; background-color: #d98d30; width: 400px; }
https://teratail.com/questions/208145 この質問と内容がほぼ同じです。teratailは質問内容の編集ができるので、変更がある場合は新しい質問をするのではなく編集してください。また、こちらの質問を削除されるよう運営に連絡されることをお勧めします。 https://teratail.com/help#delete-question https://teratail.com/contact/input
まだ回答がついていません
会員登録して回答してみよう