分享
 
 
 

HTML Basics

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

HTML Basics

Under the covers, the Web uses the Hypertext Markup Language (HTML) to send

information to Web browsers. This common markup language can be used by any

browser, on any computer. When you request a response from a Web page,

you're getting back an HTML stream, consisting of text "marked up" with

HTML elements as tags. If you're going to generate your own Web pages, you

need to have at least a basic understanding of HTML and how it renders in

the browser.

TIP

Yes, you can get by without really understanding anything about HTML, and

our guess is that most readers already have a reasonable grasp of HTML.

However, a basic knowledge of HTML can be important, because ASP.NET

generates HTML both at design time and at runtime, and your development

experience will go more smoothly if you're comfortable with HTML.

HTML has only a handful of basic tags that you need to learn in order to

create just about any Web site you want. Most of these tags are very simple

to use. The following subsections introduce some of the more common tags

you will encounter.

HTML Elements

HTML provides a huge list of elements as well as attributes that describe

those elements. We're going to cover a tiny portion of the available HTML

functionality here, mostly so you'll recognize the HTML elements used

throughout the book. The intent here is definitely not to provide an HTML

primer, but just to make sure we're all starting at the same place. For

more information on HTML, consult the appropriate reference materials on

that topic.

TIP

HTML isn't case sensitive. You'll note in the examples that the various

elements are sometimes in uppercase letters, and other times in lowercase

letters. You'll see HTML formatted both ways. Although HTML accepts

mixed-case elements (for example, <LI></li>), other similar markup

languages (such as XML) do not. Don't mix cases like this, or sooner or

later it will bite you back.

Hyperlink

The hyperlink provides the main form of navigation on a typical Web page. A

hyperlink typically appears as a highlighted word or group of words.

Clicking the hyperlink makes a request to a particular Web server, which

responds with the requested page.

To insert a hyperlink, you use text such as this:

<a href="Page to load">Text to display</a>

Note the matching begin and end tags (<a> and </a>) and the attribute

(href="Page to load") that's included within the opening tag. Any element

can contain one or more attributes梚n this case, there's only the one href

attribute.

The following example, Main.htm, contains a number of hyperlinks. You'll

find this example in the InternetBasics folder, and you can either load it

into a text editor to see its source, shown in Listing 5.1, or double-click

to load it directly into a browser.

Listing 5.1 The Contents of Main.htm

<HTML>

<BODY>

<H3>Hyperlink</H3>

<a href="UnorderedList.htm">Unordered List</a><br>

<a href="OrderedList.htm">Ordered List</a><br>

<p>

<a href="Select.htm">Select</a><br>

<a href="Table.htm">Table</a><br>

<a href="Input.htm">Input</a><br>

</p>

</BODY>

</HTML>

Line Break

HTML output generally flows from left to right, top to bottom through a

page (this is generally called flow layout). If you want to insert a line

break yourself, you can insert the <br> tag into the document. Unlike most

HTML tags, the <br> tag doesn't require an ending tag. You can see the use

of this tag in the hyperlink example earlier.

NOTE

In order to insert a paragraph break, add a <p> element to your document.

The sample page, Main.htm, uses a <p> element to break the information into

paragraph groupings.

Bulleted List

To create a bulleted list of items, use the <UL> tag. In between the <UL>

and </UL> tags, use the <LI> and </LI> tags to create each individual list

item. The <LI> tag automatically adds a line break after each item.

To try out this sample page (see Listing 5.2), which includes an unordered

list, locate UnorderedList.htm in the InternetBasics folder.

Listing 5.2 Contents of UnorderedList.htm

<HTML>

<BODY>

<H3>Unordered list</H3>

<UL>

<LI>Arizona</LI>

<LI>California</LI>

<LI>Nevada</LI>

</UL>

</BODY>

</HTML>

Numbered List

To create a numbered list of items, use the <OL> tag. In between the <OL>

and </OL> tags, use the <LI> and </LI> tags to create each individual list

item. The <LI> tag automatically adds a line break after each item. Listing

5.3 includes an example of this technique.

To try out this sample page, which includes an ordered list, locate

OrderedList.htm in the InternetBasics folder:

Listing 5.3 Contents of OrderedList.htm

<HTML>

<BODY>

<H3>Ordered list</H3>

<OL>

<LI>Wash the car</LI>

<LI>Feed the cats</LI>

<LI>Take a nap</LI>

</OL>

</BODY>

</HTML>

Combo and List Boxes

To create a drop-down list or list box containing list items, use the

<SELECT> tag. The element supports a size attribute that allows you to

control the behavior of the control. If you set the size attribute to 1,

you'll get a drop-down (combo box) control. If you set it to a larger

value, you'll get a list box control.

Each list item in a SELECT element can contain both text, which displays in

the control itself, and a text value associated with that list item.

Listing 5.4 shows an example of this. When you're programmatically

interacting with these elements, later in the book, you'll use the values.

To try out this page, load Select.htm in the InternetBasics folder.

Listing 5.4 Contents of Select.htm

<HTML>

<BODY>

<H3>Select</H3>

<SELECT size=1>

<OPTION value="AZ">Arizona</OPTION>

<OPTION value="CA">California</OPTION>

<OPTION value="NV">Nevada</OPTION>

<OPTION value="TX">Texas</OPTION>

</SELECT>

<SELECT size=4>

<OPTION value="AZ">Arizona</OPTION>

<OPTION value="CA">California</OPTION>

<OPTION value="NV">Nevada</OPTION>

<OPTION value="TX">Texas</OPTION>

</SELECT>

</BODY>

</HTML>

Table

If you wish to create a grid containing items, use the <TABLE> tag. Within

the <TABLE> and </TABLE> tags, use a combination of <TR>, <TH>, and <TD>

tags to create each row, header, and detail cell for the table. Listing 5.5

shows an example of this.

The following page, Table.htm, demonstrates the use of a table, with rows,

cells, and headers:

Listing 5.5 Contents of Table.htm

<HTML>

<BODY>

<H3>Table</H3>

<TABLE Border=1>

<TR>

<TH>Abbr</TH>

<TH>State</TH>

</TR>

<TR>

<TD>AZ</TD>

<TD>Arizona</TD>

</TR>

<TR>

<TD>CA</TD>

<TD>California</TD>

</TR>

<TR>

<TD>NV</TD>

<TD>Nevada</TD>

</TR>

</TABLE>

</BODY>

</HTML>

Images

To display an image within a Web page, use the <IMG> tag. You must supply

the src="FileName" attribute in order to specify the name of the file that

contains the picture you wish to display. Table 5.1 contains a list of the

different types of files Internet Explorer 5 and later can display.

Table 5.1. Image Types Supported by Internet Explorer File Extension

Description

.avi Audio/Visual Interleaved (AVI)

.bmp Windows Bitmap (BMP)

.emf Windows Enhanced Metafile (EMF)

.gif Graphics Interchange Format (GIF)

.jpg, .jpeg Joint Photographic Experts Group (JPEG)

.mov Apple QuickTime Movie (MOV)

.mpg, .mpeg Motion Picture Experts Group (MPEG)

.png Portable Network Graphics (PNG)

.wmf Windows Metafile (WMF)

.xbm X Bitmap (XBM)

NOTE

Your browser might not support all the different image types listed in

Table 5.1.

To try out using an image, load the following page, Image.htm:

<HTML>

<BODY>

<H3>Pictures</H3>

<img src="Northwind.gif">

</BODY>

</HTML>

Input Types

You'll need some way to allow users to input data onto your page. You can

do this using the <INPUT> tag. You can add several attributes to this tag

to control the type of input control you get on the page, as listed in

Table 5.2.

Table 5.2. These Attributes Control the Behavior of Elements Created Using

the SELECT Tag Type Description

CheckBox Displays a box that the user can check or uncheck.

File Displays a control that will allow the user to browse for a file on

the local computer.

Hidden A value that does not show up on the user's screen but will be

submitted when the form is posted to the server.

Image Displays an image on the page.

Password Displays an asterisk for each character the user types in.

Radio Displays a mutually exclusive radio button. Use this in combination

with other radio input types to create a list that the user can select one

and only one value from.

Reset Resets all input types to their default states.

Submit Posts the form with all input values to the server.

Text An input area in which the user can enter text.

TextArea A multiline input area in which the user can enter text.

Load Input.htm to try out the sample code shown in Listing 5.6.

Listing 5.6 Contents of Input.htm

<HTML>

<BODY>

<H3>Input</H3>

<form action="Process.asp" method="post">

<table border=0>

<tr>

<td>First Name</td>

<td><input type="text" value="John"

maxlength="20" id=txtFirst></td>

</tr>

<tr>

<td>Last</td>

<td><input type="text" value="Smith"

maxlength="20" id=txtLast></td>

</tr>

<tr>

<td><input id="RadioButton1" name="Gender"

type="radio" value="Female">Female</input></td>

<td><input id="RadioButton2" name="Gender"

type="radio" value="Male">Male</input></td>

</tr>

</table>

<input type="Submit" Value="Submit">

</form>

</BODY>

</HTML>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有