Pr.Pg Next Pg

HTML Interview Questions and Answers Part 3


21.Can I use percentage values for <TD WIDTH=...>?

  • The HTML 3.2 and HTML 4.0 specifications allow only integer values (representing a number of pixels) for the WIDTH attribute of the TD element.

  • However, the HTML 4.0 DTD allows percentage (and other non-integer) values, so an HTML validator will not complain about <TD WIDTH="xx%">.
    It should be noted that Netscape and Microsoft's browsers interpret percentage values for <TD WIDTH=...> differently. However, their interpretations (and those of other table-aware browsers) happen to match when combined with <TABLE WIDTH="100%">.

  • In such situations, percentage values can be used relatively safely, even though they are prohibited by the public specifications.


22.Why is there extra space before or after my table?

  • This is often caused by invalid HTML syntax. Specifically, it is often caused by loose content within the table (i.e., content that is not inside a TD or TH element).

  • There is no standard way to handle loose content within a table.

  • Some browsers display all loose content before or after the table. When the loose content contains only multiple line breaks or empty paragraphs, then these browsers will display all this empty space before or after the table itself.
    The solution is to fix the HTML syntax errors. All content within a table must be within a TD or TH element.


23.How do I create a link that sends me email?

  • Use a mailto link, for example

<a href="mailto:emailaddress">Mail Me</a>


24.How can I show HTML examples without them being interpreted as part of my document?

  • Within the HTML example, first replace the "&" character with "&amp;" everywhere it occurs.

  • Then replace the "&lt;" character with "<" and the "&gt;" character with ">" in the same way.
    Note that it may be appropriate to use the CODE and/or PRE elements when displaying HTML examples.


25.HTML for Lists

  • Bulleted Lists: <ul> begins a bulleted, indented list. Each item in the list is then prefaced with the <li> tag. It is not necessary to insert a break at the end of each line -- the <li> tag automatically creates a new line.

    1. with <li type=disc>

    2. with <li type=square>

    3. with <li type=circle

  • Numbered Lists: <ol> begins a numbered, indented list. Each item in the list is then prefaced with the <li> tag. You need to close the list with the </ol> tag. Note: You can expand the <ol> to specify the TYPE of numbering:

<ol> 1 (decimal numbers: 1, 2, 3, 4, 5, ...)

<ol type="a"> a (lowercase alphabetic: a, b, c, d, e, ...)

<ol type="A"> A (uppercase alphabetic: A, B, C, D, E, ...)

<ol type="i"> i (lowercase Roman numerals: i, ii, iii, iv, v, ...)

<ol type="I"> I (uppercase Roman numerals: I, II, III, IV, V, ...)


26.Posting Copy and Paste HTML

  • For those wanting to post direct Copy and Paste HTML on screen without the use of spaces or *s etc. and the need to explain those substitutions: Use &lt; to substitute for each opening tag < in each tagged set of HTML.

  • Example: typing the following:

  • &lt; a href="">&lt; img src=""> &lt;/a> Will show up on screen as: <a href=""> <img src=""></a>


27.How do I eliminate the blue border around linked images?

  • In your HTML, you can specify the BORDER attribute for the image:

<a ref=...><img src=... alt=... border="0"></a>

  • However, note that removing the border that indicates an image is a link makes it harder for users to distinguish quickly and easily which images on a web page are clickable.


28.How do I eliminate the space around/between my images?

  • If your images are inside a table, be sure to set the BORDER, CELLSPACING, and CELLPADDING attributes to 0.

  • Extra space between images is often created by whitespace around the <IMG> tag in the markup. It is safe to use newlines inside a tag (between attributes), but not between two tags. For example, replace this:

<td ...>

<img src=... alt=...>

<img src=... alt=...>


with this:

<td ...><img src=... alt=...><img src=... alt=...></td>

  • According to the latest specifications, the two should be equivalent. However, common browsers do not comply with the specifications in this situation.

  • Finally, extra space between images can appear in documents that trigger the "standards" rendering mode of Gecko-based browsers like Mozilla and Firefox.


29.How can I specify colors?

  • If you want others to view your web page with specific colors, the most appropriate way is to suggest the colors with a style sheet.

  • Cascading Style Sheets use the color and background-color properties to specify text and background colors.

  • To avoid conflicts between the reader's default colors and those suggested by the author, these two properties should always be used together.

  • With HTML, you can suggest colors with the TEXT, LINK, VLINK (visited link), ALINK (active link), and BGCOLOR (background color) attributes of the BODY element.

  • Note that these attributes are deprecated by HTML 4. Also, if one of these attributes is used, then all of them should be used to ensure that the reader's default colors do not interfere with those suggested by the author.

  • Here is an example:

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#000080">
Authors should not rely on the specified colors since browsers allow their users to override document-specified colors.


30.Can I prevent a form from being submitted again?

  • No. The server-side (e.g., CGI) program that processes the form submission must handle duplicate submissions gracefully.

  • You could generate the form with a server-side (e.g., CGI) program that adds a hidden field with a unique session ID.

  • Then the server-side program that processes the form submission can check the session ID against a list of previously used session IDs. I

  • f the session ID has already been used, then an appropriate action can be taken (e.g., reject the submission, or update the previously submitted data).
    Ultimately, your server-side program must be smart enough to handle resubmitted data. But you can avoid getting resubmitted data by not expiring the confirmation page from form submissions.

  • Since you want to expire pages quickly when they have transient data, you might want to avoid putting transient data on the confirmation page.

  • You could provide a link to a database query that returns transient data though.

Pr.Pg Next Pg