大家好!今天開始寫我自己的博客了,希望能記錄自己每天的成長記錄。現在的我還是個小白,可能會有很多的錯誤,但是還是要寫的。希望我的好習慣能夠養成。
今天學習到的主要內容是HTML的基本語句以及表格製作。
HTML可以在文本文檔中進行編寫,同時需要將文本文檔的格式更改爲.HTML後綴。但是爲了更好的編輯體驗(省勁)( ̄▽ ̄)”推薦使用HBuilder等編輯軟件編寫。
總的來說HTML有一個大的框架,整體的模板。如下:(是HTML的解釋註釋標籤)
<HTML>
<head><!--這是網頁的頭部主要功能是進行網頁的標題編寫和網頁的配置編寫-->
<title>標題</title>
</head>
<body>
<!--這是網頁的主體部分,也就是網頁所顯示的部分。>
</body>
</HTML>
基本的簡單的標籤在這裏也不好一個一個的列舉,有興趣的話建議大家去一些學習網站像菜鳥教程,w3c等網站看一下,很詳細的教程。
鏈接:
菜鳥教程
W3C教程
在這裏我曾經遇見過編碼錯亂的問題,如果你也遇到了,可以檢查一下自己的編碼是不是UTF-8的編碼格式。對應的在HTML中是
<meta charset="UTF-8">
下面給大家介紹一下用HTML製作表格:需要了解的表格的標籤是
<table>
</table>
先給大家看一下我自己編寫的代碼再一步一步分析:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自制表格</title>
</head>
<body>
<form>
<table border="1" bordercolor="blue" cellspacing="0" align="center" width="60%">
<caption><h1>個人信息表</h1></caption>
<tr>
<td colspan="3" align="right" >用 戶 名</td>
<td colspan="9" align="left">
<input type="text"/>
</td>
</tr>
<tr>
<td colspan="3" align="right">密 碼</td>
<td colspan="9" align="left">
<input type="password" />
</td>
</tr>
<tr>
<td colspan="3" align="right">專 業</td>
<td colspan="9" align="left">
<select style="background-color:mistyrose;" >
<option>--請選擇--</option>
<option>計算機科學與技術</option>
<option>通信工程</option>
<option>電子</option>
</select>
</td>
</tr>
<tr>
<td colspan="3" align="right">性 別</td>
<td colspan="9" align="left">
<input type="radio" name="sex" />男<input type="radio" name="sex" />女<input type="radio" name="sex" />其他
</td>
</tr>
<tr>
<td colspan="3" align="right">興 趣</td>
<td colspan="9" align="left">
<input type="checkbox" />羽毛球<input type="checkbox" />籃球<input type="checkbox" />足球<input type="checkbox" />其他
</td>
</tr>
<tr>
<td colspan="3" align="right">照 片</td>
<td colspan="9" align="left">
<input type="file" />
</td>
</tr>
<tr>
<td colspan="3" align="right">介 紹</td>
<td colspan="9" align="left">
<textarea rows="6" cols="50"></textarea>
</td>
</tr>
<tr>
<td colspan="12" align="center">
<input type="submit" value="提交" /> <input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</body>
</html>
代碼效果如下:
在開頭有<!DOCTYPE html>
這句代碼的HTML文件代表着是使用HTML5的版本。(是HTML中最新的革命性版本哦~)
<table>
...
</table>
是表格的標籤形式。
<tr>
<td></td>
</tr>
其中<tr></tr>
標籤數表示行數,<td></td>
標籤數表示一行內單元格數。(有幾個<tr></tr>
標籤就有幾行,一個<tr></tr>
標籤內有幾個<td></td>
標籤在這一行內就有幾個單元格。)
<table border="1" bordercolor="blue" cellspacing="0" align="center" width="60%">
這是table的前標籤,裏面的一些東西就是它的屬性。其中,
border 屬性是表格邊框,裏面的“1”就是邊框的寬度單位是px(像素)。 如果沒有border屬性,那麼表格就會沒有邊框。
bordercolor屬性是邊框顏色。
cellspacing是邊框間距,是指單元格與單元格之間的間距。
cellpadding是單元格內間距。兩者要區分。
align屬性可以調整位置,般有align="center" align="left" align="right"
對應的是居中,居左,居右。
width屬性是表格佔屏幕的百分比寬度。
在HTML中空格推薦使用代碼 
來表示一個空格。
<tr>
<td colspan="3" align="right" >用 戶 名</td>
<td colspan="9" align="left">
<input type="text"/>
</td>
</tr>
這個表示1行2列的表格。其中input
代表輸入,後面也一樣不再介紹。
屬性colspan="3"
表示跨列(可以理解爲合併3列)同時屬性rowspan
表示跨行(行合併)。
代碼<input type="text"/>
代表文本框,可輸入可顯示的字符和文字。
同類的在我編寫的代碼中還有
代碼<input type="password" />
表示加密的文本框,可以將輸入的字符顯示成點狀。如執行結果
代碼
<select style="background-color:mistyrose;" >
<option>--請選擇--</option>
<option>計算機科學與技術</option>
<option>通信工程</option>
<option>電子</option>
</select>
表示可選擇的下拉選項框。其中<option></option>
標籤內是下拉選項。執行結果:
代碼<input type="radio" name="sex" />男<input type="radio" name="sex" />女<input type="radio" name="sex" />其他
表示單選框。執行結果:
<input type="radio"/>男
表示一個選項,但是要注意,在一個有多個選項的單選框內,要添加name屬性,讓每個選項都擁有一樣的name值。不然會出現可以多選的錯誤。
有單選就有多選,代碼:
<tr>
<td colspan="3" align="right">興 趣</td>
<td colspan="9" align="left">
<input type="checkbox" />羽毛球<input type="checkbox" />籃球<input type="checkbox" />足球<input type="checkbox" />其他
</td>
</tr>
代表多選框。其中<input type="checkbox" />羽毛球
就是一個多選選項。
執行結果:
代碼
<tr>
<td colspan="3" align="right">照 片</td>
<td colspan="9" align="left">
<input type="file" />
</td>
</tr>
實現文件輸入框。其中<input type="file" />
是文件框實現代碼。
結果:
<tr>
<td colspan="3" align="right">介 紹</td>
<td colspan="9" align="left">
<textarea rows="6" cols="50"></textarea>
</td>
</tr>
實現多行的文本輸入。其中<textarea></textarea>
標籤是實現多行可容納無限數量字符,文字的文本控件。可以通過屬性rows="6"
來實現控制文本行數,屬性cols="50"
來控制每行可輸入字符數量(即寬度)。
結果:
最後我們來介紹一下按鈕。
我目前所學的有3種實現方法。
1.<button>按鈕</button>
可實現一個沒有功能的按鈕。應用範圍廣的按鈕。(具體功能可以自己設置哦~)
2.<input type="submit" value="提交" />
可實現一個特殊的具有提交功能的按鈕。
3.<input type="reset" value="重置" />
可實現一個特殊的具有重置功能的按鈕。
結果如下:
好了,今天學的就寫這麼多吧。第一次寫微博可能寫的不太好,以後一邊學習一邊改進。希望如果你也是小白,能對你起到一點幫助。