HTML and CSS Reference
In-Depth Information
Similar problems are associated with attributes as well. The W3C Markup Validation Service gives the error “there
is no attribute 'attrib_name'” message. The selection of allowed attributes depends on the document type being used.
For example, several attributes defined in the specification of the Transitional variant of XHTML are not allowed in Strict
XHTML documents, as described in detail in Chapter 3. Similarly, several HTML attributes are prohibited in XHTML.
Styling attributes should be provided in the CSS rather than the markup. Applying vendor-specific extensions such as
marginheight can also cause similar problems. If an element is undefined, its attributes are considered invalid too.
End Tag Errors
The W3C Markup Validation Service clearly indicates the missing end tags by the message “end tag for element
omitted, but its declaration does not permit this.” Additional (unnecessary) end tags are identified as “end tag for
element which is not open” by the W3C Markup Validation Service.
One of the easiest ways to ensure proper element closing is to write the closing tags immediately after opening
them, such as shown in Listing 15-14.
Listing 15-14. Closing Tag Provided Before Any Child Elements
<div>
</div>
Element content should not be written until the closing tag is provided. It might seem evident, but consider
that there could be hundreds of code lines between the opening and closing tags. Moreover, there might be several
identical subsequent closing tags whose opening pairs can be difficult to identify even if indentation is used, or syntax
highlighting is available in your markup editor.
Identifiers
Generally, there are two types of identifiers used in the (X)HTML markup. Naturally, class identifiers used mainly
for styling multiple elements can be applied several times within the same document—not so with the id attribute,
which should be unique throughout the document (such as a fragment identifier).
Common Style Sheet Errors
Although CSS parsers have a mechanism for handling style sheet errors [3], they should be eliminated by proper
authoring and confirmed by validation. Writing declarations with incorrect properties and nonexisting property
values are among the most common errors in CSS.
Nonexisting Properties
One of the most common CSS errors is the application of nonexisting style properties. The W3C CSS Validator clearly
indicates these errors with the message “Property doesn't exist.”
CSS name convention differs from the ones used in (X)HTML markup. The less experienced might type a CSS
property name that is logical and “should be correct.” For example, the left margin can be set with the margin-left
property, although left-margin (which does not exist) would be more logical. Even if it seems to be straightforward,
the result would be incorrect. If somebody is not familiar with the whole vocabulary of Cascading Style Sheets, all
properties should be checked in the appropriate CSS specification before applying them. Another good example is
a table data cell with vertically centralized content. In the early days of the Web when many styles were provided on
HTML attributes directly, the valign attribute was used on the td element. In CSS, however, there is no property with
the name valign . The corresponding property has a different name: vertical-align .
 
Search WWH ::




Custom Search