div配置の問題について

このQ&Aのポイント
  • divタグの配置に関して問題が発生しており、解決策を探しています。
  • 具体的な問題として、画像上の黄色のdivを水色の隣に配置したい、赤からオレンジまでの固まりをセンターに配置したい、紫のdivにpaddingを指定してもサイズが広がってしまうなどがあります。
  • スタイルシートの設定も記載しており、問題の要点となるdivのクラスも指定しています。解決策が分かる方からのご教示をお待ちしています。
回答を見る
  • ベストアンサー

div配置のことで質問です。

div配置のことで質問です。 こんにちは。タイトル通りなのですが、divタグがうまく使えません。 いろいろなサイトを参照しましたが、解決できないのでこちらで質問させてください。 お聞きしたい事は3点あります。 (下の方に画像をつけているので参照しながらお願いします。) 1.画像上の黄色のdivくくりを水色の隣に持っていきたいということ 2.赤からオレンジまでの固まりをセンターに持っていきたいということ(横です) 3.紫のdivくくりをpadding:40;に指定すると上下左右に40pxずつ幅が広がってしまうのですが、サイズはwidth900×height500のまま内側に40px余白を作りたいということ もしおわかりになる方がいらっしゃいましたら、教えていただけると幸いです。 どうぞよろしくお願いいたします。 ■スタイルシート /*------------------------------------------------------------------ */ * { margin: 0; padding: 0; } body { text-align: center; background-color: #ffffff; } body div { margin: 0 auto; border : 0 ; } /*------------------------------------------------------------------ブロック要素 */ div.all { width: 900px; margin:0; padding: 0px; } div.aka { text-align: left; width: 900px; margin:0; padding: 0px; background-color: #ff0000; } div.murasaki { font-size:10pt ; text-align: left; width: 900px; height:300px; margin:0; padding:40px; background-color: #aaaaff; } div.mizu { font-size:10pt ; text-align: left; width: 500px; margin:0; padding:0px; background-color: #00ffff; } div.kiiro { font-size:10pt ; text-align: left; width: 400px; margin:0; padding:0px; background-color: #ffff00; } div.orange { font-size:10pt ; text-align: right; width: 900px; margin:0; padding: 0px; background-color: #ff6600; } ■ボディ内 <div class="all"> <!--ーーーーーーーー赤色--> <div class="aka"> テスト </div> <!--ーーーーーーーー紫色--> <div class="murasaki"> テスト </div> <!--ーーーーーーーー水色--> <div class="mizu"> news<br /> <table cellspacing="0" cellpadding="0" width="500"><tr><td> テスト </td></tr></table> </div> <!--ーーーーーーーー黄色--> <div class="kiiro"> topics<br /> <table cellspacing="0" cellpadding="0" width="400"><tr><td> テスト </td></tr></table> </div> <!--ーーーーーーーーフッター--> <div class="orange">テスト</div> </div> 長々とすみません。よろしくお願い致します。

  • HTML
  • 回答数1
  • ありがとう数4

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

とりあえず、CSSを修正。 3が不明です。紫は現状高さ300pxですが、500pxにしたいのでしょうか? * { margin: 0; padding: 0; } body { text-align: center; background-color: #ffffff; } div.all { text-align: left; width: 900px; margin:0 auto; } div.aka { width: 900px; background-color: #ff0000; } div.murasaki { font-size:10pt; width: 820px; height:220px; padding:40px; background-color: #aaaaff; } div.mizu { font-size:10pt ; width: 500px; float:left; background-color: #00ffff; } div.kiiro { font-size:10pt ; width: 400px; float:left; background-color: #ffff00; } div.orange { clear:left; font-size:10pt ; width: 900px; background-color: #ff6600; }

cornflakes
質問者

お礼

ありがとうございます。解決しました! 紫の高さは300にしたかったのですが、これで大丈夫です。 paddingの効果を、テーブルに使うcellspacing属性と同じだと思っていたために 3はうまくいかなかったようです。修正していただいたのを見て気づきました。 感覚でやってしまいすぎているようなので、もっとちゃんと勉強しようと思います。 ありがとうございました :-D !

関連するQ&A

  • 【CSS】floatで左右に並べた<div>のマージンが効かない。

    CSS(スタイルシート)においてfloatで2つのdivを左右に並べる方法は定番ですが、<div id="A">に設定したマージンが【firefox】でききません。 おそらく基礎的なことと思われますが、検索の仕方が悪いのか、 該当する質問を探し出すことが出来ませんでしたので、質問させていただきました。 どなたか、教えていただければと思います。 【HTML】--------------------------------- <div id="A">   <div class="B">    <h3>テキスト</h3>    <p>タイトル</p>    <table>     <tr>      <th scope="col">テキスト</th>      <td>テキスト </td>     </tr>     <tr>      <th scope="col">テキスト</th>      <td>テキスト</td>     </tr>    </table>   </div>   <div class="C" >    <h3>テキスト</h3>    <p>タイトル</p>    <table>     <tr>      <th scope="col">テキスト</th>      <td>テキスト </td>     </tr>     <tr>      <th scope="col">テキスト</th>      <td>テキスト</td>     </tr>    </table>   </div> </div> 【CSS】--------------------------------- #A {     margin-bottom:10px } #A h3{ background:url(../images/bg_h3_option_half.gif) no-repeat; width:380px; height:31px; padding:0 0 0 15px; margin:10px 0 0 0; overflow:hidden; font-size: 22px; color:#FFFFFF; font-style:normal; } #A div.B { float:left; width:380px; height: 100%; margin-right:20px; } #A div.C { float:left; width:380px; height: 100%; }

    • ベストアンサー
    • HTML
  • divタグ+CSSでのレイアウトで、Firefox, Operaで不必要な余白ができてしまいます。

    divタグ+CSSでレイアウトしようとしています。 横関係では全体がセンタリングされていて、縦関係においては、各ブロック要素間の余白がなくぴったりくっついている状態にしたいのですが、Firefox 1.0やOpera 8などを使ってレイアウトを確認すると、上下や要素間に余白が出来てしまい、なかなかうまくいきません。 以下、HTMLとCSSのソースを、レイアウトに関する部分だけ載せます。 [--HTML--] <body> <div id="all"> <div id="header"> <p>header</p> </div> <div id="body"> <p>body</p> </div> <div id="sidebar"> <p>sidebar</p> </div> <div id="footer"> <p>footer</p> </div> </div> </body> [--CSS--] @charset "shift_jis" body { margin: 0 auto; padding: 0; text-align: center; } div#all { width: 760px; background-color: blue; margin: 0 auto; padding: 0 0 20px; text-align: left; overflow: hidden; } div#header { position: relative; left: 17px; width: 717px; height: 50px; background-color: yellow; margin: 0; padding: 0; text-align: left; } div#body { position: relative; left: 17px; width: 522px; height: 200px; background-color: lime; margin: 0 0 2em; padding: 0; text-align: left; float: left; } div#sidebar { position: relative; left:32px; width: 180px; height: 200px; background-color: red; margin: 0 0 3em; padding: 0; float: left; } div#footer { position: relative; left: 17px; width: 717px; height: 100px; background-color: fuchsia; margin: 0; padding: 0; clear: both; } ---------- marginやpaddingを"0"にしているにもかかわらず、余白が生まれてしまうのはなぜなのでしょう・・?

    • ベストアンサー
    • CSS
  • IEとFireFoxでCSSの見た目をそろえたい

    CSSの素人ですがボックスを使って2カラムスタイルのデザインを作ろうとしているのですが 完成したのをみるとIEとFireFoxで見た目変わりうまく調整できずに困っています。 足し算はあっているはずなのですがどこを修正すればよいのでしょうか? HTML <body> <div id="wrapper"> <div id="container"> <div class="header"> <h1>&nbsp;</h1> </div> <div class="kaijyo"></div> <div class="main"> <div></div> <h2>&nbsp;</h2> <div class="kaijyo"></div> <div class="line"> <hr> </div> </div> <div class="menu"> </div> <div class="kaijyo"></div> <div class="footer"> <p>&nbsp; </p> </div> </div> </div> </body> CSS #wrapper{ text-align:center; /*IE対応*/ } #container { width: 980px; margin-left:auto; margin-right:auto; background-color:#CAB59B; text-align:left; } .header{ width: 970px; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 10px; background-color:#6F0011; color:#000000; text-align:left; height:20px; } .main{ width: 670px; float: left; margin: 0px 0px 0px 0px; padding: 10px 15px 10px 15px; background-color:#E4E4E4; text-align:left; } .menu{ width: 260px; float: left; margin: 0px 0px 0px 0px; padding: 10px 10px 10px 10px; background-color:#CAB59B; text-align:left; } .footer{ width: 970px; float: left; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 10px; background-color:#6F0011; color:#FFFFFF; text-align:left; } .kaijyo{ clear: left; }

    • ベストアンサー
    • CSS
  • テーブルの隙間について

    WEBのデザインを、本を読みつつ学んでいるのですが テーブルに関して疑問があるので、質問させていただきます。 【cssの中身】 /* ヘッダー */ .head { background-color:#ccc; width:100%; height:70px; margin-left:auto; margin-right:auto; } .head h1 { font-size:14px; font-family:Verdana,Osaka,MS UI Gothic,; color:#000; margin-bottom:2px; } .head td{ vertical-align:middle; } .head1 { width:40px; text-align:right; } .head2 { text-align:left; padding-right: 4px; } .date{ font-size: 12px; color: #666; font-family : Verdana,Osaka,"MS UI Gothic",serif; } /* メニュー */ .menu1 div{ float: left; } .menu{ width: 100%; background-color: #666; font-size: 12px; font-weight: bold; border-top: solid 1px white; } .menu1 div{ width: 80px; border-right: solid 1px white; text-align: center; padding-top: 5px; padding-bottom: 5px; } .menu2{ text-align: right; } .menu2 div{ margin-right: 10px; color: #fff; } .menu1 a{ color: #999; text-decoration: none; } .menu1 a:hover{ color: #fff; } 【ページの中身】 <a name="top"> <table class="head" cellspacing="0"> <tr> <td class="head1"> <img src="icon.jpg" border="0" alt="*" width="35" height="36"> </td> <td class="head2"> <h1>********</h1> </td> </tr> </table> </a> <table class="menu" cellspacing="0"> <tr> <td class="menu1"> <div><a href="link.html">Test</a></div> <div><a href="link.html">Test</a></div> <div><a href="link.html">Test</a></div> <div><a href="link.html">Test</a></div> <div><a href="link.html">Test</a></div> </td> <td class="menu2"> <div>Last update:00.00</div> </td> </table> このような形で、ヘッダーとメニューを作っているのですが、メニューの線とヘッダーとの間に1pxほどの隙間(白い部分)が出来てしまいます。これをなくすことはできないのでしょうか?メニュー部分のテーブルに cellspacing="0"を入れると隙間が無くなると本に書いていたのですが、ほんの少しだけ隙間が残ってしまいます。 宜しくお願いします。

    • ベストアンサー
    • HTML
  • スタイルシート

    #Area_Login table .tbl { margin-left: auto; margin-right: auto; border: solid 1px #FFFFFF; background-color: #000000; } #Area_Login table .tbl th { text-align: center; font-size: 12pt; background-color: #AFB4DB; height: 15px; } #Area_Login table .tbl td { text-align: center; font-size: 11pt; background-color: #AFB4DB; border: solid 1px #FFFFFF; } <div id="Area_Login"> <table class="tbl"> <tr> <th><th> <tr> <td></td> </tr> </table> </dib> 上記ソースなのですが、テーブルが中央に配置されなくて困っています。 どなたか教えていただけませんか?

    • 締切済み
    • CSS
  • DIVの入り子のwidthの指定方法

    DIVの入り子のwidthの指定方法がうまくいきません。 <css> #main { width: 770px; margin: auto; padding: 0px; text-align: left; background-color: #cc0000; } .box_main{    width: 750px;    background-color: #FFFFFF; margin: 0px 10px 10px 10px; padding: 0px; border: 0px; } .box_1{ margin: 5px 2px 5px 5px; padding: 0px; border: 0px; height: 299px; width: 236px; background: url(img/test2.jpg); float: left; } .box_2{ margin: 5px 5px 5px 0px; border: 0px; height: 295px; width: 491px; background-color: #33ff00; float: left; } .cl { clear: both; } この際、.box_mainの中にbox_1、box_2を横ならびにおきたいのですが うまくいきません。box_2のWIDTHの幅の指定がおかししのでしょうか? HTMLは<html> <body> <div id="main"> <div class="box_main"> <div class="box_corner">あああああ</div> <div class="box_1"></div> <div class=box_2></div> <div class="cl"> </div> </div> </body> </html> です。

  • DIVが二つ続いた後の下にテーブルを表示したいので

    添付はエクセルの画像ですが HTMLでDIVが二つ続いた後の下にテーブルを表示したいのですが <html> <head> <title>test</title> <style type="text/css"> <!-- div.migi, div.hidari{ float : left ; text-align:center; width:100px; background-color: #ffff00; border: 1px #BDBDBD solid; padding: 10px 6px; } div.migi{ float: right; } --> </style> </head> <body> <div class="hidari"> hidari </div> <div class="migi"> migi </div> <table border=1 cellspacing=0> <tr><td>1</td><td>2</td></tr> </table> </body> </html> このコードだとDIVの中にテーブルが入ってしまいます。 理想は添付画像です。 どうすれば良いでしょうか? よろしくお願いします。

    • ベストアンサー
    • HTML
  • テーブル内widthでの改行処理がIEとFirefoxで異なる

    テーブル内のtdに対してwidthを指定していますが、IEとFirefoxで表示が異なります。具体的には下記のコードにて、【文章1】が長い場合、IEではwidth:160pxで自動改行するのですが、Firefoxでは改行されず横に表示されてしまいます。 いちいち改行文字を入れるのはめんどうなのでFirefoxでも自動改行されるようにしたいのですが、何かうまい手をご存知の方、ご教示願います。 <スタイルシート> #contact_table table { width:600px; padding:auto; margin:auto; text-align:center; border-collapse:separate; } #contact_table tr { padding:auto; margin:auto; text-align:center; } #contact_table td { padding:5px; margin:5px; border-top:solid 2px #EEEEEE; border-left:solid 2px #EEEEEE; border-right:solid 2px #C0C0C0; border-bottom:solid 2px #C0C0C0; font-size:12px; font-weight:normal; color:#000000; text-align:left; line-height:1.5em; background:#DAEAF3; } #contact_table td.item { width:160px; white-space:nowrap; background: #000080; text-align:center; border-top:solid 2px #0000CC; border-left:solid 2px #0000CC; border-right:solid 2px #000033; border-bottom:solid 2px #000033; color:#FFFFFF; } <HTML> <div id="contact_table"> <table summary="お問い合わせ"> <tr> <td class="item">【文章1】</td> <td>【文章2】</td> </tr> <tr> <td class="item">【文章1】</td> <td>【文章2】</td> </tr> ・・・ </table> </div>

    • ベストアンサー
    • HTML
  • cssで<div>にpaddingを指定したとき

    下のように、cssで<div>にwidth720px、padding10px,background-color: #00FFFF;と指定して、 IE6とoperaで表示してみたところ、widthが740px、padding10pxになってしまいます。 divの下に740pxのテーブルをおいて確認してみました。 これは、こういうものと、思うしかないのでしょうか? また、こうなるのは、私だけなのでしょうか? <style type="text/css"> <!-- #contents { width: 720px; padding: 10px; background-color: #00FFFF; } --> </style> </head> <body> <div id="contents"> あああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ </div> <table width="740" border="0"> <tr> <td bgcolor="#0000FF">あ</td> </tr> </table> </body>

    • ベストアンサー
    • HTML
  • divの入れ子が上手くいきません。

    .line { background-image: url(../img/line.gif); background-repeat: no-repeat; background-position: left bottom; display: block; padding: 0px; clear: both; width: 600px; height:auto; margin: 0px; } .left{ width:210px; height:90px; float:left; text-align:center; padding:10px 5px 10px 0px;} .right{ width:360px; height:90px; float:left; padding:10px;} <div class="line"> <div class="left">あああ</div> <div class="right">いいい</div> </div> 上記のようにlineでleftとrightを内包したいのですが、IEでは表示されるのですが、fox・safariで確認すると画像が消えてしまいます。 どうもdivで括っているせいかline内に文字が入っていないと認識されているようで、ためしに適当な数字を入れてやると認識されました。 また、lineのheightをpx指定してやると表示されるのですが、lineは使いまわしたいクラスなので、縦を固定することができません。 どうしたら解決しますか?

    • ベストアンサー
    • HTML

専門家に質問してみよう