SPANを表の両側に揃えて配置するにはどうすればよいですか?
質問
<div>
<span>left</span>
<span>right</span>
<!-- new line break, so no more content on that line -->
<table>
...
</table>
</div>
どのようにそれらのスパンを配置することができますか(それらは任意の要素に変更できます)、テーブルの大きさに応じて(どこにも定義されておらず、そうではありません)、スパンは左側のちょうど上に配置されますテーブルとテーブルの右側。
例:
a b table0 table1 table2
(aは左のスパン、bは右のスパン)
PSバーの内部テーブルhtmlは何でも変更できます。
解決
それらを比較的配置しない、または ロブ・アレンの答えは、彼らがそれらを置く ブラウザの遠くではなく、 テーブル幅内。
まあ、彼らはコンテナの幅に縛られているので、Robの答えはテーブルとコンテナの幅の両方を100%にします。
手に負えないと考える唯一の解決策は、テーブルに1列(すべての列にまたがる)の行を配置し、その行にフロートDIVを配置することです。
他のヒント
<style type="text/css">
#wrapper, #top, #tableArea
{
width: 100%;
padding: 10px;
margin: 0px auto;
}
#top
{
padding: 0px;
}
#leftBox, #rightBox
{
margin: 0px;
float: left;
display: inline;
clear: none;
}
#rightBox
{
float: right;
}
</style>
<div id="wrapper">
<div id="top">
<div id="leftBox">A</div>
<div id="rightBox">b<</div>
</div>
<div id="tableArea">
<table> ... </table>
</div>
</div>
同様の問題にぶつかり、解決策を見つけました。テーブルの幅には依存しませんが、少し注意が必要です。 IE5.5、IE6以降を含むすべてのブラウザーで動作します。
<style>
.tablediv {
float:left; /* this is a must otherwise the div will take a full width of our page and this way it wraps only our content (so only the table) */
position:relative; /* we are setting this to start the trickie part */
padding-top:2.7em; /* we have to set the room for our spans, 2.7em is enough for two rows otherwise try to use something else; for one row e.g. 1.7em */
}
.leftspan {
position:absolute; /* seting this to our spans will start our behaviour */
top:0; /* we are setting the position where it will be placed inside the .tablediv */
left:0;
}
.rightspan {
position:absolute;
top:0;
right:0;
}
</style>
<div class="tablediv">
<span class="leftspan">Left text</span>
<span class="rightspan">Right text <br /> with row</span>
<table border="1">
<tr><td colspan="3">Header</td></tr>
<tr><td rowspan="2">Left content</td><td>Content</td><td rowspan="2">Right content</td></tr>
<tr><td>Bottom content</td></tr>
</table>
</div>
<!-- If you don't want to float this on the right side of the table than you must use the clear style -->
<p style="clear:both">
something that continues under our tablediv
</p>
何らかの理由でフロートを使用できない場合は、誤って見つけた別の.tabledivスタイルを使用できます。 float:leftを置き換えるだけです。 to display:inline-block;
これはすべての最新ブラウザーで動作しますが、IE7以下では動作しません。
今、あなたは私の論点を得ることができ、他の解決策を見つけることができると確信しています。 .tabledivが内部コンテンツと同じ長さになることを忘れないでください。そのため、段落をその中に配置すると、表よりも大きなサイズに拡大されます。
スパンの代わりにdivがある場合は、スパンaにfloat:leftを、スパンbにfloat:rightを試してください
<div>
<div style="float:left">a</div><div style="float:right">b</div>
<br style="clear: both">
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
</div>
それらを比較的配置せず、Rob Allenの答えも、テーブル幅内ではなく、ブラウザの遠くに配置します。
とにかく考えられませんが、テーブルの幅を何かに設定する以外は。私の場合、100%を選択します。これは、50emでラッパーの幅まで伸びます。
<style type="text/css">
#wrapper {
width: 1%;
min-width:50em;
padding: 10px;
}
#mainTable {
width:100%;
}
#leftBox {
float: left;
}
#rightBox {
float: right;
}
</style>
<div id="wrapper">
<div id="leftBox">A</div>
<div id="rightBox">b</div>
<br style="clear: both" />
some text some text some text some text some text <br />
some text some text some text some text some text <br />
some text some text some text some text some text
<table id="mainTable" border="1"><tr><td>test</td><td>test 2</td></tr></table>
</div>
@MattMitchell、何かあるかもしれません。そして、単にfloatを使用します:左とフロートを右に仮定しますか?