跳至內容

超文字標記語言/CSS

來自華夏公益教科書

到目前為止,我們已經瞭解瞭如何將文字分成段落並建立章節標題。雖然 HTML 允許您定義文件的結構,但它不提供任何對外觀的控制。層疊樣式表 (CSS) 是一種描述文件呈現方式的語言。您可以使用 CSS 更改 HTML 文件的外觀。CSS 指令稱為規則樣式,CSS 規則文件稱為樣式表。(請注意,Web 瀏覽器具有內建樣式表,用於確定標題、段落等的預設外觀。這些樣式可以用您自己的樣式表覆蓋。)

本節介紹瞭如何使用 CSS 對 HTML 進行樣式設定。CSS 本身在配套華夏公益教科書層疊樣式表中有詳細介紹。

CSS 的作用是什麼?

[編輯 | 編輯原始碼]

來自段落和標題部分的示例頁面使用瀏覽器的預設 CSS,看起來會像這樣。

日晷
來自維基百科,自由的百科全書。
日晷是透過太陽的位置來測量時間的。最常見的日晷設計,例如“普通”或標準花園日晷,在刻有白天小時的平面上投下陰影。隨著太陽位置的變化,陰影指示的時間也會隨之變化。然而,日晷可以設計成任何表面,只要一個固定物體在該表面上投下可預測的陰影即可。
大多數日晷設計指示視太陽時。微小的設計差異可以測量標準時間和夏令時。
歷史
古埃及有 obelisk(公元前 3500 年)和 shadow clocks(公元前 1500 年)形式的日晷,並在其他文化中得到進一步發展,包括中國、希臘和羅馬文化。舊約中描述了一種沒有晷針的日晷(以賽亞書 38:2)。
據說數學家和天文學家比提尼亞的西奧多修斯(約公元前 160 年-約公元前 100 年)發明了一種可以在地球上任何地方使用的通用日晷。法國天文學家奧朗斯·菲內在 1524 年建造了一個象牙日晷。義大利天文學家喬瓦尼·帕多瓦尼在 1570 年發表了一篇關於日晷的論文,其中包括製造和佈置壁掛(垂直)和水平日晷的說明。朱塞佩·比安卡尼的《Constructio instrumenti ad horologia solaria》討論瞭如何製作一個完美的日晷,並配有插圖。
標準日晷的安裝
許多裝飾性日晷的設計是在北緯 45 度使用的。透過傾斜這種日晷,它可以被安裝在能夠保持時間的位置。然而,一些大規模生產的花園日晷由於設計不良而精度不高,無法校正。為一個緯度設計的日晷可以透過傾斜其底座來調整以在另一個緯度使用,使它的晷針或晷針平行於地球的自轉軸,使其指向北半球的天球北極,或南半球的天球南極。
一個當地的標準時區通常寬 15 度,但可能會根據地理和政治邊界進行調整。日晷可以繞其晷針或晷針(必須始終指向天球極點)旋轉,以調整到當地時區。在大多數情況下,7.5 度東至 23 度西之間的旋轉就足夠了。
要校正夏令時,一個錶盤需要兩組數字或一個校正表。一個非正式的標準是用暖色表示夏季數字,用冷色表示冬季數字。旋轉日晷效果不佳,因為大多數日晷沒有相等的時角。
普通日晷不會將視太陽時校正為鐘錶時間。由於地球的軌道略微橢圓形,並且其軸線相對於其軌道平面傾斜,因此全年存在 15 分鐘的變化,稱為時間方程。高質量的日晷將包括一個永久安裝的表格或圖表,至少提供一年中每個月的校正值。一些更復雜的日晷具有彎曲的時線、彎曲的晷針或其他排列,以便直接顯示鐘錶時間。

透過新增樣式表,外觀可以更改為

日晷
來自維基百科,自由的百科全書。
日晷是透過太陽的位置來測量時間的。最常見的日晷設計,例如“普通”或標準花園日晷,在刻有白天小時的平面上投下陰影。隨著太陽位置的變化,陰影指示的時間也會隨之變化。然而,日晷可以設計成任何表面,只要一個固定物體在該表面上投下可預測的陰影即可。
大多數日晷設計指示視太陽時。微小的設計差異可以測量標準時間和夏令時。
歷史
古埃及有 obelisk(公元前 3500 年)和 shadow clocks(公元前 1500 年)形式的日晷,並在其他文化中得到進一步發展,包括中國、希臘和羅馬文化。舊約中描述了一種沒有晷針的日晷(以賽亞書 38:2)。
據說數學家和天文學家比提尼亞的西奧多修斯(約公元前 160 年-約公元前 100 年)發明了一種可以在地球上任何地方使用的通用日晷。法國天文學家奧朗斯·菲內在 1524 年建造了一個象牙日晷。義大利天文學家喬瓦尼·帕多瓦尼在 1570 年發表了一篇關於日晷的論文,其中包括製造和佈置壁掛(垂直)和水平日晷的說明。朱塞佩·比安卡尼的《Constructio instrumenti ad horologia solaria》討論瞭如何製作一個完美的日晷,並配有插圖。
標準日晷的安裝
許多裝飾性日晷的設計是在北緯 45 度使用的。透過傾斜這種日晷,它可以被安裝在能夠保持時間的位置。然而,一些大規模生產的花園日晷由於設計不良而精度不高,無法校正。為一個緯度設計的日晷可以透過傾斜其底座來調整以在另一個緯度使用,使它的晷針或晷針平行於地球的自轉軸,使其指向北半球的天球北極,或南半球的天球南極。
一個當地的標準時區通常寬 15 度,但可能會根據地理和政治邊界進行調整。日晷可以繞其晷針或晷針(必須始終指向天球極點)旋轉,以調整到當地時區。在大多數情況下,7.5 度東至 23 度西之間的旋轉就足夠了。
要校正夏令時,一個錶盤需要兩組數字或一個校正表。一個非正式的標準是用暖色表示夏季數字,用冷色表示冬季數字。旋轉日晷效果不佳,因為大多數日晷沒有相等的時角。
普通日晷不會將視太陽時校正為鐘錶時間。由於地球的軌道略微橢圓形,並且其軸線相對於其軌道平面傾斜,因此全年存在 15 分鐘的變化,稱為時間方程。高質量的日晷將包括一個永久安裝的表格或圖表,至少提供一年中每個月的校正值。一些更復雜的日晷具有彎曲的時線、彎曲的晷針或其他排列,以便直接顯示鐘錶時間。

如何新增 CSS 樣式表

[編輯 | 編輯原始碼]

CSS 通常儲存在與 HTML 文件分開的檔案中。這樣可以使多個 HTML 文件共享一個樣式表。link 元素用於將 CSS 樣式表中的規則應用於文件。基本語法如下:

    <link rel="stylesheet" href="styles.css">

其中styles.css是樣式表的檔名、路徑或 URI。

(當您只使用一個樣式表時,為了簡單和約定,使用“styles.css”作為名稱。您可以使用多個樣式表。每個額外的樣式表都用額外的 <link> 標籤新增。在某些情況下,將 CSS 規則拆分成多個樣式表是有意義的,尤其是在處理大型網站時。在這種情況下,您應該為樣式表使用更具描述性的名稱。)

上面示例的 CSS 檔案包含以下內容

body {
  background:#ffc;
  color:#000;
  font-family:cursive
}

h1 {
  color:red;
  text-align:center;
  font-size:1.2em;
  font-weight:bold;
  margin:0
}

h2 {
  text-align:center;
  font-size:1em;
  font-weight:bold;
  margin:1em 0 0
}

p {
  text-indent:2em;
  text-align:justify;
  margin:0
}

將其儲存為styles.css

來自上一節的 HTML 文件,在第五行添加了 link 元素,如下所示。將其儲存為與styles.css同一目錄下的sundial2.htm

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Sundial</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
  </head>
  <body>
    <h1>Sundial</h1>
    <p>From Wikipedia, the free encyclopedia.</p>
    <p>A sundial measures time by the position of the sun. The most commonly seen designs, such as the
       'ordinary' or standard garden sundial, cast a shadow on a flat surface marked with the hours of
       the day. As the position of the sun changes, the time indicated by the shadow changes. However,
       sundials can be designed for any surface where a fixed object casts a predictable shadow.
    </p>
    <p>Most sundial designs indicate apparent solar time. Minor design variations can measure standard
       and daylight saving time, as well.
    </p>
    <h2>History</h2>
    <p>Sundials in the form of obelisks (3500 BC) and shadow clocks (1500 BC) are known from ancient
       Egypt, and were developed further by other cultures, including the Chinese, Greek, and Roman
       cultures. A type of sundial without gnomon is described in the old Old Testament
       (Isaiah 38:2).
    </p>
    <p>The mathematician and astronomer Theodosius of Bithynia (ca. 160 BC-ca. 100 BC) is said to have
       invented a universal sundial that could be used anywhere on Earth. The French astronomer Oronce
       Finé constructed a sundial of ivory in 1524. The Italian astronomer Giovanni Padovani published
       a treatise on the sundial in 1570, in which he included instructions for the manufacture and 
       laying out of mural (vertical) and horizontal sundials. Giuseppe Biancani's Constructio 
       instrumenti ad horologia solaria discusses how to make a perfect sundial, with accompanying 
       illustrations.
    </p>
    <h2>Installation of standard sundials</h2>
    <p>Many ornamental sundials are designed to be used at 45 degrees north. By tilting such a 
       sundial, it may be installed so that it will keep time. However, some mass-produced garden 
       sundials are inaccurate because of poor design and cannot be corrected. A sundial designed for 
       one latitude can be adjusted for use at another latitude by tilting its base so that its style 
       or gnomon is parallel to the Earth's axis of rotation, so that it points at the north celestial
       pole in the northern hemisphere, or the south celestial pole in the southern hemisphere.
    </p>
    <p>A local standard time zone is nominally 15 degrees wide, but may be modified to follow 
       geographic and political boundaries. A sundial can be rotated around its style or gnomon (which
       must remain pointed at the celestial pole) to adjust to the local time zone. In most cases, a 
       rotation in the range of 7.5 degrees east to 23 degrees west suffices.
    </p>
    <p>To correct for daylight saving time, a face needs two sets of numerals or a correction table. 
       An informal standard is to have numerals in hot colors for summer, and in cool colors for 
       winter. Rotating the sundial will not work well because most sundials do not have equal hour 
       angles.
    </p>
    <p>Ordinary sundials do not correct apparent solar time to clock time. There is a 15 minute 
       variation through the year, known as the equation of time, because the Earth's orbit is 
       slightly elliptical and its axis is tilted relative to the plane of its orbit. A quality 
       sundial will include a permanently-mounted table or graph giving this correction for at least 
       each month of the year. Some more-complex sundials have curved hour-lines, curved gnomons or 
       other arrangements to directly display the clock time.
    </p>
  </body>
</html>

用您的 Web 瀏覽器開啟sundial2.htm,您應該看到一個背景為淺黃色的頁面。

華夏公益教科書