imgrender

样式

使用内联 CSS 样式和 Tailwind CSS 控制元素外观

imgrender 支持两种方式控制样式:

  • 内联 CSS 样式

  • Tailwind CSS

imgrender 暂不支持使用 Style Sheets 来管理样式

内联 CSS 样式

使用 style 属性设置内联样式,支持 JSX 对象、HTML 字符串两种语法。

样式的属性名使用驼峰命名法。

<div style={{ color: 'blue', fontSize: '20px' }}>Hello imgrender</div>

应直接在标签中定义样式,不能先定义样式对象再引用

以下写法是不支持的

const style = {
  color: 'red',
  fontSize: '20px',
}
<div style={style}>Hello, imgrender</div>

样式值都将使用标准 CSS 属性值对 - property: value 表示。多个属性之间使用 ; 连接。

<div style="color: red; font-size: 20px">Hello imgrender</div>

Tailwind CSS

imgrender 内置了 Tailwind CSS 语法解析能力,你可以通过 tw 属性为元素设置 TailwindCSS 类名来控制元素样式。

样式对应的 TailwindCSS 类名请参考 TailwindCSS 官方文档

<div tw="text-red text-[20px]">Hello imgrender</div>
<div tw="text-[#50d71e]">Hello imgrender</div>

指定使用通用的衬线字体:

<div tw="font-serif">Hello imgrender</div>

指定使用 Roboto 字体:

<div tw="font-[Roboto]">Hello imgrender</div>

支持的样式

PropertyProperty ExpandedSupported Values
displaynone, flex, inline-flex, grid, inline-grid, block, inline-block, inline
positionrelative, absolute
directionSupported
floatSupported
clearSupported
zIndexSupported
widthSupported
heightSupported
maxWidthSupported
maxHeightSupported
minWidthSupported
minHeightSupported
aspectRatioSupported
animationanimationNameSupported
animationDurationSupported
animationDelaySupported
animationTimingFunctionlinear, ease, ease-in, ease-out, ease-in-out, step-start, step-end, steps(), cubic-bezier()
animationIterationCountSupported
animationDirectionSupported
animationFillModeSupported
animationPlayStateSupported
paddingpaddingTop, paddingRight, paddingBottom, paddingLeft, paddingInline, paddingBlockSupported
marginmarginTop, marginRight, marginBottom, marginLeft, marginInline, marginBlockSupported
insettop, right, bottom, left, insetInline, insetBlockSupported
borderborderWidth (borderTopWidth, borderRightWidth, borderBottomWidth, borderLeftWidth, borderInlineWidth, borderBlockWidth)Supported
borderStylesolid, none
borderColorSupported
borderRadiusborderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadiusSupported
outlineoutlineWidthSupported
outlineStylesolid, none
outlineColorSupported
outlineOffsetSupported
flexflexBasisSupported
flexGrowSupported
flexShrinkSupported
orderSupported
FlexboxflexDirectionSupported
flexFlowSupported
justifyContentSupported
justifySelfSupported
alignContentSupported
placeContentSupported
justifyItemsSupported
alignItemsSupported
placeItemsSupported
alignSelfSupported
placeSelfSupported
flexWrapnowrap, wrap, wrap-reverse
gap (columnGap, rowGap)Supported
objectFitSupported
objectPositionSupported
overflowoverflowX, overflowYvisible, clip, hidden
backgroundbackgroundImagelinear-gradient(), radial-gradient(), conic-gradient(), repeating-linear-gradient(), repeating-radial-gradient(), repeating-conic-gradient(), url()
backgroundPositionSupported
backgroundSizeSupported
backgroundRepeatSupported
backgroundColorSupported
backgroundClipSupported
backgroundBlendModeSupported
boxShadowSupported
ClipclipPath<basic-shape>
clipRuleSupported
maskmaskImageSupported
maskSizeSupported
maskPositionSupported
maskRepeatSupported
transformtranslate (translateX, translateY)Only 2D is supported
rotate
scale (scaleX, scaleY)
transformOriginSupported
GridgridAutoColumnsSupported
gridAutoRowsSupported
gridAutoFlowSupported
gridColumn (gridColumnStart, gridColumnEnd)Supported
gridRow (gridRowStart, gridRowEnd)Supported
gridArea (gridRowStart, gridColumnStart, gridRowEnd, gridColumnEnd)Supported
gridTemplateColumnsSupported
gridTemplateRowsSupported
gridTemplateAreasSupported
TypographytextOverflowellipsis, clip, custom character
textTransformnone, uppercase, lowercase, capitalize
fontStyleSupported
colorSupported
textShadowSupported
fontSizeSupported
fontFamilyFont fallback supported
lineHeightSupported
verticalAlignSupported
fontWeightSupported
fontStretchSupported
fontVariationSettingsSupported
fontFeatureSettingsSupported
fontSynthesisnone, weight, style
fontSynthesisWeightauto, none
fontSynthesisStyleauto, none
lineClampnumber, 1 "ellipsis character"
textAlignSupported
letterSpacingSupported
wordSpacingSupported
overflowWrapSupported
wordBreaknormal, break-all, keep-all, break-word
whiteSpacenormal, pre, pre-wrap, pre-line, <text-wrap-mode> <white-space-collapse>
whiteSpaceCollapsepreserve, collapse, preserve-spaces, preserve-breaks
textWraptextWrapModewrap, nowrap
textWrapStyleauto, balance, pretty
boxSizingSupported
opacitySupported
imageRenderingauto, smooth, pixelated
filter<filter-function>
backdropFilter<filter-function>
WebkitTextStrokeWebkitTextStrokeWidth, WebkitTextStrokeColor, WebkitTextFillColorSupported
strokeLinejoinmiter, round, bevel
textDecorationtextDecorationLineunderline, line-through, overline
textDecorationStylesolid
textDecorationColorSupported
textDecorationThicknessSupported
textDecorationSkipInkauto, none
isolationSupported
mixBlendModeSupported
visibilityvisible, hidden

On this page