HTML作成編

4.表関連タグ (No.2)






<table> <caption> <tr> <td>, <th>

3.<tr>〜</tr>に関する記述


「align=**」

その行の文字列位置(左右)を決めます。

<table border=2 align=center width=300 height=80>
<tr align=**>    ←1行目
<td> 月 </td>
・・・
(中省略)
・・・
</td>
</tr>
<tr align=**>    ←2行目
<td> 現国 </td>
・・・
(中省略)
・・・
</td>
</tr>
</table>
<tr align=**> の指定無しの場合

現国 数学 化学 英語 経済

1行目<tr align=right>
2行目<tr align=center> の場合

現国 数学 化学 英語 経済

「valign=**」

行ごとに文字列位置(上下)を決めます。 ここでは、テーブル内を少し変えて説明します。
文字列の位置だけ確認してネ!

又、alignは、どの行も「align=center」にしておきました。

<table border=2 align=center width=300 height=220>
<tr align=center>    ←1行目(指定無し)
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center valign=top>    ←2行目
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center valign=bottom>    ←3行目
・・・
(中省略)
・・・
</td>
</tr>
</table>
表示結果

















1行目を見て分かるように valign=middle を指定するのと同じ結果が出ました。

「bgcolor=#"******"」

その行単位のセルに背景色を付けます。
又。ここでは、「valign=**」の指定を外します。

<table border=2 align=center width=300 height=220>
<tr align=center bgcolor="#7777ff">    ←1行目
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor="#ffffaa">    ←2行目
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor=#cfefb7">    ←3行目
・・・
(中省略)
・・・
</td>
</tr>
</table>
表示結果

















どうですかきれいですか?だからどうしたって感じですか。
でも、まだ列ごとの間隔がおかしく見える人もいますよね。Explorerでは、 あまり変でないですが、Netscapeでは、列ごとの間隔がいまいち揃っていないはずです。 それは、次の章で.....



<table> <caption> <tr> <td>, <th>

4.<td>〜</td> <th>〜</th>に関する記述 (1)


<td>と<th>の違い

まず最初に、前の表を見て分かるように1列増えていますが、 1列目で太文字の指定はしていません。 そうです<th>〜</th>を使っています。1行目の曜日も<th>にします。
又、ここでは、前の表を使いますが、<tr>の align=centerを外します。

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr bgcolor="#ffffaa">    ←2行目
<th> 1<br>時<br>限<br>目 </th>
<td> 現<br>国 </td>
・・・
(中省略)
・・・
</td>
</tr>
<tr bgcolor="#cfefb7">    ←3行目
<th> 2<br>時<br>限<br>目 </th>
<td> 数<br>学 </td>
・・・
(中省略)
・・・
</tr>
</table>
表示結果

















このように<td>の変わりに<th>を使う事によって 文字列が強調(太文字)され、更に中央に揃えてくれます。

「align=**」

<td>,<th>で出来たセルの文字列位置(左右)を決めます。
又、<tr>の align=centerは、元に戻します。

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th> ★ </th>
<th> 月 </th>
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor="#ffffaa">    ←2行目
<th> 1<br>時<br>限<br>目 </th>
<td align=left> 現<br>国 </td>
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor="#cfefb7">    ←3行目
<th> 2<br>時<br>限<br>目 </th>
<td align=right> 数<br>学 </td>
・・・
(中省略)
・・・
</tr>
</table>
表示結果

















<tr>で align=centerを指定しているので、 <td>での align=centerの指定は、省略します。

「valign=**」

<td>,<th>で出来たセルの文字列位置(上下)を決めます。
又、前の表をそのまま使います。

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th> ★ </th>
<th> 月 </th>
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor="#ffffaa">    ←2行目
<th> 1<br>時<br>限<br>目 </th>
<td align=left> 現<br>国 </td>
<td valign=top> 数<br>学 </td>
・・・
(中省略)
・・・
</td>
</tr>
<tr align=center bgcolor="#cfefb7">    ←3行目
<th> 2<br>時<br>限<br>目 </th>
<td align=right> 数<br>学 </td>
<td valign=bottom> 生<br>物 </td>
・・・
(中省略)
・・・
</tr>
</table>
表示結果

















例題では、<th>での指定はしていませんが、 結果は同じなので省略します。
たまたま、作った表が時間割りでしたが、画像などを取り入れて<table> での border=**を外すか、0(ゼロ)にし、 align=** valign=**を使いセル一つ一つ位置を変えると、 面白い物が出来ると思います。

私の Pageで言うと 以前のメインページですが、テーブルのボーダーを表した 物があります。 見る

「width=** height=**」

<td>,<th>で出来たセルの幅、高さを決めます。ここでは、表の幅で300を取っているので その 300を 6列に分配します。例では、均等に取ります。
ここでは、 height=**の指定は、省略します。

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th width=50></th>
<td width=50></td>
<td width=50></td>
<td width=50></td>
<td width=50></td>
<td width=50></td>
</tr>
・・・
(中省略)
・・・
</table>
表示結果

















この指定は、1行目だけの指定でも大丈夫だと思います。が、ちなみに私は、 Explorer,Netscapee以外のブラウザでは、どうか分からないので なるべくすべての行に指定しています。
又、例えば 2列の表があるとします。1列目だけ width=100を指定するとします。 するとInternet Explorerではその分だけのサイズを取ってくれますが、 Netscapeでは、無効となり指定していないのと同じになりますから サイズを指定する際は、両方に指定した方が良いです。

「bgcolor=#"******"」

セル一つ一つにの背景色を付けます。

「background="画像 File"」● Internet Explorer3.0以上対応

セル一つ一つにの背景画を付けます。

「bgcolor=#"******"」

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th width=bgcolor="50"></th>
<th width=50 bgcolor="#99ee22"></th>
<th width=50 bgcolor="#66ff66"></th>
<th width=50 bgcolor="#aaffff"></th>
<th width=50 bgcolor="#cc66aa"></th>
<th width=50 bgcolor="#ffd700"></th>
</tr>
<tr align=center bgcolor="#ffffaa">    ←2行目
<td width=50 bgcolor="#ffff66"> 1<br>時<br>限<br>目 </td>
・・・
(中省略)
・・・
</tr>
<tr align=center bgcolor="#cfefb7">    ←3行目
<td width=50 bgcolor="#9cbc84"> 1<br>時<br>限<br>目 </td>
・・・
(中省略)
・・・
</tr>
</table>

表示結果

















あまりセンスは良くありませんが我慢して見て下さい。(^^;

「backgound="画像 File"」

<table border=2 align=center width=300 height=220>
<tr bgcolor="#7777ff">    ←1行目
<th width=bgcolor="50"></th>
<th width=50 bgcolor="#9922ee" background="images/b2.gif"></th>
<th width=50 bgcolor="#ff66ff" background="images/b2.gif"></th>
<th width=50 bgcolor="#aaffff" background="images/b2.gif"></th>
<th width=50 bgcolor="#ccaa66" background="images/b2.gif"></th>
<th width=50 bgcolor="#ffd700" background="images/b2.gif"></th>
</tr>
<tr align=center bgcolor="#ffffaa">    ←2行目
<th width=50 bgcolor="#ffff66"> 1<br>時<br>限<br>目 </th>
・・・
(中省略)
・・・
</tr>
<tr align=center bgcolor="#cfefb7">    ←3行目
<th width=50 bgcolor="#9cbc84"> 2<br>時<br>限<br>目 </th>
・・・
(中省略)
・・・
</tr>
</table>

表示結果

















Internet Explorer3.0以上、及びNetscape4.0で見ている方は、分かると思います。 言うまでもありませんがそれ以外で見ている人もいますから、色の指定はしておいた方が良いと思います。
このメニューの、TopPageの「Tomey の Study Room」もこれを使っています。



<table> <caption> <tr> <td>, <th>



続きは、次のPAGEへ。


戻る
次へ




The Purposeロゴ
http://www.web-purpose.com/purpose/
Copyright (C) 1997-2005 Tomio Sato. All Rights Reserved.