3

わかりました、私は基本的に流動的なレイアウトを構築しています。私のHTMLは次のようなものです。

<div id="container">
    <div class="box" id="left">Left</div>
    <div class="box" id="center">This text is long and can get longer</div>
    <div class="box" id="right">Right</div>
    <div class="clear"></div>
</div>

これがcssです:

#container{
    width: 100%;
}
.box{
    float: left;
}
#left, #right{
    width: 100px;
}
#center{
    width: auto; /* ? */
    overflow: hidden;
}
.clear{
    clear:both;
}

私が知る必要があるのは、要素が互いに下に移動せずにサイズを#center変更したときに、どのようにサイズを変更するかです。#container

4

3 に答える 3

2

これらの修正を試してください(単純なフローティング要素、絶対要素やパディングを設定する必要はありません)

新しいフィドルを追加しました

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>fluid layout</title>
<style>
    /*class to set the width of the columns */
    .floatbox{
        width:100px;
    }

    #container{
        width: 100%;
        float:left;
    }
    #left{
        float:left;
    }
    #right{
        float:right;
    }
    #center{
        overflow: hidden;
    }
    .clear{
        clear:both;
    }
</style>
</head>
<body>
    <div id="container">
        <!-- floating column to the right, it must be placed BEFORE the left one -->
        <div class="floatbox" id="right">Right</div>
        <div class="floatbox" id="left">Left</div>

        <!-- central column, it takes automatically the remaining width, no need to declare further css rules -->
        <div id="center">This text is long and can get longer</div>

        <!-- footer, beneath everything, css is ok -->
        <div class="clear"></div>
    </div>
</body>
</html>
于 2010-12-14T13:53:14.873 に答える
1

#containerまた、それを実現するには、フロート(またはオーバーフロー:自動/非表示)する必要があります。よく知られている流体ソリューションのいくつかを使用することを強くお勧めします:http ://www.noupe.com/css/9-timeless-3-column-layout-techniques.html

于 2010-12-14T13:41:38.583 に答える
1

これを行い、発生する問題を完全に回避する最も簡単な方法はfloat、コンテナにパディングを使用し、パディング領域で左右の要素を絶対位置に配置することです。(http://www.jsfiddle.net/gaby/8gKWq/1のデモ

HTML

<div id="container">
    <div class="box" id="left">Left</div>
    <div class="box" id="right">Right</div>
    <div class="box" id="centre">This text is long and can get longer</div>
</div>

divの順序はもう重要ではありません。

Css

#container{
    padding:0 100px;
    position:relative;
}
.box{
   /*style the boxes here*/
}
#left, #right{
    width: 100px;
    position:absolute;
}
#left{left:0;top:0;}
#right{right:0;top:0;}

#center{
   /*anything specific to the center box should go here.*/
}
于 2010-12-14T13:42:22.390 に答える