0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CSS でボックスを横に並べるのに top,left を使ってダメだった話

Posted at

ボタン2つを左に、黒いボックスを右に配置しようと安直に作ったら

image.png

微妙にずれているし、コンテンツが無いのに右側にスクロールバーが出てしまいました。

さくっと直しましたが一応記録。

環境

  • Google Chrome 103.0.5060.114
  • Ubuntu Linux 20.04 LTS

コード

html:

<!DOCTYPE html>
<HTML>
<HEAD>
<META CHARSET="UTF-8">
<link href="style.css" rel="stylesheet">
</HEAD>
<BODY>
<DIV class="controls">
<DIV class="button1">
<FORM ACTION=. METHOD=POST>
<INPUT TYPE=SUBMIT VALUE="" >
</FORM>
</DIV>
<DIV class="button2">
<FORM ACTION=. METHOD=POST>
<INPUT TYPE=SUBMIT VALUE="" >
</FORM>
</DIV>
</DIV>
<DIV>
<DIV class="status">
</DIV>
</DIV>
</BODY>
</HTML>

style.css:

.status{
border: 3px solid #0000FF;
width: 100px;
height: 200px;
position:relative;
background-color:#000000;
top:-200px;
left:100px;
}


.button1 input[type="submit"]{
width:100px;
height:100px;
border: 1px solid #FF0000;
border-radius: 18px;
outline:none;
box-shadow:0 0 0 0 0;
}


.button2 input[type="submit"]{
width:100px;
height:100px;
border: 1px solid #00FF00;
outline:none;
box-shadow:0 0 0 0 0;
}


としています。安直に黒のボックスを以下のように指定していますが、根本的に間違っているようです。。

top:-200px;
left:100px;

解決

top,left 指定をやめて float:left で指定しました。


.controls {
   float: left;
}
.status {
   float: left;
}
.status{
border: 3px solid #0000FF;
width: 100px;
height: 200px;
position:relative;
background-color:#000000;
}


.button1 input[type="submit"]{
width:100px;
height:100px;
border: 1px solid #FF0000;
border-radius: 18px;
outline:none;
box-shadow:0 0 0 0 0;
}


.button2 input[type="submit"]{
width:100px;
height:100px;
border: 1px solid #00FF00;
outline:none;
box-shadow:0 0 0 0 0;
}


image.png
うまくいきました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?