Chapter 6 - Code Examples:
- fig. 6.1: inline.html - Using inline styles.
- fig. 6.2: declared.html - Declaring a style sheet in the header section.
- fig. 6.3: advanced.html - More advanced style sheets.
- External Style Sheet Examples
- fig. 6.4: styles.css - An external stylesheet.
- fig. 6.5: external.html - Linking external style sheets
- fig. 6.8: positioning.html - Positioning of elements using Absolute positioning.
- fig. 6.9: positioning2.html - Relative positioning of elements
- fig. 6.10: background.html - Adding background images and indentation
- fig. 6.11: width.html - Setting box dimension s and aligning text
- fig. 6.12: floating.html - Floating elements and element boxes.
- fig. 6.14: borders.html - Setting borders of an element.
- fig. 6.15: borders2.html - Various border styles.
- fig. 6.16: user_absolute.html - User styles
- fig. 6.17: userstyles.css - External Stylesheet with user styles.
- fig. 6.20: user_relative.html
| Link to File | Source Code |
| inline.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig.
6.1: inline.html --> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <!-- The
style attribute allows you to declare --> <p style="font-size: 20pt">This text has the <em>font-size</em> style applied to it, making it 20pt. </p> <p style="font-size: 20pt; color: #0000ff">This text has the <em>font-size</em> and <em>color</em> styles applied to it, making
it 20pt. and blue.</p> |
| declared.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig.
6.2: declared.html --> <head> <!-- this
begins the style sheet section --> </head> <!-- this
class attribute applies the .blue style --> <p>Deitel & Associates, Inc. is an internationally
recognized corporate training and publishing organization specializing in programming
languages, Internet/World Wide Web technology and object technology education.
Deitel & Associates, Inc. is a member of the World Wide Web Consortium. The
company provides courses on Java, C++, Visual Basic, C, Internet and World Wide Web
programming, and Object Technology.</p> <p class="special">The company's clients include many <em>Fortune 1000 companies</em>, government agencies, branches of the military and business organizations. Through its publishing partnership with Prentice Hall, Deitel & Associates, Inc. publishes leading-edge programming textbooks, professional books, interactive CD-ROM-based multimedia Cyber Classrooms, satellite courses and World Wide Web courses.</p> </body> |
| advanced.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig 6.3: advanced.html --> <!-- More advanced style sheets --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> </head> <ul> <ul> <li>Rice</li> <p><a class="nodec" href="http://www.food.com">Go to the Grocery store</a></p> |
| external.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.5: external.html --> <!-- Linking external style sheets --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <ul> <ul> </li> <li>Rice</li> <p><a href="http://www.food.com">Go to the Grocery store</a> </p> |
| styles.css [top] |
/* Fig. 6.4: styles.css */ /* An external stylesheet */ a { text-decoration: none }
a:hover { text-decoration: underline;
color: red;
background-color: #ccffcc }
li em { color: red;
font-weight: bold;
background-color: #ffffff }
ul { margin-left: 2cm }
ul ul { text-decoration: underline;
margin-left: .5cm }
|
| positioning.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig
6.6: positioning.html --> <body> <p style="position: absolute; top: 50px; left: 50px; z-index: 3; font-size: 20pt;"> Positioned Text</p> <p><img src="circle.gif" style="position: absolute; top: 25px; left: 100px; z-index: 2" alt="Second positioned image" / width="150" height="150"></p> </body> |
| positioning2.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.7: positioning2.html --> <head> <style type="text/css"> span { color: red; font-size: .6em; height: 1em } .super { position: relative; top: -1ex } .sub { position: relative; bottom: -1ex } .shiftleft { position: relative; left: -1ex } .shiftright { position: relative; right: -1ex } </style> <body> |
| background.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.8: background.html --> <!-- Adding background images and indentation --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Background Images</title> <style type="text/css"> body { background-image: url(logo.gif); background-position: bottom right; background-repeat: no-repeat; background-attachment: fixed; } p { font-size: 18pt; color: #aa5588; text-indent: 1em; font-family: arial, sans-serif; } .dark { font-weight: bold; } </style> </head> |
| width.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.9: width.html --> <!-- Setting box dimensions and aligning text --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Box Dimensions</title> <style type="text/css"> div { background-color: #ffccff; margin-bottom: .5em } </style> </head> <div style="width: 20%"> <p>Here is some text that goes in a box which is set to stretch across twenty precent of the width of the screen.</p> </div><div style="width: 80%; text-align: center"> <p>Here is some CENTERED text that goes in a box which is set to stretch across eighty precent of the width of the screen.</p> </div><div style="width: 20%; height: 30%; overflow: scroll"> <p>This box is only twenty percent of the width and thirty percent of the height. What do we do if it overflows? Set the overflow property to scroll!</p> </div> |
| floating.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.10: floating.html --> <!-- Floating elements and element boxes --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Flowing Text Around Floating Elements</title> <style type="text/css"> div { background-color: #ffccff; margin-bottom: .5em; font-size: 1.5em; width: 50% } p { text-align: justify; } </style> </head> <div style="float: right; margin: .5em;
text-align: right"> <p>Deitel & Associates, Inc. is an internationally recognized corporate training and publishing organization specializing in programming languages, Internet/World Wide Web technology and object technology education. Deitel & Associates, Inc. is a member of the World Wide Web Consortium. The company provides courses on Java, C++, Visual Basic, C, Internet and World Wide Web programming, and Object Technology.</p> <div style="float: right; padding: .5em; text-align:
right"> <span style="clear: right"> Here is some unflowing text. Here is some unflowing text.</span></p> </body> |
| borders.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.12: borders.html --> <!-- Setting borders of an element --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> div { text-align: center; margin-bottom: 1em; padding: .5em } .thick { border-width: thick } </head> <div class="thick
groove"> <div class="medium groove"> <div class="thin groove"> <p class="thin red inset">A thin red line...</p> <p class="medium blue outset">And a thicker blue line</p> |
| borders2.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <head> body { background-color: #ccffcc } div { text-align: center; margin-bottom: .3em; width: 50%; position: relative; left: 25%; padding: .3em } </style> <div style="border-style: solid"> <div style="border-style: double"> <div style="border-style: groove"> <div style="border-style: ridge"> <div style="border-style: inset"> <div style="border-style: outset"> </body> |
| user_absolute.html
[top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.16: user_absolute.html --> <html xmlns="http://www.w3.org/1999/xhtml"> <style type="text/css"> </head> |
| userstyles.css [top] |
/* Fig. 6.17: userstyles.css */ /* A user stylesheet */ body { font-size: 20pt;
color: yellow;
background-color: #000080 }
|
| user_relative.html [top] |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 6.20: user_relative.html --> <html xmlns="http://www.w3.org/1999/xhtml"> <style type="text/css"> .note { font-size: .75em } </style> |
This page was last updated on 3/14/2008 by Linda M. Hicks