CSS 实用工具
Ionic Framework 提供了一组 CSS 实用程序类,可在任何元素上使用,以便修改文本、元素位置或调整填充和边距。
¥Ionic Framework provides a set of CSS utility classes that can be used on any element in order to modify the text, element placement or adjust the padding and margin.
如果你的应用不是使用可用的 Ionic Framework 启动器启动的,则需要包含 全局样式表的可选部分 中列出的样式表才能使这些样式正常工作。
¥If your app was not started using an available Ionic Framework starter, the stylesheets listed in the optional section of the global stylesheets will need to be included in order for these styles to work.
文本修改
¥Text Modification
文本对齐
¥Text Align
<ion-grid>
<ion-row>
<ion-col>
<div class="ion-text-start">
<h3>text-start</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-end">
<h3>text-end</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-center">
<h3>text-center</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<div class="ion-text-justify">
<h3>text-justify</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-wrap">
<h3>text-wrap</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-nowrap">
<h3>text-nowrap</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</ion-col>
</ion-row>
</ion-grid>
类 | 风格规则 | 描述 |
---|---|---|
.ion-text-left | text-align: left | 内联内容与行框的左边缘对齐。 |
.ion-text-right | text-align: right | 内联内容与行框的右边缘对齐。 |
.ion-text-start | text-align: start | 如果方向是从左到右,则与 text-left 相同;如果方向是从右到左,则与 text-right 相同。 |
.ion-text-end | text-align: end | 如果方向是从左到右,则与 text-right 相同;如果方向是从右到左,则与 text-left 相同。 |
.ion-text-center | text-align: center | 内联内容在行框内居中。 |
.ion-text-justify | text-align: justify | 内联内容是合理的。文本的间距应使其左右边缘与行框的左右边缘对齐(最后一行除外)。 |
.ion-text-wrap | white-space: normal | 空白序列被折叠。源中的换行符被视为其他空格。根据需要断行以填充行框。 |
.ion-text-nowrap | white-space: nowrap | 与 normal 一样折叠空白,但抑制文本内的换行符(文本换行)。 |
文本变换
¥Text Transform
<ion-grid>
<ion-row>
<ion-col>
<div class="ion-text-uppercase">
<h3>text-uppercase</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-lowercase">
<h3>text-lowercase</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
<ion-col>
<div class="ion-text-capitalize">
<h3>text-capitalize</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</div>
</ion-col>
</ion-row>
</ion-grid>
类 | 风格规则 | 描述 |
---|---|---|
.ion-text-uppercase | text-transform: uppercase | 强制将所有字符转换为大写。 |
.ion-text-lowercase | text-transform: lowercase | 强制将所有字符转换为小写。 |
.ion-text-capitalize | text-transform: capitalize | 强制将每个单词的第一个字母转换为大写。 |
响应式文本类
¥Responsive Text Classes
上面列出的所有文本类都有附加类来根据屏幕尺寸修改文本。使用 text-{breakpoint}-
代替每个类中的 text-
,仅在特定屏幕尺寸上使用该类,其中 {breakpoint}
是 Ionic 断点 中列出的断点名称之一。
¥All of the text classes listed above have additional classes to modify the text based on the screen size. Instead of text-
in each class, use text-{breakpoint}-
to only use the class on specific screen sizes, where {breakpoint}
is one of the breakpoint names listed in Ionic Breakpoints.
下表显示了默认行为,其中 {modifier}
是以下任意一项:left
、right
、start
、end
、center
、justify
、wrap
、nowrap
、uppercase
、lowercase
或 capitalize
,如上所述。
¥The table below shows the default behavior, where {modifier}
is any of the following: left
, right
, start
, end
, center
, justify
, wrap
, nowrap
, uppercase
, lowercase
, or capitalize
, as they are described above.
类 | 描述 |
---|---|
.ion-text-{modifier} | 将修改器应用于所有屏幕尺寸上的元素。 |
.ion-text-sm-{modifier} | 当 min-width: 576px 时,将修饰符应用于元素。 |
.ion-text-md-{modifier} | 当 min-width: 768px 时,将修饰符应用于元素。 |
.ion-text-lg-{modifier} | 当 min-width: 992px 时,将修饰符应用于元素。 |
.ion-text-xl-{modifier} | 当 min-width: 1200px 时,将修饰符应用于元素。 |
元素放置
¥Element Placement
浮动
¥Float
float CSS 属性指定元素应放置在其容器的左侧或右侧,文本和内联元素将环绕元素。这样,该元素就取自网页的正常流程,但仍保留为流程的一部分,这与绝对定位相反。
¥The float CSS property specifies that an element should be placed along the left or right side of its container, where text and inline elements will wrap around it. This way, the element is taken from the normal flow of the web page, though still remaining a part of the flow, contrary to absolute positioning.
<ion-grid>
<ion-row>
<ion-col>
<h3>no float</h3>
<img
alt="Silhouette of a person's head"
src="https://ionic.nodejs.cn/img/demos/avatar.svg"
height="50px"
/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</ion-col>
<ion-col>
<h3>float-left</h3>
<img
alt="Silhouette of a person's head"
src="https://ionic.nodejs.cn/img/demos/avatar.svg"
height="50px"
class="ion-float-left"
/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</ion-col>
<ion-col>
<h3>float-right</h3>
<img
alt="Silhouette of a person's head"
src="https://ionic.nodejs.cn/img/demos/avatar.svg"
height="50px"
class="ion-float-right"
/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
</ion-col>
</ion-row>
</ion-grid>
类 | 风格规则 | 描述 |
---|---|---|
.ion-float-left | float: left | 该元素将浮动在其包含块的左侧。 |
.ion-float-right | float: right | 该元素将浮动在其包含块的右侧。 |
.ion-float-start | float: left /float: right | 如果方向是从左到右,则与 float-left 相同;如果方向是从右到左,则与 float-right 相同。 |
.ion-float-end | float: left /float: right | 如果方向是从左到右,则与 float-right 相同;如果方向是从右到左,则与 float-left 相同。 |
响应式浮动类
¥Responsive Float Classes
上面列出的所有浮动类都有附加类来根据屏幕尺 寸修改浮动。使用 float-{breakpoint}-
代替每个类中的 float-
,仅在特定屏幕尺寸上使用该类,其中 {breakpoint}
是 Ionic 断点 中列出的断点名称之一。
¥All of the float classes listed above have additional classes to modify the float based on the screen size. Instead of float-
in each class, use float-{breakpoint}-
to only use the class on specific screen sizes, where {breakpoint}
is one of the breakpoint names listed in Ionic Breakpoints.
下表显示了默认行为,其中 {modifier}
是以下任意一项:left
、right
、start
或 end
,如上所述。
¥The table below shows the default behavior, where {modifier}
is any of the following: left
, right
, start
, or end
, as they are described above.
类 | 描述 |
---|---|
.ion-float-{modifier} | 将修改器应用于所有屏幕尺寸上的元素。 |
.ion-float-sm-{modifier} | 当 min-width: 576px 时,将修饰符应用于元素。 |
.ion-float-md-{modifier} | 当 min-width: 768px 时,将修饰符应用于元素。 |
.ion-float-lg-{modifier} | 当 min-width: 992px 时,将修饰符应用于元素。 |
.ion-float-xl-{modifier} | 当 min-width: 1200px 时,将修饰符应用于元素。 |
元素显示
¥Element Display
显示
¥Display
display CSS 属性设置元素是被视为块还是内联框,以及其子元素使用的布局,例如流布局、网格还是弹性。它还可用于在布局中完全隐藏元素。
¥The display CSS property sets whether an element is treated as a block or inline box and the layout used for its children, such as flow layout, grid or flex. It can also be used to completely hide an element from the layout.
Ionic 为 display
提供了以下实用程序类:
¥Ionic provides the following utility classes for display
:
类 | 风格规则 | 描述 |
---|---|---|
.ion-display-none | display: none | 关闭元素的显示,使其不影响布局(文档渲染时,该元素如同不存在一样)。 |
.ion-display-inline | display: inline | 该元素的行为类似于行内元素,不会在自身前后创建换行符。 |
.ion-display-inline-block | display: inline-block | 该元素的行为类似于块元素,它会像一个单独的行内框一样与周围的内容一起流动。 |
.ion-display-block | display: block | 该元素的行为类似于块元素,在正常流动时,会在自身前后创建换行符。 |
.ion-display-flex | display: flex | 该元素的行为类似于块元素,并根据弹性盒模型布 局其内容。 |
.ion-display-inline-flex | display: inline-flex | 该元素的行为类似于行内元素,并根据弹性盒模型布局其内容。 |
.ion-display-grid | display: grid | 该元素的行为类似于块元素,并根据网格模型布局其内容。 |
.ion-display-inline-grid | display: inline-grid | 该元素的行为类似于内联元素,并根据网格模型布局其内容。 |
.ion-display-table | display: table | 该元素的行为类似于 HTML <table> 元素。它定义了一个块级框。 |
.ion-display-table-cell | display: table-cell | 该元素的行为类似于 HTML <td> 元素。 |
.ion-display-table-row | display: table-row | 该元素的行为类似于 HTML <tr> 元素。 |
响应式显示类
¥Responsive Display Classes
上面列出的所有显示类都包含额外的类,可根据屏幕尺寸修改显示内容。使用 display-{breakpoint}-
代替每个类中的 display-
,仅在特定屏幕尺寸上使用该类,其中 {breakpoint}
是 Ionic 断点 中列出的断点名称之一。
¥All of the display classes listed above have additional classes to modify the display based on the screen size. Instead of display-
in each class, use display-{breakpoint}-
to only use the class on specific screen sizes, where {breakpoint}
is one of the breakpoint names listed in Ionic Breakpoints.
下表显示了默认行为,其中 {modifier}
是以下任意一项:none
、inline
、inline-block
、block
、flex
、inline-flex
、grid
、inline-grid
、table
、table-cell
、table-row
,如上所述。
¥The table below shows the default behavior, where {modifier}
is any of the following: none
, inline
, inline-block
, block
, flex
, inline-flex
, grid
, inline-grid
, table
, table-cell
, table-row
, as they are described above.
类 | 描述 |
---|---|
.ion-display-{modifier} | 将修改器应用于所有屏幕尺寸上的元素。 |
.ion-display-sm-{modifier} | 当 min-width: 576px 时,将修饰符应用于元素。 |
.ion-display-md-{modifier} | 当 min-width: 768px 时,将修饰符应用于元素。 |
.ion-display-lg-{modifier} | 当 min-width: 992px 时,将修饰符应用于元素。 |
.ion-display-xl-{modifier} | 当 min-width: 1200px 时,将修饰符应用于元素。 |
已弃用的类
¥Deprecated Classes
以下类已弃用,将在下一个主要版本中移除。请改用推荐的 .ion-display-*
类。
¥The following classes are deprecated and will be removed in the next major release. Use the recommended .ion-display-*
classes instead.
类 | 描述 |
---|---|
.ion-hide | 在所有屏幕尺寸上将 display: none 应用于元素。已弃用 — 请改用 ion-display-none 类。 |
.ion-hide-sm-{dir} | 当 min-width: 576px (up ) 或 max-width: 576px (down ) 时,将修饰符应用于元素。已弃用 — 请改用 ion-display-sm-{modifier} 类。 |
.ion-hide-md-{dir} | 当 min-width: 768px (up ) 或 max-width: 768px (down ) 时,将修饰符应用于元素。已弃用 — 请改用 ion-display-md-{modifier} 类。 |
.ion-hide-lg-{dir} | 当 min-width: 992px (up ) 或 max-width: 992px (down ) 时,将修饰符应用于元素。已弃用 — 请改用 ion-display-lg-{modifier} 类。 |
.ion-hide-xl-{dir} | 当 min-width: 1200px (up ) 或 max-width: 1200px (down ) 时,将修饰符应用于元素。已弃用 — 请改用 ion-display-xl-{modifier} 类。 |
内容空间
¥Content Space
填充
¥Padding
padding 类设置元素的填充区域。填充区域是元素内容与其边框之间的空间。
¥The padding class sets the padding area of an element. The padding area is the space between the content of the element and its border.
要应用的 padding
的默认量是 16px
,并由 --ion-padding
变量设置。有关如何更改这些值的更多信息,请参阅 CSS 变量 部分。
¥The default amount of padding
to be applied is 16px
and is set by the --ion-padding
variable. See the CSS Variables section for more information on how to change these values.
<ion-grid>
<ion-row>
<ion-col class="ion-padding">
<div>padding</div>
</ion-col>
<ion-col class="ion-padding-top">
<div>padding-top</div>
</ion-col>
<ion-col class="ion-padding-start">
<div>padding-start</div>
</ion-col>
<ion-col class="ion-padding-end">
<div>padding-end</div>
</ion-col>
</ion-row>
<ion-row>
<ion-col class="ion-padding-bottom">
<div>padding-bottom</div>
</ion-col>
<ion-col class="ion-padding-vertical">
<div>padding-vertical</div>
</ion-col>
<ion-col class="ion-padding-horizontal">
<div>padding-horizontal</div>
</ion-col>
<ion-col class="ion-no-padding">
<div>no-padding</div>
</ion-col>
</ion-row>
</ion-grid>
类 | 风格规则 | 描述 |
---|---|---|
.ion-padding | padding: 16px | 对所有面应用填充。 |
.ion-padding-top | padding-top: 16px | 将填充应用于顶部。 |
.ion-padding-start | padding-start: 16px | 将填充应用于开头。 |
.ion-padding-end | padding-end: 16px | 将填充应用到末尾。 |
.ion-padding-bottom | padding-bottom: 16px | 将填充应用到底部。 |
.ion-padding-vertical | padding: 16px 0 | 将填充应用于顶部和底部。 |
.ion-padding-horizontal | padding: 0 16px | 对左侧和右侧应用填充。 |
.ion-no-padding | padding: 0 | 不对所有边应用填充。 |
边距
¥Margin
边距区域用一个空白区域扩展了边框区域,该空白区域用于将元素与其相邻元素分开。
¥The margin area extends the border area with an empty area used to separate the element from its neighbors.
要应用的 margin
的默认量是 16px
,并由 --ion-margin
变量设置。有关如何更改这些值的更多信息,请参阅 CSS 变量 部分。
¥The default amount of margin
to be applied is 16px
and is set by the --ion-margin
variable. See the CSS Variables section for more information on how to change these values.
<ion-grid>
<ion-row>
<ion-col class="ion-margin">
<div>margin</div>
</ion-col>
<ion-col class="ion-margin-top">
<div>margin-top</div>
</ion-col>
<ion-col class="ion-margin-start">
<div>margin-start</div>
</ion-col>
<ion-col class="ion-margin-end">
<div>margin-end</div>
</ion-col>
</ion-row>
<ion-row>
<ion-col class="ion-margin-bottom">
<div>margin-bottom</div>
</ion-col>
<ion-col class="ion-margin-vertical">
<div>margin-vertical</div>
</ion-col>
<ion-col class="ion-margin-horizontal">
<div>margin-horizontal</div>
</ion-col>
<ion-col class="ion-no-margin">
<div>no-margin</div>
</ion-col>
</ion-row>
</ion-grid>
类 | 风格规则 | 描述 |
---|---|---|
.ion-margin | margin: 16px | 对所有边应用边距。 |
.ion-margin-top | margin-top: 16px | 将边距应用于顶部。 |
.ion-margin-start | margin-start: 16px | 应用左侧边距。 |
.ion-margin-end | margin-end: 16px | 将边距应用于右侧。 |
.ion-margin-bottom | margin-bottom: 16px | 将边距应用于底部。 |
.ion-margin-vertical | margin: 16px 0 | 将边距应用于顶部和底部。 |
.ion-margin-horizontal | margin: 0 16px | 对左侧和右侧应用边距。 |
.ion-no-margin | margin: 0 | 不对所有边应用边距。 |
弹性容器属性
¥Flex Container Properties
弹性框属性分为两类:控制所有弹性项目布局的容器属性,以及控制单个弹性项目的项目属性。有关项目级对齐,请参阅 弹性条目属性