初心者向けHTML入門の決定版:タグHTML

スタイルを適用させるにはどうするべき?

Facebook にシェア
このエントリーをはてなブックマークに追加
Tweet

スタイルの適用方法

HTML文章にスタイルを適用させるには、次の方法があります。

  • 1. link要素で外部スタイルシートを利用する
  • 2. HTML文章内 style要素の内容として記述する
  • 3. HTML文章内 style要素で外部スタイルシートを利用する
  • 4. HTML要素のsytle属性で記述する

HTMLは構造を記述する言語であるため、視覚的表現と切り離すことが望ましいとされています。保守性なども考慮すると、1.または2.の方法で外部スタイルシートを利用するようにしましょう。

1. link要素で外部スタイルシートを利用する

href属性に外部cssのURIを指定します。

<link rel="stylesheet" type="text/css" href="css/style.css" /> 

2. HTML文章内 style要素で外部スタイルシートを読み込む

href属性に外部cssのURIを指定します。

<style type="text/css"> 
@import "css/style.css";
</style> 

3. HTML文章内 style要素の内容として記述する

<style type="text/css"> 
p.desc { font-size: 1.2em; }
</style> 

4. HTML要素のsytle属性で記述する

<p style="font-size:1.2em;">
この記事を見た人はこんな記事も見ています
  • link要素・linkタグとは
  • div要素・divタグとは
  • li要素・liタグとは
  • br要素・brタグについて
  • コメントの書き方について

HTML要素(タグ)一覧

a  abbr  acronym  address  applet  area  b  base  basefont  bdo  big  blockquote  body  br  button  caption  center  cite  code  col  colgroup  dd  del  dfn  dir  div  dl  dt  em  fieldset  font  form  frame  frameset  h1 - h6  head  hr  html  i  iframe  img  input  ins  isindex  kbd  label  legend  li  link  map  menu  meta  noframes  noscript  object  ol  optgroup  option  p  param  pre  q  s  samp  script  select  small  span  strike  strong  style  sub  sup  table  tbody  td  textarea  tfoot  th  thead  title  tr  tt  u  ul  var  <!-- --> 

ブロックレベル要素一覧

p  h1-h6  ul  ol  dir  menu  pre  dl  div  center  noscript  noframes  blockquote  form  isindex  hr  table  fieldset  address 

インライン(テキストレベル)要素一覧

フォントスタイルに関するもの
tt  i  b  big  small
フレーズ・句に関するもの
em  strong  dfn  code  samp  kbd  var  cite  abbr  acronym
特別なもの
a  img  object  br  script  map  q  sub  sup  span  bdo
フォームに関するもの
input  select  textarea  label  button 

  • sitemap
  • 運営者情報
  • 免責事項
designed by ホームページ制作のササエル
Copyright © tagHTML All Rights Reserved.