2012年6月1日金曜日

HTML

はじめに

インターネット上で蜘蛛の巣のように張り巡らされた情報網のことを World Wide Web (WWW) と呼びます。その情報網では,インターネット閲覧ソフト(ウェブブラウザ)で表示されたページ(ウェブページ)の一部分をクリックすることで,次々とジャンプしアクセスすることができます。 そのようなウェブページは,HTML (HyperText Markup Language) という言語で記述されています。 ここでは,HTML言語の書き方を学習しましょう。

HTMLファイルのサンプルと構造

サンプルファイル

まず最初に,この授業用のディレクトリを作りましょう。

  cd  mkdir html  cd html  

そして,次のように入力すると,エディタ emacs が起動し,mypage.html と名前を付けたファイルの作成画面が表示されます。

emacs mypage.html &

ここで,emacs がご丁寧に
Insert /usr/local/lib/html/template.html?(y or n)
(HTMLファイルのテンプレート(ひな形ファイル)を出しましょうか?)
と聞いてくるので,n (いいえ) を選択します。間違えてテンプレートが出てしまった場合には,それを全部消して下さい。( 最初の行の先頭で,CTRL-K を押し続けると,消えます)

それから,次のような内容のものを作り,保存しましょう。 ただし, のように < と > とで挟まれた部分は, < > も含めて半角文字で書いていることに注意しましょう。

サンプルHTMLファイル

そして,ウェブブラウザでそのファイルを開いてみましょう。
ウェブブラウザの「ファイル」メニューの「ファイルのオープン」というサブメニューを用いて,先ほど選択したファイルを開きます。 すると,次のように表示されます。

サンプルファイルの結果

ブラウザのウインドウには"ようこそ!これは私のウェブページです。" が表示されています。また,そのウインドウのタイトルが"Welcome"となっています。 しかし,その他のとかのように, <と>とで挟まれたものはブラウザ画面のどこにも表示されていません。 なぜなら,それはHTMLファイルの内容の構造を表す タグと呼ばれるものだからです。 HTMLファイルの書き方を覚えるということは, このタグの書き方を覚えるということに他なりません。

タグと要素

さきほどのファイルにあるタグを抜き出してみましょう。


/ が付かないものと付くものとが セットになっているものがたくさんあります。 このように,通常,タグはセットになって現れます。
/が付かないものを開始タグ, /が付いたものを終了タグと呼びます。 また,開始タグから終了タグまでの部分を,要素と呼びます。
しかし,
のように,終了タグがなく単独で現れるものもあります。
タグは,その要素が全体の文書中で どのような意味を持つものであるかを表すものです。 また,タグはのように,大文字で書いてもよく, 多くの解説書では大文字を採用していますが, ここでは書きやすさのために小文字で書くことにします。 (大文字だと,シフトキーを押し続けるか,caps lockキーをいちいち押す必要がありますから。また,次世代の HTML とも言える新しい言語である XHTML では,タグを小文字で書くことになっていますので。)</p> <p>では,さきほどのファイルのタグを,ひとつひとつ解説していきます。</p> <h3>HTMLファイルの構造</h3> <p>まず,ファイルの先頭に<br/><!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <br/>という一行ありますが,これは,文書型の宣言をしているものです。 ここでは詳しいことは解説しないので,おまじないだと思っておいて下さい。 (doctype の前に ! があることを忘れないように)</p> <p> 次に,それ以降の内容全体が <html>と</html>とで挟まれて,html要素となっています。 これは,このファイルがHTML言語で書かれていることを意味しています。<br/>html要素の中は, <head>と</head>とで挟まれたhead要素と, <body>と <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> 投稿者 <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/17063665837518747956' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/17063665837518747956' rel='author' title='author profile'> <span itemprop='name'>Sam</span> </a> </span> </span> <span class='post-timestamp'> 時刻: <meta content='http://kayyiamm.blogspot.com/2012/06/html.html' itemprop='url'/> <a class='timestamp-link' href='http://kayyiamm.blogspot.com/2012/06/html.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2012-06-01T21:18:00+09:00'>21:18</abbr></a> </span> <span class='post-comment-link'> </span> <span class='post-icons'> <span class='item-control blog-admin pid-2101169976'> <a href='https://www.blogger.com/post-edit.g?blogID=7183334355807021960&postID=3089285495682110252&from=pencil' title='投稿を編集'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> <a class='goog-inline-block share-button sb-email' href='https://www.blogger.com/share-post.g?blogID=7183334355807021960&postID=3089285495682110252&target=email' target='_blank' title='メールで送信'><span class='share-button-link-text'>メールで送信</span></a><a class='goog-inline-block share-button sb-blog' href='https://www.blogger.com/share-post.g?blogID=7183334355807021960&postID=3089285495682110252&target=blog' onclick='window.open(this.href, "_blank", "height=270,width=475"); return false;' target='_blank' title='BlogThis!'><span class='share-button-link-text'>BlogThis!</span></a><a class='goog-inline-block share-button sb-twitter' href='https://www.blogger.com/share-post.g?blogID=7183334355807021960&postID=3089285495682110252&target=twitter' target='_blank' title='Twitter で共有する'><span class='share-button-link-text'>Twitter で共有する</span></a><a class='goog-inline-block share-button sb-facebook' href='https://www.blogger.com/share-post.g?blogID=7183334355807021960&postID=3089285495682110252&target=facebook' onclick='window.open(this.href, "_blank", "height=430,width=640"); return false;' target='_blank' title='Facebook で共有する'><span class='share-button-link-text'>Facebook で共有する</span></a><a class='goog-inline-block share-button sb-pinterest' href='https://www.blogger.com/share-post.g?blogID=7183334355807021960&postID=3089285495682110252&target=pinterest' target='_blank' title='Pinterest に共有'><span class='share-button-link-text'>Pinterest に共有</span></a> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> <div class='comments' id='comments'> <a name='comments'></a> <h4>0 件のコメント:</h4> <div id='Blog1_comments-block-wrapper'> <dl class='avatar-comment-indent' id='comments-block'> </dl> </div> <p class='comment-footer'> <div class='comment-form'> <a name='comment-form'></a> <h4 id='comment-post-message'>コメントを投稿</h4> <p> </p> <a href='https://www.blogger.com/comment/frame/7183334355807021960?po=3089285495682110252&hl=ja' id='comment-editor-src'></a> <iframe allowtransparency='true' class='blogger-iframe-colorize blogger-comment-from-post' frameborder='0' height='410px' id='comment-editor' name='comment-editor' src='' width='100%'></iframe> <script src='https://www.blogger.com/static/v1/jsbin/4269703388-comment_from_post_iframe.js' type='text/javascript'></script> <script type='text/javascript'> BLOG_CMT_createIframe('https://www.blogger.com/rpc_relay.html'); </script> </div> </p> </div> </div> </div></div> </div> <div class='blog-pager' id='blog-pager'> <span id='blog-pager-newer-link'> <a class='blog-pager-newer-link' href='http://kayyiamm.blogspot.com/2012/06/ustream-cures-hemorrhoids-safely.html' id='Blog1_blog-pager-newer-link' title='次の投稿'>次の投稿</a> </span> <span id='blog-pager-older-link'> <a class='blog-pager-older-link' href='http://kayyiamm.blogspot.com/2012/05/yahoo_30.html' id='Blog1_blog-pager-older-link' title='前の投稿'>前の投稿</a> </span> <a class='home-link' href='http://kayyiamm.blogspot.com/'>ホーム</a> </div> <div class='clear'></div> <div class='post-feeds'> <div class='feed-links'> 登録: <a class='feed-link' href='http://kayyiamm.blogspot.com/feeds/3089285495682110252/comments/default' target='_blank' type='application/atom+xml'>コメントの投稿 (Atom)</a> </div> </div> </div></div> </div> </div> <div class='column-left-outer'> <div class='column-left-inner'> <aside> </aside> </div> </div> <div class='column-right-outer'> <div class='column-right-inner'> <aside> <div class='sidebar section' id='sidebar-right-1'><div class='widget BlogArchive' data-version='1' id='BlogArchive1'> <h2>ブログ アーカイブ</h2> <div class='widget-content'> <div id='ArchiveList'> <div id='BlogArchive1_ArchiveList'> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='http://kayyiamm.blogspot.com/2012/'> 2012 </a> <span class='post-count' dir='ltr'>(36)</span> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='http://kayyiamm.blogspot.com/2012/06/'> 6月 </a> <span class='post-count' dir='ltr'>(2)</span> <ul class='posts'> <li><a href='http://kayyiamm.blogspot.com/2012/06/ustream-cures-hemorrhoids-safely.html'>USTREAM: Cures Hemorrhoids Safely: .</a></li> <li><a href='http://kayyiamm.blogspot.com/2012/06/html.html'>HTML</a></li> </ul> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://kayyiamm.blogspot.com/2012/05/'> 5月 </a> <span class='post-count' dir='ltr'>(12)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://kayyiamm.blogspot.com/2012/04/'> 4月 </a> <span class='post-count' dir='ltr'>(19)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://kayyiamm.blogspot.com/2012/03/'> 3月 </a> <span class='post-count' dir='ltr'>(3)</span> </li> </ul> </li> </ul> </div> </div> <div class='clear'></div> </div> </div><div class='widget Profile' data-version='1' id='Profile1'> <h2>自己紹介</h2> <div class='widget-content'> <dl class='profile-datablock'> <dt class='profile-data'> <a class='profile-name-link g-profile' href='https://www.blogger.com/profile/17063665837518747956' rel='author' style='background-image: url(//www.blogger.com/img/logo-16.png);'> Sam </a> </dt> </dl> <a class='profile-link' href='https://www.blogger.com/profile/17063665837518747956' rel='author'>詳細プロフィールを表示</a> <div class='clear'></div> </div> </div></div> </aside> </div> </div> </div> <div style='clear: both'></div> <!-- columns --> </div> <!-- main --> </div> </div> <div class='main-cap-bottom cap-bottom'> <div class='cap-left'></div> <div class='cap-right'></div> </div> </div> <footer> <div class='footer-outer'> <div class='footer-cap-top cap-top'> <div class='cap-left'></div> <div class='cap-right'></div> </div> <div class='fauxborder-left footer-fauxborder-left'> <div class='fauxborder-right footer-fauxborder-right'></div> <div class='region-inner footer-inner'> <div class='foot no-items section' id='footer-1'></div> <table border='0' cellpadding='0' cellspacing='0' class='section-columns columns-2'> <tbody> <tr> <td class='first columns-cell'> <div class='foot no-items section' id='footer-2-1'></div> </td> <td class='columns-cell'> <div class='foot no-items section' id='footer-2-2'></div> </td> </tr> </tbody> </table> <!-- outside of the include in order to lock Attribution widget --> <div class='foot section' id='footer-3' name='フッター'><div class='widget Attribution' data-version='1' id='Attribution1'> <div class='widget-content' style='text-align: center;'> 「シンプル」テーマ. Powered by <a href='https://www.blogger.com' target='_blank'>Blogger</a>. </div> <div class='clear'></div> </div></div> </div> </div> <div class='footer-cap-bottom cap-bottom'> <div class='cap-left'></div> <div class='cap-right'></div> </div> </div> </footer> <!-- content --> </div> </div> <div class='content-cap-bottom cap-bottom'> <div class='cap-left'></div> <div class='cap-right'></div> </div> </div> </div> <script type='text/javascript'> window.setTimeout(function() { document.body.className = document.body.className.replace('loading', ''); }, 10); </script> <script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/1807328581-widgets.js"></script> <script type='text/javascript'> window['__wavt'] = 'AOuZoY6XBvZQGyGokc9RQhco1xWL7SS98Q:1714252822301';_WidgetManager._Init('//www.blogger.com/rearrange?blogID\x3d7183334355807021960','//kayyiamm.blogspot.com/2012/06/html.html','7183334355807021960'); _WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '7183334355807021960', 'title': 'notebook', 'url': 'http://kayyiamm.blogspot.com/2012/06/html.html', 'canonicalUrl': 'http://kayyiamm.blogspot.com/2012/06/html.html', 'homepageUrl': 'http://kayyiamm.blogspot.com/', 'searchUrl': 'http://kayyiamm.blogspot.com/search', 'canonicalHomepageUrl': 'http://kayyiamm.blogspot.com/', 'blogspotFaviconUrl': 'http://kayyiamm.blogspot.com/favicon.ico', 'bloggerUrl': 'https://www.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'ja', 'localeUnderscoreDelimited': 'ja', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': false, 'isMobileRequest': false, 'mobileClass': '', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22notebook - Atom\x22 href\x3d\x22http://kayyiamm.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22notebook - RSS\x22 href\x3d\x22http://kayyiamm.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22notebook - Atom\x22 href\x3d\x22https://www.blogger.com/feeds/7183334355807021960/posts/default\x22 /\x3e\n\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22notebook - Atom\x22 href\x3d\x22http://kayyiamm.blogspot.com/feeds/3089285495682110252/comments/default\x22 /\x3e\n', 'meTag': '', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': false, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/16e657cb9c57b8a2', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': '\u30ea\u30f3\u30af\u3092\u53d6\u5f97', 'key': 'link', 'shareMessage': '\u30ea\u30f3\u30af\u3092\u53d6\u5f97', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Facebook \u3067\u5171\u6709', 'target': 'facebook'}, {'name': 'BlogThis!', 'key': 'blogThis', 'shareMessage': 'BlogThis!', 'target': 'blog'}, {'name': 'Twitter', 'key': 'twitter', 'shareMessage': 'Twitter \u3067\u5171\u6709', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Pinterest \u3067\u5171\u6709', 'target': 'pinterest'}, {'name': '\u30e1\u30fc\u30eb', 'key': 'email', 'shareMessage': '\u30e1\u30fc\u30eb', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27ja\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': '\u7d9a\u304d\u3092\u8aad\u3080', 'pageType': 'item', 'postId': '3089285495682110252', 'pageName': 'HTML', 'pageTitle': 'notebook: HTML'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': '\u7de8\u96c6', 'linkCopiedToClipboard': '\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3057\u305f\u3002', 'ok': 'OK', 'postLink': '\u6295\u7a3f\u306e\u30ea\u30f3\u30af'}}, {'name': 'template', 'data': {'name': 'Simple', 'localizedName': '\u30b7\u30f3\u30d7\u30eb', 'isResponsive': false, 'isAlternateRendering': false, 'isCustom': false, 'variant': 'pale', 'variantId': 'pale'}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': false, 'title': 'HTML', 'description': '\u306f\u3058\u3081\u306b \u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u8718\u86db\u306e\u5de3\u306e\u3088\u3046\u306b\u5f35\u308a\u5de1\u3089\u3055\u308c\u305f\u60c5\u5831\u7db2\u306e\u3053\u3068\u3092 World Wide Web (WWW) \u3068\u547c\u3073\u307e\u3059\u3002\u305d\u306e\u60c5\u5831\u7db2\u3067\u306f\uff0c\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u95b2\u89a7\u30bd\u30d5\u30c8\uff08\u30a6\u30a7\u30d6\u30d6\u30e9\u30a6\u30b6\uff09\u3067\u8868\u793a\u3055\u308c\u305f\u30da\u30fc\u30b8\uff08\u30a6\u30a7\u30d6\u30da\u30fc\u30b8\uff09\u306e\u4e00\u90e8\u5206\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3053\u3068\u3067\uff0c\u6b21\u3005\u3068\u30b8\u30e3\u30f3\u30d7\u3057\u30a2\u30af\u30bb...', 'url': 'http://kayyiamm.blogspot.com/2012/06/html.html', 'type': 'item', 'isSingleItem': true, 'isMultipleItems': false, 'isError': false, 'isPage': false, 'isPost': true, 'isHomepage': false, 'isArchive': false, 'isLabelSearch': false, 'postId': 3089285495682110252}}]); _WidgetManager._RegisterWidget('_NavbarView', new _WidgetInfo('Navbar1', 'navbar', document.getElementById('Navbar1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'lightboxEnabled': true, 'lightboxModuleUrl': 'https://www.blogger.com/static/v1/jsbin/3388589258-lbx__ja.js', 'lightboxCssUrl': 'https://www.blogger.com/static/v1/v-css/13464135-lightbox_bundle.css'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'sidebar-right-1', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': '\u8aad\u307f\u8fbc\u307f\u4e2d\x26hellip;'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_ProfileView', new _WidgetInfo('Profile1', 'sidebar-right-1', document.getElementById('Profile1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_AttributionView', new _WidgetInfo('Attribution1', 'footer-3', document.getElementById('Attribution1'), {}, 'displayModeFull')); </script> </body> </html>