jQuery を使用することにオープンであるかどうかはわかりません。はいの場合は、次のことができます。
すべてのフロートを取り除き、ラッパーdisplay:inline-block
に追加し、 jQuery を使用してラッパーの合計幅から差を引いた値を計算し、それを に設定します。 div
left div width
right div
HTML
<div id="wrapper">
<div id="left">left</div>
<div id="right">right</div>
</div>
CSS
#left{
background-color: Blue;
height: 100px;
width: 200px;
margin-left:10px;
}
#right{
background-color: #5a71e5;
height: 100px;
}
#wrapper div {
display: inline-block;
}
#wrapper{
width:100%;
}
jQuery
$('#right').width($('#wrapper').width() - $('#left').width() - 20);
サンプル フィドル: http://jsfiddle.net/3P9XN/12/
アップデート
応答性のためにウィンドウのサイズ変更検出を追加
http://jsfiddle.net/3P9XN/14/
Update2
Marc の提案に従ってソリューションを更新し、スクリプトを通じて outerWidth と css マージンの値を取得するようになりました。よりダイナミックでクリーンなアプローチ。
jQuery
$(document).ready(setRightWidth);
$(window).resize(setRightWidth);
function setRightWidth(){
var leftmargin = parseFloat($('#left').css('margin-left'));
var width = $('#wrapper').outerWidth(true) - $('#left').outerWidth(true) - leftmargin;
$('#right').width(width);
}
http://jsfiddle.net/3P9XN/17/