Backgrounds
From FHTML
Contents |
In addition to standard html background syntax, FluidHtml supports some special methods of specifying backgrounds.
1 What's the same as html?
1.1 background
- The background (shortcut) property lets you specify the following properties in any order:
background-color, background-image, background-repeat, background-attachmentandbackground-position. - (Note that FluidHtml does not support the background-attachment property. So, of the three possible values for this property (scroll, fixed and inherit), Fhtml will always default to 'scroll.')
- The following shortcut specifies: background-color, background-image, background-repeat and background-position.
<style type="text/fhtml">
#test {
background:transparent url('images/metal.jpg') repeat top left;
}
</style>
<div id="test"></div>
#test {
background:transparent url('images/metal.jpg') repeat top left;
}
</style>
<div id="test"></div>
Here are some syntax options:
background:rgba(0, 0, 100%, 100%);
background:transparent url("myPng.png") no-repeat fixed right bottom;
background:myBitmapBg; /*points to an asset */
background:url("myPing.png") myGradient bottom right no-repeat; /*gradient asset and bitmap*/
background:transparent url("myPng.png") no-repeat fixed right bottom;
background:myBitmapBg; /*points to an asset */
background:url("myPing.png") myGradient bottom right no-repeat; /*gradient asset and bitmap*/
1.2 background-color
- Accepted values:
background-color:red; /*any color name*/
background-color:rgb(255,0,0); /*rgb*/
background-color:rgba(0, 0, 100%, 100%); /*rgba*/
background-color:#ff0000; /*hexadecimal*/
background-color:myFancyBackground; /*This is a pointer to an Fhtml background asset. Fhtml supports gradients, bitmaps, pixelbender filters and swfs (and combinations thereof) as backgrounds.*/
background-color:rgb(255,0,0); /*rgb*/
background-color:rgba(0, 0, 100%, 100%); /*rgba*/
background-color:#ff0000; /*hexadecimal*/
background-color:myFancyBackground; /*This is a pointer to an Fhtml background asset. Fhtml supports gradients, bitmaps, pixelbender filters and swfs (and combinations thereof) as backgrounds.*/
- Here's a running example. Make a pale blue background. Red and green are 0, blue is 100% and alpha is 25%:
background-color:rgba(0, 0, 100%, 25%); /*rgba*/
1.3 background-image
- Use
urlto specify the path to your background image:
background-position:top left;
background-repeat:no-repeat;
background-image:url("images/panel.png");
background-repeat:no-repeat;
background-image:url("images/panel.png");
1.4 background-repeat
- Determines how (or if) your background image will be repeated. Accepted values:
- repeat
- The background image will be repeated both vertically and horizontally. This is the default.
- repeat-x
- The background image will be repeated horizontally.
- repeat-y
- The background image will be repeated vertically.
- no-repeat
- The background-image will not be repeated.
- inherit
- Inherit from parent element.
background-position:top left;
background-repeat:repeat;
background-image:url("images/panel.png");
background-repeat:repeat;
background-image:url("images/panel.png");
1.5 background-attachment
- Fhtml does not support the background-attachment property. If you pass in a value, however, no one will get hurt. Fhtml behaves as it the value you always want is 'scroll.'
1.6 background-position
- Sets the starting position of a background image. Possible values:
background-position: left top
background-position: left center
background-position: left bottom
background-position: right top
background-position: right center
background-position: right bottom
background-position: center top
background-position: center center
background-position: center bottom
background-position: x% y%
background-position: inherit
background-position: left center
background-position: left bottom
background-position: right top
background-position: right center
background-position: right bottom
background-position: center top
background-position: center center
background-position: center bottom
background-position: x% y%
background-position: inherit
- Here's a running example:
background-position:right center;
background-repeat:no-repeat;
background-image:url("images/panel.png");
background-repeat:no-repeat;
background-image:url("images/panel.png");
2 What's extra?
- Fluidhtml uses assets that can be stored and reused in an application. For more info, see Assets.
- Gradient, bitmap, pixelbender and swf backgrounds are among the types of assets that can be stored in this way.
2.1 Gradient backgrounds
- The following looks like a standard html background declaration, but instead of specifying a color, it points to a gradient stored in a <style type="xml/fhtmlassets" > node. Note that it also points to an image in the CSS, allowing you to easily combine images and gradients:
<style type="text/css">
#test {
background:gradient_5 url('images/sc-colororb0.png') no-repeat right bottom;
}
</style>
<style type="xml/fhtmlassets" >
<background
name="gradient_5" type="gradient" fillType="radial"
colors="[0, 0xFFFFFF, 0, 0xFFFFFF]"
alphas="[1, 1, 1, 1]" ratios="[.2, .3, .4, 1]"
rotation="45" width="1" height="1" spreadMethod="reflect"
focalPointRatio=".75"
/>
</style>
#test {
background:gradient_5 url('images/sc-colororb0.png') no-repeat right bottom;
}
</style>
<style type="xml/fhtmlassets" >
<background
name="gradient_5" type="gradient" fillType="radial"
colors="[0, 0xFFFFFF, 0, 0xFFFFFF]"
alphas="[1, 1, 1, 1]" ratios="[.2, .3, .4, 1]"
rotation="45" width="1" height="1" spreadMethod="reflect"
focalPointRatio=".75"
/>
</style>
- Gradients in Fhtml can be animated. Examples coming soon.
2.2 Bitmap backgrounds
- To use a bitmap background as an asset, first create a bitmap asset, then use that asset in a background asset.
<style type="text/css">
#test {
margin:20px;
w:50%;
h:25%;
border-radius:20px;
background:metal;
box-shadow:10px 10px 10px #666666;
}
</style>
<style type="xml/fhtmlassets" >
<bitmap name="metal" src="images/metal.jpg" />
<background type="bitmap" name="metal" bitmap="metal" repeat="repeat" />
</style>
<div id="test" onclick="trace(background)" ></div>
<p>Resize page</p>
#test {
margin:20px;
w:50%;
h:25%;
border-radius:20px;
background:metal;
box-shadow:10px 10px 10px #666666;
}
</style>
<style type="xml/fhtmlassets" >
<bitmap name="metal" src="images/metal.jpg" />
<background type="bitmap" name="metal" bitmap="metal" repeat="repeat" />
</style>
<div id="test" onclick="trace(background)" ></div>
<p>Resize page</p>
2.3 Pixelbender backgrounds
- To use a pixelbender as a background, first create a pixelbender asset and use it in your background asset and CSS background property:
<style type="text/css">
#test {
background:threePointGrad;
}
</style>
<style type="xml/fhtmlassets" >
<pixelbender
name="threePointGrad" src="assets/pbf/threePointGradient.pbj"
/>
<background name="threePointGrad" type="pixelbender" pixelbender="threePointGrad" />
</style>
<div id="test"></div>
#test {
background:threePointGrad;
}
</style>
<style type="xml/fhtmlassets" >
<pixelbender
name="threePointGrad" src="assets/pbf/threePointGradient.pbj"
/>
<background name="threePointGrad" type="pixelbender" pixelbender="threePointGrad" />
</style>
<div id="test"></div>
2.4 Swf backgrounds
- FluidHtml lets you use any swf as the background of an element.
- To use a swf as a background asset, you must set the swf's Document Class..
- This example also shows how you can control a swf background:
-
onclick="background.swf.getChildAt(0).stop(); - Note that
getChildAt(0)is unique to this timeline. A timeline that had no nested movieclips would be controllable withbackground.swf.stop(), etc...
-
<style type="text/css">
#test {
//background:mySwfBg url('images/sc-colororb0.png') no-repeat top left;
background:mySwfBg;
}
</style>
<style type="xml/fhtmlassets" >
<swf name="mySwf" src="assets/swf/character.swf" />
<background name="mySwfBg" type="swf" swf="mySwf" />
</style>
<div id="test" onclick="background.swf.getChildAt(0).stop();" ></div>
#test {
//background:mySwfBg url('images/sc-colororb0.png') no-repeat top left;
background:mySwfBg;
}
</style>
<style type="xml/fhtmlassets" >
<swf name="mySwf" src="assets/swf/character.swf" />
<background name="mySwfBg" type="swf" swf="mySwf" />
</style>
<div id="test" onclick="background.swf.getChildAt(0).stop();" ></div>
What we end up with is a guy and a dog running from a sphere in the top left corner! As one does...
2.5 Using scaleGrid to prevent background bitmap distortion
- Use the scaleGrid property to determine how bitmap backgrounds scale. Note how the rounded corners of the bitmap background stay the same while the rest of it scales.
- This is achieved by using
scaleGrid="{x:20, y:20, r:-20, b:-20}" - Once the example loads, resize the browser.
<style type="text/css">
div {
border:none;
box-orient:vertical;
}
#test {
w:50%;
h:50%;
background:panel;
}
</style>
<style type="xml/fhtmlassets" >
<bitmap name="panel" src="images/panel.png" />
<background type="bitmap" name="panel" bitmap="panel" repeat="repeat-scale" scaleGrid="{x:20, y:20, r:-20, b:-20}" />
</style>
<div>
<div id="test"></div>
RESIZE THIS PAGE
</div>
div {
border:none;
box-orient:vertical;
}
#test {
w:50%;
h:50%;
background:panel;
}
</style>
<style type="xml/fhtmlassets" >
<bitmap name="panel" src="images/panel.png" />
<background type="bitmap" name="panel" bitmap="panel" repeat="repeat-scale" scaleGrid="{x:20, y:20, r:-20, b:-20}" />
</style>
<div>
<div id="test"></div>
RESIZE THIS PAGE
</div>
2.6 Using repeat-scale in CSS to create a scalable background without a background asset
- FluidHtml supports a special property called
repeat-scale. - In the example below, we mark a 20px region from each edge of the background. That region will not be scaled when the background is resized.
- To do so, we specify both
repeat-scaleand a value for therepeat-scaleproperty to use:20px. In this case we add that value as the last argument in the background shortcut property. - The difference between this and the example above is that in that example, because we are using a background preset, which is defined in xml, we are free to set different values for each side of the rectangle that won't scale. In this example, we add an argument to the already bloated CSS background shortcut - and we don't want to add more than one!
<style type="text/css">
div {
border:none;
box-orient:vertical;
}
#test {
w:50%;
h:50%;
background:transparent url('images/panel.png') repeat-scale top left 20px;
}
</style>
<div>
<div id="test"></div>
RESIZE THIS PAGE
</div>
div {
border:none;
box-orient:vertical;
}
#test {
w:50%;
h:50%;
background:transparent url('images/panel.png') repeat-scale top left 20px;
}
</style>
<div>
<div id="test"></div>
RESIZE THIS PAGE
</div>







