imgrender

样式

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

imgrender 目前只支持内联 CSS 来控制样式:

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

内联 CSS 样式

使用 style 属性设置内联样式。属性名使用标准 CSS 的连字符写法(如 font-size),属性和值之间使用 :,多个属性之间使用 ; 连接。

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

支持的样式

下表列出支持的样式属性、取值及使用限制。

属性展开属性支持值限制
displaynone, flex, inline-flex, grid, inline-grid, block, inline-block, inline, flow-root, list-item, table, table-row, table-cell, table-header-group, table-row-group, table-footer-group, table-caption;表格支持固定列宽、标题及行组排序列宽和标题间距可能与浏览器不同
positionstatic, relative, absolute, fixed;static 不应用定位偏移,fixed 相对画布定位—
directionltr, rtl;支持继承、子级覆盖及文字起始对齐—
floatleft, right, none—
clearleft, bothnone、right 可能仍将元素放在较高浮动块下方
z-index支持—
width长度、auto, fit-content, stretch;block 支持百分比inline-block 的百分比宽度可能导致背景绘制过窄,min-content、max-content 的宽度可能不符合内容尺寸,建议使用显式长度
height长度、百分比、auto, min-content, max-content, fit-content, stretch—
max-width长度、百分比、auto、none;auto 与 none 均不限制上限不支持 min-content、max-content、fit-content、stretch
max-height长度、百分比、auto、none;auto 与 none 均不限制上限不支持 min-content、max-content、fit-content、stretch
min-width长度、百分比、auto不支持 min-content、max-content、fit-content、stretch
min-height长度、百分比、auto不支持 min-content、max-content、fit-content、stretch
aspect-ratio比例值,用于计算自动宽度或高度同时指定宽高时,比例可能覆盖显式高度
containnone, style, layout, paint 及不重复的组合,content 等价于 layout style paint;layout 建立绝对定位包含块,paint 裁剪溢出不支持 size、inline-size、strict
animationanimation-name支持—
animation-duration支持—
animation-delay支持—
animation-timing-functionlinear, ease, ease-in, ease-out, ease-in-out, step-start, step-end, steps(), cubic-bezier()—
animation-iteration-count支持—
animation-direction支持—
animation-fill-mode支持—
animation-play-state支持—
paddingpadding-top, padding-right, padding-bottom, padding-left, padding-inline, padding-inline-start, padding-inline-end, padding-block支持—
marginmargin-top, margin-right, margin-bottom, margin-left, margin-inline, margin-inline-start, margin-inline-end, margin-block支持—
insettop, right, bottom, left, inset-inline, inset-block支持RTL 下 inset-inline 不交换左右端,请使用 left、right
borderborder-width (border-top-width, border-right-width, border-bottom-width, border-left-width, border-inline-width, border-block-width)长度(含 0)可见边框可能使外盒尺寸不符合预期,请显式设置 box-sizing。RTL 下 border-inline-width 不交换左右端,请使用 border-left-width、border-right-width。空元素不绘制时,移除内部缩进空白
border-stylenone, hidden, solid, dashed, dotted, double, groove, ridge, inset, outset;none 不绘制边框—
border-color支持—
border-radiusborder-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius支持—
border-top, border-right, border-bottom, border-left单边宽度、样式与颜色的组合请显式设置 box-sizing 以确定外盒尺寸
border-top-style, border-right-style, border-bottom-style, border-left-stylenone, hidden, solid, dashed, dotted, double, groove, ridge, inset, outset—
border-top-color, border-right-color, border-bottom-color, border-left-color颜色值(含 transparent)—
corner-shapecorner-top-left-shape, corner-top-right-shape, corner-bottom-left-shape, corner-bottom-right-shaperound, squircle, bevel, scoop, notch, square, superellipse(2), superellipse(0)需配合 border-radius
outlineoutline-width支持—
outline-stylenone, hidden, solid, dashed, dotted, double, groove, ridge, inset, outset;hidden 与 none 均不绘制轮廓—
outline-color支持—
outline-offset支持—
flexflex-basis长度、百分比、content, auto, min-content, max-content, fit-content, stretch—
flex-grow支持—
flex-shrink支持—
order支持—
Flexboxflex-directionrow, row-reverse, column, column-reverse—
flex-flow支持—
flex-line-count1, 2, 3配合 flex-wrap: balance 设置最小行数
-webkit-box-orienthorizontal, vertical;分别对应 flex-direction: row、column—
-webkit-box-packstart, end, center, justify;分别对应 justify-content 的 flex-start, flex-end, center, space-between—
-webkit-box-alignstart, end, center, baseline, stretch;分别对应 align-items 的 flex-start, flex-end, center, baseline, stretch—
justify-contentnormal, stretch, start, end, flex-start, flex-end, center, space-between, space-around, space-evenly;支持 safe、unsafesafe 不支持 normal、stretch 和空间分配值;溢出时 safe 回退至起始侧,unsafe 保持指定对齐
justify-self网格布局:normal, baseline, stretch, start, end, flex-start, flex-end, self-start, self-end, center;支持 safe、unsafesafe 不支持 normal、baseline、stretch;溢出时 safe 回退至起始侧,unsafe 保持指定对齐;不支持 auto
align-contentnormal, stretch, start, end, flex-start, flex-end, center, space-between, space-around, space-evenly;支持 safe、unsafesafe 不支持 normal、stretch 和空间分配值;溢出时 safe 回退至起始侧,unsafe 保持指定对齐
place-contentcenter center—
justify-items网格布局:normal, baseline, stretch, start, end, flex-start, flex-end, self-start, self-end, center;支持 safe、unsafesafe 不支持 normal、baseline、stretch;溢出时 safe 回退至起始侧,unsafe 保持指定对齐
align-items网格布局:normal, baseline, stretch, start, end, flex-start, flex-end, self-start, self-end, center;支持 safe、unsafesafe 不支持 normal、baseline、stretch;溢出时 safe 回退至起始侧,unsafe 保持指定对齐
place-items网格布局:center—
align-self网格布局:normal, baseline, stretch, start, end, flex-start, flex-end, self-start, self-end, center;支持 safe、unsafesafe 不支持 normal、baseline、stretch;溢出时 safe 回退至起始侧,unsafe 保持指定对齐;不支持 auto
place-self网格布局:end—
flex-wrapnowrap, wrap, wrap-reverse, balance, wrap balance, balance wrap, wrap-reverse balance, balance wrap-reverse;balance 可与 flex-line-count 组合,反向组合交换行的排列方向—
gap (column-gap, row-gap)支持—
object-fitcontain, cover, fill, none, scale-down—
object-positioncenter, left top, right bottom, 50% 50%—
caption-sidetop, bottom;标题位于表格上方或下方间距可能与浏览器不同
border-collapseseparate, collapse;相邻边框分别独立显示或合并—
border-spacing单值或双值长度;双值分别设置横向、纵向间距—
table-layoutauto, fixed列宽和标题间距可能与浏览器不同
overflowoverflow-x, overflow-yvisible, clip, hidden;clip 与 visible 可按独立轴裁剪hidden 与 visible 的分轴组合可能同时裁剪两轴
background颜色值组合颜色、图片、位置、尺寸和重复方式时可能只显示底色,请分别使用下列长写属性
背景长写属性background-imagelinear-gradient(), radial-gradient(), conic-gradient(), repeating-linear-gradient(), repeating-radial-gradient(), repeating-conic-gradient(), url()—
background-positionleft top, center, right bottom—
background-originborder-box, padding-box, content-box;控制背景图片定位原点—
background-sizecontain, cover, auto;支持显式宽高,如 100px 50px—
background-repeatno-repeat, repeat, repeat-x, repeat-y—
background-color支持—
background-clipcontent-box, padding-box, border-box, text;text 配合透明文字填充显示字形内背景裁剪范围受内边距、边框及盒模型影响,请显式设置 box-sizing;空元素不绘制时,移除内部缩进空白
background-blend-modenormal, multiply, screen—
box-shadow支持—
Clipclip-pathcircle(), inset(), polygon(), none不支持 ellipse(50px 30px at center)
clip-ruleevenodd, nonzero;作用于 HTML 的 polygon(),分别可留洞或填满中心;也可使用 polygon(evenodd, ...) 指定形状自身规则—
masklinear-gradient(to right, transparent, #000)组合图片、位置、尺寸和重复方式的简写不生效,请使用下列长写属性。空元素不绘制时,移除内部缩进空白
蒙版长写属性mask-imageurl(), linear-gradient(), none;配合 mask-position、mask-size、mask-repeat 设置图片蒙版空元素不绘制时,移除内部缩进空白
mask-size支持显式宽高,如 100px 50px—
mask-positionleft top, center, right bottom—
mask-repeatno-repeat, repeat, repeat-x, repeat-y—
transformtranslate(), translateX(), translateY(), rotate(), scale(), scaleX(), scaleY(), matrix(), skewX(), skewY(), none;支持函数组合,顺序影响结果仅支持二维变换。空元素不绘制时,移除内部缩进空白
二维独立变换属性translate二维位移,如 40px 20px不支持 translate-x、translate-y,可使用 transform 的 translateX()、translateY()。空元素不绘制时,移除内部缩进空白
rotate支持二维旋转,如 90deg空元素不绘制时,移除内部缩进空白
scale二维缩放,如 1.5 0.5不支持 scale-x、scale-y,可使用 transform 的 scaleX()、scaleY()。空元素不绘制时,移除内部缩进空白
transform-origincenter, 0 0, 100% 100%—
offsetpath("M 0 0 L 200 0") 50% 0deg, path("M 0 0 L 200 0") 50px auto—
offset-path直线 path()、显式中心的 circle()、ellipse() 和 polygon()ray()、inset()、border-box、content-box 的位置可能不符合预期;不支持 url()
offset-distance长度、百分比;百分比相对路径长度—
offset-rotateauto, reverse, 0deg, 90deg, auto 30deg—
offset-anchorauto, 0 0, 100% 100%不支持 center
offset-positionnormal, auto, 0 0, 50% 50%—
Gridgrid-auto-columns支持长度,如 80px—
grid-auto-rows支持长度,如 30px—
grid-auto-flowrow, column, row dense—
grid-column (grid-column-start, grid-column-end)支持数字网格线起止,如 2 / 4;支持跨度,如 2 / span 2—
grid-row (grid-row-start, grid-row-end)支持数字网格线起止,如 1 / 3—
grid-area (grid-row-start, grid-column-start, grid-row-end, grid-column-end)支持数字网格线形式,如 1 / 2 / 3 / 4不支持命名区域
grid-template-columns长度、fr、repeat() 和 minmax() 组合—
grid-template-rows长度列表和 repeat()—
list-stylesquare inside, decimal outside图片组合简写可能不生效,请使用 list-style-image
list-style-typenone, decimal, decimal-leading-zero, lower-alpha, lower-latin, upper-alpha, upper-latin, lower-roman, upper-roman 和字符串 "X"disc, circle, square 存在标记尺寸或首行占位差异
list-style-positioninside, outside;分别让标记参与首行占位或位于内容区外—
list-style-imageurl() 图片标记及 none;none 取消图片并恢复类型标记—
Typographytext-overflowellipsis, clip自定义字符串不支持,按 clip 处理
text-transformnone, uppercase, lowercase, capitalize—
font-style支持—
color支持—
text-shadow支持—
font-size支持—
font-family支持字体回退—
line-height支持长度和无单位倍数;支持换行后的行距,如 24px 字号配合 1.5 得到 36px 行距—
vertical-alignbaseline, top, bottom, middle 和长度偏移—
font-weight支持—
font-stretch支持—
font-variation-settings支持—
font-feature-settings支持—
font-variantnormal, none, small-caps需字体具备相应 OpenType 特性,不合成缺失特性
font-variant-ligaturesnormal, none, common-ligatures, no-common-ligatures, discretionary-ligatures需字体具备相应 OpenType 特性,不合成缺失特性
font-variant-numericnormal, oldstyle-nums, proportional-nums, diagonal-fractions, ordinal, slashed-zero需字体具备相应 OpenType 特性,不合成缺失特性
font-variant-east-asiannormal, jis83, jis90, full-width, proportional-width需字体具备相应 OpenType 特性,不合成缺失特性
font-variant-capsnormal, small-caps, all-small-caps, petite-caps, all-petite-caps需字体具备相应 OpenType 特性,不合成缺失特性
font-variant-positionnormal, sub, super需字体具备相应 OpenType 特性,不合成缺失特性
font-kerningauto, normal, none需字体具备相应 OpenType 特性,不合成缺失特性
font-synthesisnone, weight, style不支持 small-caps
font-synthesis-weightauto, none—
font-synthesis-styleauto, none—
line-clamp数字自定义截行标记按普通省略号处理,请使用 block-ellipsis 设置自定义标记
max-linesnone, 1, 2, 3与 continue: collapse 配合限制行数
block-ellipsisnone(无标记)、auto(省略号)、"END"(显示 END)配合 max-lines 和 continue: collapse
continuenormal, collapse;保留后续内容或在 max-lines 处截断—
text-alignleft, right, center, start, end, justify—
text-indent长度、百分比(含负值);仅缩进首行—
tab-size0, 2, 4, 8保留制表符时,每个制表符展开为对应个数的空格,与浏览器的制表位对齐方式不同
text-fitnone, grow, shrink;单行文本分别保持原字号、放大短文或缩小溢出长文以适配容器—
letter-spacing支持—
word-spacing支持—
overflow-wrapnormal, break-word, anywhere—
word-breaknormal, break-all, keep-all, break-word—
white-spacenormal, nowrap, pre, pre-wrap, pre-line, <text-wrap-mode> <white-space-collapse>;nowrap 禁止软换行、折叠连续空白,保留显式 br 换行—
white-space-collapsepreserve, collapse, preserve-spaces, preserve-breaks—
text-wraptext-wrap-modewrap, nowrap—
text-wrap-styleauto, balance, pretty—
box-sizingcontent-box, border-box—
opacity支持—
image-renderingauto, smooth, pixelated—
filterblur(), brightness(), grayscale(), hue-rotate(), invert(), opacity(), saturate(), sepia(), drop-shadow(), none;支持函数组合不支持 contrast()、url()(含局部片段和外部 SVG)
backdrop-filterblur(), brightness(), contrast(), grayscale(), hue-rotate(), invert(), opacity(), saturate(), sepia(), drop-shadow(), none 及函数组合;作用于覆盖区域后方的内容不支持 url()(含局部片段和外部 SVG)
-webkit-text-stroke-webkit-text-stroke-width, -webkit-text-stroke-color, -webkit-text-fill-color支持—
stroke-linejoinmiter, round, bevel—
text-decorationtext-decoration-lineunderline, line-through, overline, underline overline顶线需留足行高以免被裁剪,如 48px 字号使用 line-height: 72px
text-decoration-stylesolid, double, dotted, dashed, wavy双线需留足行高,如 48px 字号使用 line-height: 72px,并显式设置 text-decoration-thickness
text-decoration-color支持—
text-decoration-thickness支持—
text-decoration-skip-inkauto, none—
text-underline-offsetauto, 0, 8px, 20%;百分比相对字号—
text-underline-positionauto, from-font, under—
isolationauto, isolate—
mix-blend-modenormal, multiply, screen, darken, lighten, overlay, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color, luminosity—
visibilityvisible, hidden—

On this page