• 締切済み

<DIV>タグで書いた文字が、

<DIV>タグで書いた文字が、 IEで位置を合わせるとFIREFOXではズレてしまいます。 どうしてなんでしょう? <DIV style="top : 79px;left : 55px; position : absolute; z-index : 23; width : 530px; height : 13px; " id="moji"> <P><FONT size="2">IE8とFIREFOXとでズレる</FONT></P> どうもこんな感じのプログラムで、だいたい20ピクセルぐらい下がって表示されてしまうようです。 前に同じ質問をしたのですが、うまく解決できなかったもので急いでます…

noname#176524
noname#176524

みんなの回答

回答No.2

失礼。 下記のサンプルのアタマに <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> または <html> を付けないと動作しません。 コピーし忘れでした。 Dreamweaverで5分ほどで作ったサンプルですが、何かしらの参考になればと思います。 サンプルを一歩発展させて、見た目を多少整えたものも下記に添付しておきます。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DIV分けスタイルサンプル</title> <style type="text/css"> * { margin: 0px; padding: 0px; } #container { margin: 0px auto; width: 800px; background: #9FF; } #head { margin-top: 10px; margin-bottom: 10px; padding: 20px; } #navi { float: left; width: 180px; background: #FFC; padding: 10px; margin-bottom: 20px; } #contents { float: right; width: 580px; background: #FFF; padding: 10px; margin-bottom: 20px; } #foot { clear: both; text-align: center; padding: 10px; margin-bottom: 20px; } #navi ul { list-style: none; } #navi li { line-height: 2em; } #contents h2 { margin-bottom: 20px; } #contents p { line-height: 1.6em; font-size: 1em; } </style> </head> <body> <div id="container"> <div id="head"> <h1>見出し1(サイトのタイトル)</h1> </div> <div id="wrapper"> <div id="navi"> <ul> <li><a href="#">メニュー1</a></li> <li><a href="#">メニュー2</a></li> <li><a href="#">メニュー3</a></li> </ul> </div> <div id="contents"> <h2>見出し2(記事タイトル)</h2> <p>記事はここに書いていきます。</p> <p>記事はここに書いていきます。</p> </div> </div> <div id="foot"> <p>Copyrights&copy;2010 JIBUN-NO-NAMAE. All rights reserved.</p> </div> </div> </body> </html>

noname#176524
質問者

お礼

これはこれは大変丁寧な回答ありがとうございます。 プログラムはまだあまりわかりませんが、 さっそくなんとか解読して研究してみます。 上手く言ったらベストアンサーにさせていただきます。 ありがとうございました<(__)>

回答No.1

divを、z-indexでレイヤーを付け、positionで位置指定をしているために起こる現象です。 ブラウザの仕様の違い、と思ってもいいですね。 Webページ作りでは、表示ブラウザごとに処理を分岐させる方法でブラウザの仕様の違いに対応させるか、どのブラウザで見ても共通の表示になるようにスタイルを作るか、どちらかの方法しかありません。 このため、z-indexとpositionを使っている限りはうまくいかないと思って下さい。 どのブラウザで見ても共通の表示になり、尚且つ最も理解しやすく解りやすいコーディングの仕方に「div分け」という方法があります。 これはz-indexは使いませんし、画像の表示位置くらいにしかpositionも登場しません。 divでセクションをくくって、marginとpaddingで細かな位置を調整していく、という方法。 下記はmarginもpaddingも入れていないサンプルですが、メニューが左側に、コンテンツがその右側に来て、タイトル部分とコピーライト部分は上下に配置された、常に画面の中央に表示されるようにしている、最も基本的なdiv分けのスタイルです。 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DIV分けスタイルサンプル</title> <style type="text/css"> #container { margin: 0px auto; width: 800px; background: #9FF; } #navi { float: left; width: 200px; background: #FFC; } #contents { float: right; width: 600px; background: #FFF; } #foot { clear: both; } </style> </head> <body> <div id="container"> <div id="head"> <h1>見出し1(サイトのタイトル)</h1> </div> <div id="wrapper"> <div id="navi"> <ul> <li><a href="#">メニュー1</a></li> <li><a href="#">メニュー2</a></li> <li><a href="#">メニュー3</a></li> </ul> </div> <div id="contents"> <h2>見出し2(記事タイトル)</h2> <p>記事はここに書いていきます。記事はここに書いていきます。</p> </div> </div> <div id="foot"> <p>Copyrights&copy;2010 JIBUN-NO-NAMAE. All rights reserved.</p> </div> </div> </body> </html> ホームページビルダーを使うとやりづらいこの方法も、Dreamweaverならばサクサク作れてしまうスタイルです。 一応は、プロが教えるホームページ作りの基礎中の基礎になってくるスタイルつくりの基本部分です。 単純に見えますが、この方法だと3段組み、4段組みも可能ですし、メニューを横に配置することもラクですし、なによりもほとんどのブラウザで表示が共通になります。 バグだらけブラウザのIE6やIE7などではたまに崩れる場合もありますけれども、それでもほとんどの場合大丈夫だったりします。 上記のHTMLをメモ帳などにコピーして、htmlとして保存して表示させてみると、全体が水色で、その中に黄色の背景のメニュー、白い背景の本文、というスタイルで表示されるはずです。 このdiv分けを駆使することで、もっともっと複雑なスタイルが組めます。

関連するQ&A

  • タグの修正に力をかしてください

    ホットペッパーに出てくるお店のページのバナーのように、 「アクセス」「TEL」の文字を表示させたいのですがうまくいきません。 タグの修正にちからをかしていただけないでしょうか。 以下、タグです。よろしくおねがいします。 <table width="702" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="color3" colspan="3"><img src="images/spacer.gif" alt="" width="1" height="1"></td> </tr> <tr> <td class="color3"><img src="images/spacer.gif" alt="" width="1" height="1"></td> <div style="position:relative;"><img src="images/hotpot_bannar.gif" alt="バナー" width="700" height="151"></div> <div style="position:absolute; top:70px; left:400px; color:#ffffff; font-size:10px; border:solid 1px; padding:2px;">アクセス</div> <div style="position:absolute; top:50px; left:450px; color:#ffffff; font-size:10px;>JR環状線:「福島駅」・・・</div> <div style="position:absolute; top:70px; left:450px; color:#ffffff; font-size:10px;>JR東西線:「新福島駅」・・・</div> <div style="position:absolute; top:120px; left:400px; color:#ffffff; font-size:10px; border:solid 1px; padding:2px;">TEL</div> <div style="position:absolute; top:120px; left:450px; color:#ffffff; font-size:10px;>06-****-****</div> <td class="color3"><img src="images/spacer.gif" alt="" width="1" height="1"></td> </tr> </table>

    • ベストアンサー
    • HTML
  • CSSのdivで、ページ全体をセンタリング出来ない

    質問させて頂きます。 <style type="text/css"> #contena { margin-right: 10px; margin-left: 10px; text-align: center; height: 900px; width: 950px; } </style></head> というように、全体をdivで囲んだにもかかわらず、何故かセンタリング出来ません。 最も簡単に、このページをセンタリングするには、どうすればよいでしょうか? ホームページビルダーで「どこでも配置モード」で作ったものを、dreamweaverで作り直す場合に該当します。 下記にHTMLを記載しておきます。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta name="IBM:HPB-Input-Mode" content="mode/flm; pagewidth=750; pageheight=900"> <meta name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 14.0.8.0 for Windows"> <title>タイトル</title> <style type="text/css"> #contena { margin-right: 10px; margin-left: 10px; text-align: center; height: 900px; width: 950px; } </style></head> <body background="blue_p7b.gif"> <div id="contena"> <div style="top : 0px;left : 20px; position : absolute; z-index : 20; " id="Layer22"><img src="anim.gif" width="373" height="93" border="0" alt="ようこそ"></div> <div style="top : 18px;left : 575px; position : absolute; z-index : 2; " id="Layer4"><a href="http://www.dodgeball.or.jp/"><img src="jdba1.gif" border="0" width="106" height="30"></a></div> <div style="top : 60px;left : 143px; position : absolute; z-index : 1; " id="Layer1"><img src="logo111.gif" width="488" height="69" border="0" alt="リンク"></div> <div style="top : 219px;left : 317px; position : absolute; z-index : 27; width : 580px; height : 51px; " id="Layer28"> <p><font color="#0000ff" size="+2">コンテンツ</font></p> </div> <div style="top : 161px;left : 647px; position : absolute; z-index : 22; " id="Layer23"></div> <div style="top : 255px;left : 284px; position : absolute; z-index : 28; " id="Layer2"><img src="frendlyindx.gif" width="546" height="410" border="0"></div> <div style="top : 216px;left : 652px; position : absolute; z-index : 23; " id="Layer24"></div> <div style="top : 304px;left : 50px; position : absolute; z-index : 26; " id="Layer27"></div> <div style="top : 754px;left : 47px; position : absolute; z-index : 19; width : 707px; height : 154px; " id="Layer21"><iframe frameborder="1" src="saishijoho.html" width="709" height="150" scrolling="AUTO"></iframe></div> <div style="top : 953px;left : 40px; position : absolute; z-index : 7; " id="Layer9"><a href="taikaikekka.html"><img src="button41.gif" width="57" height="54" border="0" alt=" "></a></div> <div style="top : 659px;left : 48px; position : absolute; z-index : 6; " id="Layer8"><img src="logo1.gif" width="194" height="65" border="0" alt="最新情報 "></div> <div style="top : 1020px;left : 34px; position : absolute; z-index : 12; </div> </body> </html> 詳しい方がいましたら、よろしくお願いします。

  • float: leftで横に並べたら、サファリだけ

    float: leftで横に並べたら、サファリだけ隙間が空いてしまいます。 IEやファイヤーフォックスではピッタリ表示できています。 問題の箇所は以下です。 <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-001.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト1</span> </p> </div> <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-002.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト2</span> </p> </div> <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-003.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト3</span> </p> </div> どうすればサファリの隙間を消せるでしょうか?

    • ベストアンサー
    • HTML
  • IE6,7で画像の上に載せた文字がずれる

    HTMLなのですが、 画像が縦に3つつながって1つの画像のようになった状態で表示しようとしています。 さらに上と下の画像にはテキストを上にかぶせて表示します。 画像全体にリンクを貼ってあります。 下記のようなコードで作成した所、IE6,7でのみ、下記のバグが出てしまいました。 ・画像とテキストの縦位置のズレ ・画像間に2px程度の空白が生じる ・画像に設定したリンクが開かない 大変困っています。 どなたか原因と修正方法を教えていただけますでしょうか。 <a href="test.html"> <div style="position: relative; width: 183px; height: 265px; "> <img src="images/top.jpg" width="183" height="36" /> <div style="position: absolute; top: -11px; left: 55px;" class="font16b"> <p align="center">text1</p> </div> <img src="images/main.jpg" width="183" height="193" border="0" /> <img src="images/bottom.jpg" width="183" height="36" /> <div style="position: absolute; top: 218px; left: 4px; width: 181px;" class="font13"> <p align="left">text2</p> </div> </div> </a>

    • ベストアンサー
    • CSS
  • firefoxでdivタグの体裁崩れ

    お世話になります。 以下のソースを IEで見るとリスト1、リスト2は同じ内容が表示されます FireFoxで見るとリスト2のlist3が左側につめられて表示されます。 ・これはIE or FireFoxのバグになるのでしょうか? ・IEと同じようにFireFoxで表示したいのですが出来ますでしょうか? 申し訳ありませんがご教授よろしくお願いいたします。 <html> <title>DIVタグテスト</title> <body> DIVタグテスト<br> <br> リスト1 <div style="width:300px;"> <div style="float:left;width:100px;"> <div style="width:100px;"> <div>list1</div> </div> </div> <div style="float:left;width:100px;"> <div style="width:100px;"> <div>list2</div> </div> </div> <div style="float:left;width:100px;"> <div style="width:100px;"> <div>list3</div> </div> </div> </div> <br> <br> リスト2 <div style="width:300px;"> <div style="float:left;width:100px;"> <div style="width:100px;"> <div>list1</div> </div> </div> <div style="float:left;width:100px;"> <div style="width:100px;"> <div></div> </div> </div> <div style="float:left;width:100px;"> <div style="width:100px;"> <div>list3</div> </div> </div> </div> </body> </html>

    • ベストアンサー
    • HTML
  • このタグですが、左右一杯に広がったまま、左方向にページを伸縮しても

    このタグですが、左右一杯に広がったまま、左方向にページをちじめても、左右にページ一杯のまま、伸縮するようになりませんか? <BODY> <DIV style="top : 0px;left : 0px; position : absolute; z-index : 1; " id="Layer1"> <DIV> <TABLE> <TBODY> <TR> <TD bgcolor="#ffcccc" height="130" width="750"></TD> </TR> </TBODY> </TABLE> </DIV> </DIV> <DIV style="top : 41px;left : 151px; position : absolute; z-index : 2; width : 397px; height : 43px; " id="Layer2" align="center"><FONT size="+3">テキスト</FONT></DIV> </BODY>

    • ベストアンサー
    • HTML
  • このタグですが、ページを右端から左へ縮めても、常に中央に位置させたいのですが、、

    このタグですが、ページを右端から左へ縮めても、常に中央に位置させたいのですが、、、 <BODY> <DIV style="top : 56px;left : 95px; position : absolute; z-index : 1; width : 336px; height : 21px; " id="Layer1" align="center"><FONT size="+4">テキスト</FONT></DIV> </BODY>

    • ベストアンサー
    • HTML
  • <P>タグと<div>タグについて

    <P>タグと<div>タグには“前後に空行が入るかどうか”という違いがあるそうですが、下記のようなデータを作り、自分のホームページに記入したところ、前後に全く空行が入りませんでした。 しかし、自分のホームページ以外で、このデータを試してみたところ、<p>タグにはきちんと空行が入るようです。 記入する場所によって、空行が入ったり入らなかったりするのは、なぜなのでしょうか? ※ブラウザはIE8を使用しています。 <P align="right" style="width:740px;margin:auto;">●●●</p> <P align="right" style="width:740px;margin:auto;">●●●</p> <P align="right" style="width:740px;margin:auto;">●●●</p> <div align="right" style="width:740px;margin:auto;">▲▲▲</div> <div align="right" style="width:740px;margin:auto;">▲▲▲</div> <div align="right" style="width:740px;margin:auto;">▲▲▲</div>

  • divが思うように使いこなせず困っています。

    divが思うように使いこなせず困っています。 下記のようにした場合、背景色や、width:100; height:100の指定は無視されてしまいます。 (動作確認はfirefox3でしています) width:100; height:100と指定していてもサイズが小さければ小さくなってしまうのでしょうか。 サイズの固定方法と、一番外のdivを効かせる方法をどなたか教えていただけますか? <div style="min-height:50; width:200; background-color:#FFFF00;"> <div style="width:200; height:100; float:left"> <p>testtest</p> <p>testtest</p> </div> <div style="width:100; height:100; float:left"> <p>testtest</p> <p>testtest</p> </div> </div>

    • ベストアンサー
    • SEO
  • 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