• ベストアンサー

cssのfloatについて質問です。

cssでfloatを使い3カラムで表示しています。 クラスは左からleft,centre,rightと振っています。 やりたいことはウィンドウサイズを縮めた時にカラム落ちするのではなく、 rightのdivをlefr,centreの下に潜り込ませたいです。 イメージ的にはleft,centreのz-indexが1に対し、rightが0で下に入るように縮めたいです。 できればpositionは使いたくないです。 flexboxでも試してみましたが、比率が変わりいい感じに縮むのですが、下に潜り込ませることはできませんでした。 もしなにかアドバイスがあれば宜しくお願い致します。

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

  • ベストアンサー
  • hok212
  • ベストアンサー率66% (100/150)
回答No.1

やはりpositionを使うべき場面だと思いますが、何らかの理由で使えないのであれば、 こんな感じでしょうか。 ============== ソース (ここから)==================== <!DOCTYPE HTML> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style> html, body { margin:0; padding:0; } #wrap { width:100%; } #wrap div { height:200px; float:left; } #left, #center, #rightInner { width:300px; } #left { background-color:#f00; } #center { background-color:#090; } #right { width:calc(100% - 600px); background-color:#00f; overflow:hidden; } @media only screen and (max-width: 900px) { #rightInner { margin-left:calc(100% - 300px); } } </style> </head> <body> <div id="wrap"> <div id="left"></div> <div id="center"></div> <div id="right"><div id="rightInner">ああああああああああああああああああああああああああああああああああああああああああああああ</div></div> </div> </body> </html> ============== ソース (ここまで)==================== ※上記のソースをコピペして実際の動きを確認してください。 ウィンドウ幅が900px以下で、#right(背景色青)の領域内の「あああ・・・」の文字が#center(同緑)の領域の下に潜り込むような感じになります。 実際は潜り込んでいるのではなく、親要素のoverflow:hidden; と 子要素のmargin-leftを調整することで、擬似的にそのように見せかけているだけです。

shiro857
質問者

補足

なるほど。こういうような手があったのですね。 思いつかなかったです。勉強になりました。 少し試してみてもしまた何か質問があればよろしくお願いします。

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (1)

  • gahyu
  • ベストアンサー率50% (3/6)
回答No.2

display: flex; flex: 0 0 1; とかflexを当ててみるのはどうでしょうか

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • cssのfloatについて

    cssのfloatを使い横並びを実現していますがoverflowを利用して横並びを実現するという方法を聞きました。 現状の構成は具体的に以下のような感じです。 <div id="main"> <div id="left">レフト</div> <div id="center">センター</div> </div> #main:after { content: "."; display: block; visibility: hidden; height: 0.1px; font-size: 0.1em; line-height: 0; clear: both; } #left {float: left;} #center { float: right} これをoverflowで実現するにはどうすればいいのでしょうか? また、floatを使用しないで実現するメリットはなんでしょうか?

    • ベストアンサー
    • HTML
  • cssのfloatについて質問があります。

    cssのfloatについて質問があります。 floatがなかなか理解できずに悩んでおります。 下記のようなcssがあり、同じブロック要素でも table,pなどは右に回りこみ、divボックスはfloatを指定しないと floatボックスの下に入ってしまうのをなんか理解できません。 初歩的なことかもしれませんが、 どなたかアドバイスいただけると助かります。 宜しく尾根会い致します。 <html lang="ja"> <head> <title></title> <style type="text/css"> #con { width: 800px; border: solid 1px black; } .left { width: 300px; height: 300px; float: left; border: solid 1px blue; } .right { width: 200px; height: 200px; border: solid 1px red; } table { width: 100px; height: 100px; border: solid 1px green; } p { border: solid 1px yellow; } </style> </head> <body> <div id="con"> <div class="left"> </div> <table> <tr><td>TABLE</td></tr> </table> <p>ppppp</p> <div class="right"> </div> </div> </body> </html>

    • ベストアンサー
    • HTML
  • CSSで、何故か、「float」が上手く効かない

    詳しく書きますと、前回した質問、 http://okwave.jp/qa/q7786505.html の続きになります。 ちなみにこれは、今の所、解決した次第です。 しかし、新たな場面に直面している最中であります。 http://sky.geocities.jp/thanksv0358/index.html# 質問は、上記で作成しているページについてです。 その内容ですが、ページ中程にある「 今月のおすすめ 」とある、すぐ下の「 見出し3 」という2つの項目を先頭行にして、横一列にそろえて表示したいと思いました。 そのため、項目内容をHTMLで、 <div class="left"> ~ </div> と、 <div class="right"> ~ </div> で囲い、その後、それぞれをCSSで、 .left{ float:left; } .right{ float:right; } としたにもかかわらず、何故か中途半端な形で、ずれている状態が確認できます。 これが現在、意味不明な箇所になっています。 ここで質問ですが、この場合、どうすれば「 見出し3 」の文字2つを並列に表示できますでしょうか? 詳しい方がいましたら、よろしくお願いします。

  • 3カラムのサイトでfloatができない

    3カラムのホームページを作っているのですが、 中央と右のカラムがどうしてもfloatできません。。 左カラムをfloat:leftにして、中央と右のカラムを#contentsBoxで囲ってfloat:rightさせています 【HTML】 <div id="wrapper_2"><!--div id wrapper_2 START--> <div id="contentsBox"><!--div id contentsBox START--> <div id="560"><!--div id 560 START--> 中央カラム     </div><!--div id 560 END--> <div id="175"><!--div id 175 START-->     右カラム </div><!--div id 175 END--> </div><!--div id contentsBox END--> <div id="205"><!--div id 205 START-->     左カラム </div><!--div id 205 END--> </div><!--div id Wrapper_2 END--> 【CSS】 /*+++wrapper_2++++++++++++++++++++++++++*/ #wrapper_2 { width: 984px; background-color:#fff; padding: 8px; margin: 10px auto 10px auto; overflow: hidden; } /*+++contentsBox++++++++++++++++++++++++++*/ #contentsBox { width: 757px; float: right; } #contentsBox:after { height: 0; visibility: hidden; content: "."; display: block; clear: both; } /*+++左カラム+++++++++++++++++++++++++++++*/ #205{ width: 205px; margin: 0 22px 0 0; float: left; } /*+++中カラム+++++++++++++++++++++++++++++*/ #560{ width: 560px; float: left; } /*+++右カラム+++++++++++++++++++++++++++++*/ #175{ width: 175px; float: right; margin-left: 22px; } まだ勉強中なので、初歩的なミスなのかもしれませんが、 どうしても中央カラムの下に右カラムがきてしまいます。 (ドリームウィーバーで見たら、望み通りの配置になっているのですが、ブラウザでチェックすると、中央カラムの下に右カラムがきてしまいます) アドバイスいただければ嬉しいです。 よろしくお願い致します。

    • ベストアンサー
    • CSS
  • CSSの応用がわかりません。

    使用目的に合うCSSスタイルをダウンロードしてきました。 これはdivの高さを揃えられるcssです。 しかし、内容を理解していないので自分のホームページに適用できていません。 やりたいことは、col1が155px,col2が14px,col3が382px,col4が14px,col5が190pxにして使用したのですがこのcssを変更して使いたいのですがどのように変更すればよいでしょうか? /* Start of Column CSS */ #container5 { clear:left; float:left; width:100%; overflow:hidden; background:#eee; /* column 5 background colour */ } #container4 { clear:left; float:left; width:100%; position:relative; right:20%; background:#b2f0f9; /* column 4 background colour */ } #container3 { clear:left; float:left; width:100%; position:relative; right:20%; background:#89ffa2; /* column 3 background colour */ } #container2 { clear:left; float:left; width:100%; position:relative; right:20%; background:#ffa7a7; /* column 2 background colour */ } #container1 { float:left; width:100%; position:relative; right:20%; background:#fff689; /* column 1 background colour */ } #col1 { float:left; width:16%; position:relative; left:82%; overflow:hidden; } #col2 { float:left; width:16%; position:relative; left:84%; overflow:hidden; } #col3 { float:left; width:16%; position:relative; left:90%; overflow:hidden; } #col4 { float:left; width:16%; position:relative; left:94%; overflow:hidden; } #col5 { float:left; width:16%; position:relative; left:98%; overflow:hidden; } 以上がCSSです <body> <div id="container5"> <div id="container4"> <div id="container3"> <div id="container2"> <div id="container1"> <div id="col1"> <!-- col1 start --> <p>Each column is 20% percent wide with 2 percent padding on each side.</p> <!-- col1 end --> </div> <div id="col2"> <!-- col2 start --> <h2>No Images</h2> <!-- col2 end --> </div> <div id="col3"> <!-- col3 start --> <p>The HTML in this layout validates as XHTML 1.0 strict.</p> <!-- col3 end --> </div> <div id="col4"> <!-- col4 start --> <h2>This layout is FREE for anyone to use</h2> <!-- col4 end --> </div> <div id="col5"> <!-- col5 start --> <li>Opera 8 &amp; 9</li> <!-- col5 end --> </div> </div> </div> </div> </div> </div> </body>

  • 3カラムのカラム落ちについて質問です。

    3カラムのカラム落ちについて質問です。 IE6だけ3カラムのうち右カラムだけカラム落ちしてなおりません。 ネットで検索して色々試した結果「clear: right;」を追加したら右に戻ったのですが、今度は隙間ができました。 <div id="wrap">  <div id="left">左カラム</div>  <div id="left">メインカラム</div>  <div id="left">右カラム</div> </div> という形です。 --CSS-- #wrap{ width: 970px; margin: 0 auto; background-color: #FFFFFF; height: 100%; min-height: 100%; position:relative; overflow: hidden; } #left{ width: 175px; margin: 15px 15px 0 15px; padding: 0; float: left; display: inline; } #contents{ width: 560px; float: right; margin-top: 15px; display: inline; clear: right; } #right{ width: 175px; margin: 15px; float: right; display: inline; clear: right; } です。 それぞれの中にはmargin やpaddingを使っています。 2日間それで悩まされていますができずに困っています。 IE6以外はすべて大丈夫なので、分かるかた教えてください。

  • CSSのfloatについて

    ホームページを作成していて、CSSが効かなくて困っています。 2カラムで左側にメニュー 右側にメインのコンテンツを作成しております。 メインのコンテンツは floatでrightに設定していて その中にさらに 2つの内容を入れようと (メインコンテンツ内に左側に画像で右側に画像の詳細をいれたい) floatタグでleftとrightに設定したのですが CSSが効かなくて 左側に画像が配置され その下に画像の詳細文が配置されてしまい 全部左側に配置されてしまいました。 色々と試したみたのですが やっぱりCSSが効きませんでした。 すいません誰かお分かりになられましたら 教えてください。宜しくお願い致します。

  • HTMLのCSS(float)の設定がよくわかりません

    HTMLのCSS(float)の設定がよくわかりません 画像のように各配置はうまく表示されているのですが footerのCSSを #footer { width: 100%; float: left; clear: both; } と表記するとwrapperのCSSで表記した外枠のボーダーが footerの前で切、footerの左横に1px~2pxの隙間が できてしまうのですが、その理由をわかる方いらっしゃいますか。 宜しくお願い致します。 footerの表記を #footer { width: 100%; clear: both; } とすると、ボーダーも1pxの隙間もなく正常に表示されます。 宜しくお願い致します。 ■HTML <html> <body> <div id="wrapper"> <div id="header"></div> <div id="container"> <div id="left"></div> <div id="right"></div> </div> <div id="footer"></div> </div> </body> </html> ■CSS #wrapper { width: 700px; border-right-width: 1px; border-left-width: 1px; border-right-style: solid; border-left-style: solid; border-right-color: #000; border-left-color: #000; } #container { overflow: hidden; } #left { float: left; } #right { float: left; } #footer { width: 100%; float: left; clear: both; } わかる方いらっしゃいましたら 宜しくお願い致します。

    • ベストアンサー
    • HTML
  • CSSレイアウトについて

    cssによる3カラムを作っているのですがie6で見ると右のカラムが 落ちしてしまいます。 ie6のバグのようでdisplay: inline;を使うなどいろいろと試して みたのですがwidthとmarginの合計で1000px以内にしなければ ならないようなのですがその場合firefoxなどのブラウザで確認 すると若干ではありますが微妙に違いがでてきます。 下記のソースのように特に画像をいれなくてもbackgroundを設定 することによりカラム落ちはしなくなったのですがこの他に解決 方法はあるのでしょうか? また、なぜbackgroundを設定することにより解決したのかも 全く意味不明なのでご存知の方がおりましたら教えてください。 #contents { width: 1000px; } #left { display: inline; float: left; width: 180px; text-align: left; background: url(); } #center { display: inline; float: left; width: 600px; margin: 0 20px; text-align: left; background: url(); } #right { display: inline; float: left; width: 180px; text-align: left; background: url(); } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ~略~ <div id="contents"> <div id="left">レフト</div> <div id="center">センター</div> <div id="right">ライト</div> </div> ~略~

    • ベストアンサー
    • CSS
  • 回り込みfloatの間隔について質問です

    ボックスでボックスを回り込みしています。(?) …書いたほうが早いですね… HTMLが <div id="left"> 左ボックス </div> <div id="right"> 右ボックス </div> CSSが *{ margin: 0px; padding: 0px; } #left { float: left; width: 100px; height: 100px; } #right{ width: 200px; height: 100px; } といった感じです。 左ボックスと右ボックスの間に1~2pxほどの間隔があいてしまいます。 これをなくすにはどうすればいいですか? お願いします。