CssBuilder
The CssBuilder class implements the conversion of (Python) tags with attributes to CSS syntax.
All standard CSS names are implements. Keep in mind to remove the hyphen from the CSS name when using it (in Python
the hyphen will be interpreted as a minus.)
Do’s and don’ts
- The pointsize and leading attributes of the css tag should be defined for td, th, div. Not just for the body tag.
Debugging
Sometimes (e.g. as in the calendarmonth) it is difficult to know which class_ an XHTML tag got. Besides looking to the source code of the generated page, it is possible to add a //debugstyle to the url to see the value of all class_ attributes (if defined).
An overview
The CssBuilder class contains the following tags:| Open tag | Close tag | Attributes | Docstring or default value | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BROWSER_CAMINO | 3 | |||||||||||||||||||||||
| BROWSER_CHROME | 8 | |||||||||||||||||||||||
| BROWSER_CSSPREFIXES | ['-webkit-', '-moz-', '-o-'] | |||||||||||||||||||||||
| BROWSER_FIREFOX | 2 | |||||||||||||||||||||||
| BROWSER_IE | 4 | |||||||||||||||||||||||
| BROWSER_IPAD | 9 | |||||||||||||||||||||||
| BROWSER_IPHONE | 7 | |||||||||||||||||||||||
| BROWSER_NETSCAPE | 6 | |||||||||||||||||||||||
| BROWSER_OPERA | 5 | |||||||||||||||||||||||
| BROWSER_OSMAC | 1 | |||||||||||||||||||||||
| BROWSER_OSWINDOWS | 2 | |||||||||||||||||||||||
| BROWSER_SAFARI | 1 | |||||||||||||||||||||||
| BROWSER_UNKNOWN | 0 | |||||||||||||||||||||||
| CSS_ARG_SET | {} | |||||||||||||||||||||||
| buildcssattribute | attribute value |
The buildcssattribute builds the attribute and its value in CSS syntax.
|
||||||||||||||||||||||
| css | ids |
The self.css() tag makes it easy to write CSS (Cascading Stylesheets) language, without the problem
that browsers do not really check the syntax. On errors, they just skip the CSS definition,
which makes it hard to find them. To solve this, this tag generates all CSS code from
the parameters. The tag takes all known (and relevant) parameters, with the
only difference is that hyphens ('-') in the the names are removed. If the translation of the value encounters an error, the error is raised when the DEBUGSERVER is True. Otherwise the error is ignored, just like the browser would do with CSS. The ids attribute expects the identifier string, identical to the one in CSS syntax. All other attributes are optional. See also: http://www.w3schools.com/css/css_reference.asp For convenience some alternative attributes were added, such as x, y, z and tracking with the same result as the respectively standard attributes left, top, zaxis and letterspacing. Note that the use of these alternative parameter names should not be mixed with the standard names or else they appear double in the CSS output.
All attributes that need a pixel measuare, automatically add px to the value, so there is no need to do that on application level. Also other types of parameters are completed, e.g. the backgroundimage, which takes an relative path and adds url('...') to the code. The attributes bordertopcolor, bordertopstyle, bordertopwidth, borderrightcolor, borderrightstyle, borderrightwidth, borderleftcolor, borderleftstyle, borderleftwidth, borderbottomcolor, borderbottomstyle, borderbottomwidth are not implemented because they are not supported by many browsers. Use instead definitions as bordertop='2px dotted black'. About boxshadow: boxshadow can be applied as a string or list/tuple, e.g. "#888888 6px 6px 20px" or ("#888888", 6, 6, 60). In both way the value is converted through self.cssboxshadowvalue(). About opacity: opacity can be applied as value 0-100, but must be fraction. The builder change the value to a fraction, supported by most browsers. MSIE need the filter attribute with an alpha value 0-100. The builder adds the filter attribute automatically. opacity and filter are not w3c-css valid. See also: http://www.quirksmode.org/css/opacity.html that says: Note that an element must have layout for a filter to work. You must specify either a width or a height for any element you want to be opaque, (except for form fields, because they have a default width set). This is a consequence of the way Microsoft defines filters. Python example self.css(ids='body', fontfamily='Verdana', fontsize=14, leading=18) self.css(ids='td', backgroundimage=self.PATH_IMAGESBASE + '/bgimage.png') self.css(ids='.td head', fontweight='bold', fontsize=24, leading=28) self.css(ids='.em', fontweight='bold') self.css(ids='.transparent', opacity=40, width=200, height=100) |
||||||||||||||||||||||
| cssBrowserValue | attribute browser value |
|||||||||||||||||||||||
| cssGradientValue | endcolor startcolor type x0 x1 y0 y1 |
The cssBoxShadowValue method answers browser dependent css gradient value. self.div(style=self.cssGradientValue({'startcolor':'#fff000','endcolor':'#999999'})) self.div(style=self.cssGradientValue('#fff000','#999999')) Browser dependent formatting: background: -webkit-gradient(linear, left top, left bottom, from(#fff000), to(#999999)); background: -moz-linear-gradient(top, #fff000, #999999); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff000', endColorstr='#999999'); |
||||||||||||||||||||||
| getbrowser |
The getbrowser method answers the code of the browser.
|
|||||||||||||||||||||||
| getos |
The getos method answers the OS of the browser.
|
|||||||||||||||||||||||
| getosbrowserversion |
The getosbrowserversion method answers a tuple of (ostype, browsercode, version).
The information is interpreted and guessed from the request field 'useragent'.
This method must be maintained overtime, to add more browsers and versions. Warning: This method replaces the deprecated browser() function that is used by Environment instances to fill the e['browser'] field. |
|||||||||||||||||||||||
| media | _media | media |
The self.media() adds |
