<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="../../_utils/stylesheets/admin-tei.css"?>
<?oxygen RNGSchema="../schema/handout.rnc" type="compact"?>
<!-- To generate XHTML for browsing use the stylesheet at
  ../../_utils/stylesheets/admin.xslt. The command would be
  $ saxon css_cribsheet.xml ../../_utils/stylesheets/admin.xslt > css_cribsheet.xhtml
  presuming you have a "saxon" front-end that does the right thing.
  Could also add
  out-SystemLiteral=/Applications/oxygen/frameworks/xhtml/dtd/xhtml1-strict.dtd
  if desired.
-->
<TEI xml:lang="en-US" xmlns="http://www.tei-c.org/ns/1.0" version="P5.1.0.1">
  <teiHeader>
    <fileDesc>
      <titleStmt>
        <title>Text Encoding Fundamentals: CSS Crib Sheet</title>
        <author xml:id="jf">Julia Flanders</author>
        <author xml:id="sb">Syd Bauman</author>
      </titleStmt>
      <publicationStmt>
        <p>An unpublished document used for training.</p>
        <p>Available under GFDL, no invariant sections</p>
        <p>Copyleft 2008 Syd Bauman &amp; Julia Flanders</p>
      </publicationStmt>
      <sourceDesc>
        <p>Content adapted from <name type="filePath">../presentations/css.xml</name>.</p>
      </sourceDesc>
    </fileDesc>
    <revisionDesc>
      <change when="2008-04-24" who="#sb">
	<list>
	  <item>Corrected description of where curly-braces go</item>
	  <item>Added CSS pass-through hack to make all labels bold</item>
	  <item>Added notes on whitespace in some selectors</item>
	  <item>Used CSS pass-through to make <gi>eg</gi>s have no background color</item>
	  <item>Reversed use of "horizontal" and "Cheers" (makes more sense this way)</item>
	</list>
      </change>
      <change when="2008-04-24" who="#jf">Further small wording and capitalization tweaks.</change>
      <change when="2008-04-24" who="#sb">
	<list>
	  <item>Fixed header comment and copyleft notice</item>
	  <item>Changed URL to W3C CSS tutorial to one that I think is more correct.</item>
	  <item>A bunch of content tweaks, mostly relating to grammatical number</item>
	  <item>Changed generic example selector to have numbered property-value pairs</item>
	  <item>Added phrase-level encoding to example selector list; fixed "warning" to "horizontal"</item>
	  <item>"utf" to "UTF" in example XML decls</item>
	  <item>Added encoding to gloss lists so that code comes out more readable in XHTML version</item>
	  <item>Added moved document or stylesheet problem to trouble shooting section</item>
	</list>
      </change>
      <change when="2008-04-23" who="#jf">Created first version.</change>
    </revisionDesc>
  </teiHeader>
  <text>
    <body>
      <p>This is more of a brief reference sheet than an exhaustive
      list of CSS terms: it is intended to provide you with a way to
      look up the information you’re most likely to need right away.
      For detailed information about CSS syntax, selectors, and
      properties, visit the W3C’s CSS
      tutorial pages at <ref target="http://www.w3schools.com/css/">http://www.w3schools.com/css/</ref>.</p>

      <div type="section">
        <head>CSS Rulesets</head>

        <p>A CSS stylesheet is essentially a group of rulesets. Rulesets are made up of three
          things: <list type="gloss">
            <label rend="CSS( font-weight: bold; )">selectors </label><item>These are how you select which elements or groups of elements in your
              document will be affected by the style information.</item>
            <label rend="CSS( font-weight: bold; )">properties </label><item>These identify the style properties (such as size or color) that are
              being controlled.</item>
            <label rend="CSS( font-weight: bold; )">values </label><item>Each property has a specific value indicating the size, color, margin, or other style information that is being applied.</item>
          </list>
        </p>
        <p>The syntax for combining these into a ruleset is simple. The selector comes first,
          followed by a set of one or more property-value pairs enclosed in curly braces and
          separated by semicolons: <eg rend="CSS( background: white; )">selector { property1: value1; property2: value2; } </eg> For
          example: <eg rend="CSS( background: white; )">head { font-weight: bold; color: red;}</eg> You may have as many
          property-value pairs as you like, but they must be separated
          by semicolons. Use whitespace liberally to make your
          rulesets easy to read.</p>
      </div>

      <div type="section">
        <head>Selectors</head>

        <p>A selector is the way you identify the elements or groups of elements that will be affected
          by your style information. A selector may be simply the name of an element, or they may
          take into account the nesting of the element, or a specific attribute value. </p>
        <p>Here’s a list of the most common selectors and their syntax. </p>
        <list type="unordered">
          <item>element</item>
          <item>element descendant-element</item>
          <item>element > child-element</item>
          <item>element[attribute="value"] </item>
	  <item>element:before <emph>or</emph> element:after</item>
        </list>

        <p>Some examples: <list type="gloss">
            <label rend="CSS( font-weight: bold; )"><code>me</code></label><item> matches all <gi>me</gi> elements </item>
            <label rend="CSS( font-weight: bold; )"><code>foo > bar</code></label><item> matches each <gi>bar</gi> element that is a child of a <gi>foo</gi> element </item>
            <label rend="CSS( font-weight: bold; )"><code>foo bar</code></label><item> matches each <gi>bar</gi> element that is a descendant of a <gi>foo</gi>
              element </item>
            <label rend="CSS( font-weight: bold; )"><code>primo:first-child</code></label><item> matches each <gi>primo</gi> element that is the first child
              of its parent </item>
            <label rend="CSS( font-weight: bold; )"><code>foo[bar]</code></label><item> matches each <gi>foo</gi> element that has a <att>bar</att> attribute, whatever
              the value </item>
            <label rend="CSS( font-weight: bold; )"><code>foo[bar="horizontal"]</code></label><item> matches each <gi>foo</gi> element that has a <att>bar</att> attribute
              with the value <val>horizontal</val> </item>
            <label rend="CSS( font-weight: bold; )"><code>foo[bar~="Cheers"]</code></label><item> matches each <gi>foo</gi> element whose <att>bar</att> attribute
              value is a list of space-separated <soCalled>words</soCalled>, one of which is <q><code>Cheers</code></q></item>
	      <label rend="CSS( font-weight: bold; )"><code>foo:before</code></label><item> matches <emph>before</emph> each <gi>foo</gi>; used to insert text (using <code>content:</code> keyword) before the content</item>
          </list>
        </p>
        <p>Here are some more examples, using real-world TEI selectors, and some useful property-value pairs: <list type="gloss">
            <label rend="CSS( font-weight: bold; )"><code>div { font-family: arial, sans-serif; padding-top: 2em; }</code></label>
            <item>applies to all <gi>div</gi> elements, no matter how deeply nested</item>
            <label rend="CSS( font-weight: bold; )"><code>p { text-indent: 1em }</code></label>
            <item>indents the first line of each paragraph 1 em space</item>
            <label rend="CSS( font-weight: bold; )"><code>bibl name {font-weight: bold;}</code></label>
            <item>makes the <gi>name</gi> element bold only when it appears as a descendant of <gi>bibl</gi> </item>
            <label rend="CSS( font-weight: bold; )"><code>author > name { font-weight: bold; }</code></label>
            <item>makes the <gi>name</gi> element bold only when it is a child of <gi>author</gi> (whitespace around <q><code>></code></q> optional)
            </item>
            <label rend="CSS( font-weight: bold; )"><code>name[type="person"] {color: red;}</code></label>
            <item>applies only to <gi>name</gi> when it has <code>type="person"</code> (whitespace in front of <q><code>[</code></q> not allowed) </item>
            <label rend="CSS( font-weight: bold; )"><code>div[type="chapter"] > head {font-size:200%}</code></label>
            <item>makes chapter headings larger</item>
	    <label rend="CSS( font-weight: bold; )"><code>div[type="chap"]:before { content: "* * * * *"; text-align: center; }</code></label><item>inserts a line of asterisks before each chapter</item>
	    <label rend="CSS( font-weight: bold; )"><code>item:before { content: attr(n) ". "; }</code></label><item>inserts the value of <att>n</att>, a space, and a period before each item in a list</item>
          </list></p>
        <p> Note that multiple selectors may be used at once, separated by commas. E.g.:
            <eg rend="CSS( background: white; )">rs[type="person"], name[type="person"], persName { color: red; }</eg>
        </p>
      </div>
      <div type="section">
        <head>Properties and values </head>
        <p>Here’s a list of common properties and their most common
        kinds of values. Note that some properties (especially those
        that govern size) can be measured in several different ways.
        Some of the measurements are in absolute units such as pixels;
        others are relative to the font size (for instance, ems), and
        others are relative to the surrounding text (for instance,
        percentages or <q>larger</q> or <q> smaller</q>).
          <list type="unordered">
            <item>display: none | block | inline</item>
            <item>font-size: xx-small | x-small | small | medium | large | x-large | xx-large</item>
            <item>font-size: % | smaller | larger</item>
            <item>font-style: normal | italic | oblique</item>
            <item>font-weight: normal | bold | 900</item>
            <item>font-family: serif | sans-serif | cursive | fantasy | monospace</item>
            <item>margin-left, margin-right, margin-top, margin-bottom: 1em, 2ex</item>
            <item>padding-left, padding-right, padding-top, padding-bottom: 1em, 2ex</item>
            <item>text-align: left | right | center | justify</item>
            <item>text-indent: 1em | 48px</item>
            <item>border: thin solid blue;</item>
            <item>color: red, #99AABB</item>
	    <item>content: "stuff" | attr(<emph rend="CSS(font-style: italic;font-weight: normal;)">attr_name</emph>) | ./image.png</item>
            <item>background-color: red, #99AABB</item>
            <item>background-image: url("./image.png")</item>
            <item>background-repeat: repeat | repeat-x | repeat-y | no-repeat</item>
            <item>background-attachment: scroll | fixed</item>
            <item>background-position: ( top | center | bottom ) ( left | center | right )</item>
            <item>background-position: 20% 70%</item>
          </list>
        </p>
      </div>
      <div type="section">
	<head>Languages and Quotation Marks</head>
	<p>You can match elements in a particular language with the
	<code>:lang</code> pseudo-class. E.g.,
	<code>said:lang(fr)</code> matches <gi>said</gi> elements that
	have an <att>xml:lang</att> that indicates the natural
	language is French (e.g., <val>fr</val> or <val>fr-CA</val>).
	If a <gi>said</gi> element does not have an
	<att>xml:lang</att>, then each ancestor element is examined in
	turn until an <att>xml:lang</att> is found. If none is ever
	found, the selector does not match.</p>
	<p>There are special values to the <code>content</code>
	keyword for handling quoation marks. Namely
	<code>open-quote</code> and <code>close-quote</code>. They
	mean <q>use the appropriate string from this element’s
	<code>quotes</code> property</q>. See the following example.</p>
        <eg>said { quotes: '"' '"' "'" "'"; }                         /* generic straigt double quotes w/ nested straight singles by default */
said:lang(en) { quotes: '\201C' '\201D' '\2018' '\2019' } /* same, but curly, for English */
said:lang(fr) { quotes: '«' ' »' }                        /* guillemets for French */
said:lang(de) { quotes: '»' '«' '\2039' '\203A' }         /* reversed guillemets w/ nested single angle quotes for German */
said:before { content: open-quote; }
said:after { content: close-quote; }</eg>
      </div>
      <div type="section">
        <head>Associating a stylesheet with your XML document </head>
        <p> To tell a browser which stylesheet to use, put the following after the XML declaration 
          (but before the DOCTYPE declaration if there is one)
            <eg><![CDATA[<?xml-stylesheet type="text/css" href="filepath/my.css"?> ]]></eg> where
          <val>filepath/my.css</val> is the filepath and name of your CSS file, relative to your XML
          document. For example, here are the relevant lines from the template we provide for this
          workshop: <eg><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="../../_utils/stylesheets/yaps-tei.css"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:lang='en'> ]]></eg>
        Note that the pointer to the stylesheet (<att>href</att>) is a
        URL, so the stylesheet can also live on the web.</p>
      </div>
      <div type="section">
        <head>Tips and Trouble-shooting</head>
        <p>As you create more complex CSS stylesheets, there are a few things you can do to make your stylesheets more powerful and easy to manage:
        <list type="unordered">
        <item>Group your rulesets together by function. The stylesheet we’ve provided for this workshop lists all of the TEI elements available in our teaching schema, grouped together according to their function in the document (for instance, prose, poetry, phrase-level elements). This makes it easier to find and work with all of the elements that have a similar role.</item>
        <item>You can create multiple rulesets for the same element that control its behavior in different contexts, or with different attributes and values. For instance, you might want the <gi>quote</gi> element to look different when it is encoded as <tag>quote rend="block"</tag> or as <tag>quote rend="inline"</tag>. Make sure you don’t create multiple rulesets with identical selectors, though. </item>
        </list>
        
        </p>
        
        <p>Here are some things to check when your stylesheet isn’t working as expected:
	<list type="unordered">
	  <item>Make sure that your browser is actually reading the stylesheet&#x2014; probably the most common error we see is
	  that either the document or the stylesheet has been moved,
	  but the <att>href</att> has not been changed to reflect the
	  move</item>
	  <item>Make sure that all of your property-value pairs are separated by semicolons</item>
	  <item>Make sure every ruleset is enclosed within curly braces (don’t forget the brace
	  at the end!)</item>
	  <item>Check for typos (and especially typos in the element names, since oXygen can’t
	  check these for you)</item>
	  <item>Make sure the element you’re creating the ruleset for is really the element
	  you’re looking at in your encoding </item>
	  <item>Make sure that you don’t have two rulesets for the same element without realizing it.</item>
          </list>
        </p>

      </div>
    </body>
  </text>
</TEI>
