電子書籍の厳選無料作品が豊富!

ボックス1、ボックス2、ボックス3と3つのボックスをfloat: left;で左から横に並べて、キッチリブラウザの幅に収めたいです。

ボックス1は、width: 20%;を指定。
ボックス2は、width: 5px;を指定。
ボックス3は、ブラウザ幅に3つが収まる値をjavascriptで計算して指定したいです。

そこで、各ボックスwidthの合計値をoffsetWidth以下なら、各ボックスは折り返さずに表示されると考え、以下htmlを作成しました。

※行頭スペースは全角です。

<html>
<head>
<style type="text/css">
#b1 {
 background-color: ffffff;
 float: left;
 height: 100%;
 width: 20%;
 overflow: auto;
}

#b2 {
 background-color: 000000;
 float: left;
 height: 100%;
 width: 5px;
}

#b3 {
 background-color: ffffff;
 float: left;
 height: 100%;
 overflow: auto;
}
</style>
<script>
i = function(id){ return document.getElementById(id) };
function init(){
 var W = document.body.offsetWidth || document.documentElement.offsetWidth;
 var b1 = i('b1').offsetWidth;
 var b2 = i('b2').offsetWidth;
 var b3= W - b1 - b2;

 alert(W +' = ' + b1 + ' + ' + b2 + ' + ' + b3);

 i('b3').style.width = b3 + 'px';
};
</script>
</head>
<body onLoad = "init();" >
<div id="b1">f1</div>
<div id="b2" ></div>
<div id="b3">f2</div>
</body>
</html>

上記を実行した結果、IE,Operaは折り返してしまい、FirFox,Google Chromeは折り返さずに表示できました。

IE,Operaは、なぜ折り返してしまうのでしょうか?

A 回答 (1件)

http://d.hatena.ne.jp/onozaty/20060803/p1
http://d.hatena.ne.jp/onozaty/20060802/p1

border-right:5px black solid;
ではだめなの?
    • good
    • 0
この回答へのお礼

_pipi_さん ご回答ありがとうございました。

教えていただいたページが非常によく纏まってて参考になりました。
クロスブラウザに作るには、ちょっと手間がかかりそうですね。

>border-right:5px black solid;
>ではだめなの?

5pxの上でイベントを発生させたいので、ダメなんです。。

お礼日時:2009/01/23 03:02

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!