display:block/inline/inline-block/inline-table/list-item区别

本文详细解析了display:inline-block与inline-table在网页布局中的使用场景和区别,包括它们如何影响元素的显示方式以及跨浏览器兼容性问题。重点介绍了display:inline-block在实现元素自定义宽高的灵活性,以及inline-table在特定布局需求下的局限性和解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

大家都知道 display:block是显示成块状,独占一行;

而inline是行内的意思,会根据里面的内容大小而改变;

那display:inline-block实际就是inline可以定义宽高,

但是重点是我试了一下,ie6、7不支持这个样式。


inline-table一般很少用到(ie6、7不支持这个样式),表格属于block类型,独占一行,如果想要文字跟它一行显示,就要把表格设置成inline-table,这时会发现,safari及chrome垂直对齐方式为底部对齐,火狐和ie及Opera是顶部对齐,我们可以通过vertical-align去修改对齐方式。


list-item将多个元素作为列表来显示,同时在元素的开头加上列表的标记。

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="w r"> <xsl:output method="xml" indent="yes"/> <!-- 根模板 --> <xsl:template match="/"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm" margin-top="1cm" margin-bottom="1cm" margin-left="2cm" margin-right="2cm"> <fo:region-body margin-top="1cm" margin-bottom="1cm"/> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="A4"> <fo:flow flow-name="xsl-region-body" font-family="SimSun, 宋体" language="zh-CN" line-height="1.5"> <xsl:apply-templates select="//w:body"/> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <!-- 正文处理 --> <xsl:template match="w:body"> <xsl:apply-templates select="*"/> </xsl:template> <!-- 段落处理 --> <xsl:template match="w:p"> <fo:block font-size="12pt" space-after="12pt" linefeed-treatment="preserve" wrap-option="wrap" text-align="justify"> <xsl:apply-templates select="w:r"/> </fo:block> </xsl:template> <!-- 文本运行处理 --> <xsl:template match="w:r"> <fo:inline font-family="SimSun, 宋体, Microsoft YaHei, sans-serif"> <!-- 处理粗体时使用黑体 --> <xsl:if test="w:rPr/w:b"> <xsl:attribute name="font-family">SimHei, 黑体</xsl:attribute> <xsl:attribute name="font-weight">bold</xsl:attribute> </xsl:if> <!-- 处理斜体时使用楷体 --> <xsl:if test="w:rPr/w:i"> <xsl:attribute name="font-family">KaiTi, 楷体</xsl:attribute> <xsl:attribute name="font-style">italic</xsl:attribute> </xsl:if> <xsl:value-of select="w:t"/> </fo:inline> </xsl:template> <!-- 表格处理 --> <xsl:template match="w:tbl"> <fo:table table-layout="fixed" width="100%"> <xsl:for-each select="w:tblGrid/w:gridCol"> <fo:table-column column-width="{@w:w}dxa"/> </xsl:for-each> <fo:table-body> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <!-- 表格行 --> <xsl:template match="w:tr"> <fo:table-row> <xsl:apply-templates select="w:tc"/> </fo:table-row> </xsl:template> <!-- 单元格 --> <xsl:template match="w:tc"> <fo:table-cell border="1pt solid black" padding="2pt"> <fo:block> <xsl:apply-templates select=".//w:p"/> </fo:block> </fo:table-cell> </xsl:template> <!-- 列表处理 --> <xsl:template match="w:numPr"> <fo:list-block> <xsl:apply-templates select="w:numId"/> </fo:list-block> </xsl:template> </xsl:stylesheet>使用上述样式表转出来的xsl-fo模板表格样式消失了
03-08
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="w r"> <xsl:output method="xml" indent="yes"/> <!-- 根模板 --> <xsl:template match="/"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm" margin-top="1cm" margin-bottom="1cm" margin-left="2cm" margin-right="2cm"> <fo:region-body margin-top="1cm" margin-bottom="1cm"/> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="A4"> <fo:flow flow-name="xsl-region-body" font-family="SimSun, 宋体" language="zh-CN" line-height="1.5"> <xsl:apply-templates select="//w:body"/> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <!-- 正文处理 --> <xsl:template match="w:body"> <xsl:apply-templates select="*"/> </xsl:template> <!-- 段落处理 --> <xsl:template match="w:p"> <fo:block font-size="12pt" space-after="12pt" linefeed-treatment="preserve" wrap-option="wrap" text-align="justify"> <xsl:apply-templates select="w:r"/> </fo:block> </xsl:template> <!-- 文本运行处理 --> <xsl:template match="w:r"> <fo:inline font-family="SimSun, 宋体, Microsoft YaHei, sans-serif"> <!-- 处理粗体时使用黑体 --> <xsl:if test="w:rPr/w:b"> <xsl:attribute name="font-family">SimHei, 黑体</xsl:attribute> <xsl:attribute name="font-weight">bold</xsl:attribute> </xsl:if> <!-- 处理斜体时使用楷体 --> <xsl:if test="w:rPr/w:i"> <xsl:attribute name="font-family">KaiTi, 楷体</xsl:attribute> <xsl:attribute name="font-style">italic</xsl:attribute> </xsl:if> <xsl:value-of select="w:t"/> </fo:inline> </xsl:template> <!-- 表格处理 --> <xsl:template match="w:tbl"> <fo:table table-layout="fixed" width="100%" border-collapse="collapse"> <!-- 新增边框合并属性 --> <xsl:for-each select="w:tblGrid/w:gridCol"> <!-- 修正单位转换 --> <fo:table-column column-width="{@w:w div 20}pt"/> </xsl:for-each> <fo:table-body> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <!-- 表格行 --> <xsl:template match="w:tr"> <fo:table-row> <xsl:apply-templates select="w:tc"/> </fo:table-row> </xsl:template> <!-- 单元格模板增强 --> <xsl:template match="w:tc"> <fo:table-cell border="1pt solid black" padding="2pt" display-align="center"> <!-- 新增垂直居中 --> <fo:block> <xsl:apply-templates select=".//w:p"/> </fo:block> </fo:table-cell> </xsl:template> <!-- 列表处理 --> <xsl:template match="w:numPr"> <fo:list-block> <xsl:apply-templates select="w:numId"/> </fo:list-block> </xsl:template> </xsl:stylesheet>这是我改完的xslt样式表,出现了一些不该有的换行,我应该怎么修改
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值