-
-
Couldn't load subscription status.
- Fork 918
How To Use Style
In 1.0.0, most elements can be styled and customized with basic CSS styles without worrying about customRender. The style parameter is a powerful tool for customizing your HTML/Flutter page.
style takes in a Map<String, Style> (A map of CSS selectors to Style objects). Styles are automatically cascaded, so inherited values are automatically applied to children elements (e.g. you don't need to explicitly set the color of the child of a <p> tag if you've set the color of the <p> tag itself.)
Html(
data: ...,
style: {
"h1": Style(
fontFamily: 'serif',
backgroundColor: Colors.black,
color: Colors.white,
),
"p": Style(
border: Border(bottom: BorderSide(color: Colors.grey)),
padding: const EdgeInsets.all(16),
fontSize: FontSize.larger,
),
"p > a": Style(
textDecoration: TextDecoration.none,
),
"#footer": Style(
display: Display.BLOCK,
whiteSpace: WhiteSpace.PRE,
backgroundColor: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
},
),All basic CSS selectors and a few advanced CSS selectors are available for styling your HTML document. Below is a list of some of the basic CSS selectors this library supports. There are more selectors available than those listed here.
*elementelement, otherelement, ....class#idelement > childelementelement descendantelement- And more...
The Style class represents all the available CSS properties of any element. All available CSS attributes are included in this class, and any styling beyond what is available in the Style class should use customRender instead.
Color backgroundColorColor color-
Displaydisplay String fontFamily-
FontSizefontSize FontStyle fontStyleFontWeight fontWeightdouble height-
ListStyleTypelistStyleType EdgeInsets paddingEdgeInsets marginTextDecoration textDecorationTextDecorationStyle textDecorationStyle-
VerticalAlignverticalAlign -
WhiteSpacewhiteSpace double width
The following are currently available but may be changed in an upcoming version since they don't directly correlate with a CSS attribute:
String beforeString afterTextDirection textDirectionBorder borderAlignment alignmentString markerContent
There are four options available for Display. They behave in the same way that the correlated CSS options behave on the web:
Display.BLOCKDisplay.INLINEDisplay.INLINE_BLOCKDisplay.LIST_ITEM
You can pass in a pixel or percent value to FontSize or use one of the available FontSize constants.
Here are the available options:
-
FontSize(25.0)Value is in pixels. -
FontSize.percent(50)Value is a percent of the parent font size (50%). FontSize.xxSmallFontSize.xSmallFontSize.small-
FontSize.mediumThis is the default value forFontSize FontSize.largeFontSize.xLargeFontSize.xxLarge-
FontSize.smaller(83% of the parent font size) -
FontSize.larger(120% of the parent font size)
This is used on ol or ul when deciding what type of list item indicator to use. There are currently two available options:
ListStyleType.DISCListStyleType.DECIMAL
There are three available options for VerticalAlign:
-
VerticalAlign.BASELINEThe default -
VerticalAlign.SUB(Subscript baseline) -
VerticalAlign.SUPER(Superscript baseline)
You can choose whether or not to preserve whitespace in a given element. There are two available options:
-
WhiteSpace.NORMALDefault -
WhiteSpace.PREPreserves all whitespace in element and its children.
CSS, as its name implies, cascades its styles down to its children. This package replicates that behavior and the following attributes are inherited by children from their parents, which means that if you set any of these attributes on an element, all children elements will have that option applied as well.
The following attributes are inherited:
colorfontFamilyfontSizefontStylefontWeightlistStyleTypewhiteSpace