XML

Summary

Cascading Style Sheets (CSS) were originally created for use with HTML, but they also work quite well with XML. CSS focuses purely on the positioning and formatting of XML content and doesn't involve itself with processing or otherwise translating XML code. However, when it comes to positioning and formatting XML content for display within web pages, CSS proves to be a powerful and easy-to-use technology. CSS gives you the ability to carefully control the positioning of XML content on a page and align it as desired. Once you've positioned XML content on a page, you have the option of formatting the text using a variety of different CSS style properties. Through these style properties, you can control the font, color, background, and spacing of text, which gives you considerable flexibility in determining the appearance of text.

This tutorial introduced you to CSS and how it is used to style XML documents. You got started by learning the basics of CSS, including the fundamental layout and formatting styles that are used to style XML content. You then learned how to associate an external style sheet with an XML document, which is a necessity if you plan on seeing the fruits of your CSS labors. You also found out the difference between relative and absolute positioning and how each are used to position elements. You learned about several other CSS positioning features such as z-index, margins, padding, content alignment, fonts, colors, backgrounds, and text spacing. And finally, you wrapped up the tutorial by exploring a complete CSS example that pulled together most of what you learned throughout the lesson.

Q&A

Q.

Why can't I just place style rules directly in XML code?

A.

XML code must adhere to XML syntax, which consists of elements and attributes. CSS is not an XML-based markup language, which immediately excludes its usage within XML documents using familiar XML elements and attributes. Technically, it could be possible to use inline CSS styles with XML content by way of a special attribute, such as style, which is supported in HTML. However, even this special attribute would need to be supported by the particular XML-based markup language being used in the document. Because there is no such standard XML language, the style attribute isn't recognized in XML documents for viewing in web browsers. In other words, you must use external style sheets if you plan on using CSS alone to style your XML documents.

Q.

How do you know when to use relative versus absolute positioning?

A.

Although there are no set guidelines regarding the usage of relative versus absolute positioning, the general idea is that absolute positioning is required only when you want to exert a fine degree of control over how content is positioned. This has to do with the fact that absolute positioning allows you to position content down to the exact pixel, whereas relative positioning is less exacting in terms of how it positions content. This isn't to say that relative positioning can't do a good job of positioning XML content; it just means that absolute positioning is more explicit.

Q.

If you don't specify the z-index of two elements that overlap each other, how do you know which element will appear on top?

A.

If the z-index property isn't set for overlapping elements, the element appearing later in the XML content will appear on top. The easy way to remember this is to think of a web browser drawing each element on a page as it reads it from the XML document; elements read later in the document are drawn on top of those read earlier.

Q.

Is there a way to know if a font is installed on a system when specifying it in a style sheet?

A.

No. Different users may have different fonts installed, and there is no way to predict which fonts will be available. The best solution to this problem is to use popular fonts or system fonts and always provide a secondary font that is ideally a system font.

by BrainBellupdated
Advertisement: