Skip to main content

ion-button

shadow

按钮提供了可点击的元素,可以在表单中或任何需要简单、标准按钮功能的地方使用。它们可能显示文本、图标或两者兼而有之。可以使用多个属性对按钮进行样式设置,以使其具有特定的外观。

¥Buttons provide a clickable element, which can be used in forms, or anywhere that needs simple, standard button functionality. They may display text, icons, or both. Buttons can be styled with several attributes to look a specific way.

基本用法

¥Basic Usage

展开

¥Expand

此属性允许你指定按钮的宽度。默认情况下,按钮具有 display: inline-block,但设置此属性会将按钮更改为具有 display: block 的全角元素。

¥This property lets you specify how wide the button should be. By default, buttons have display: inline-block, but setting this property will change the button to a full-width element with display: block.

形状

¥Shape

此属性允许你指定按钮的形状。默认情况下,按钮是矩形,边框半径较小,但将其设置为 "round" 会将按钮更改为圆形元素。

¥This property lets you specify the shape of the button. By default, buttons are rectangular with a small border radius, but setting this to "round" will change the button to a rounded element.

填充

¥Fill

该属性决定按钮的背景和边框颜色。默认情况下,按钮具有纯色背景,除非按钮位于工具栏内部,在这种情况下,按钮具有透明背景。

¥This property determines the background and border color of the button. By default, buttons have a solid background unless the button is inside of a toolbar, in which case it has a transparent background.

尺寸

¥Size

该属性指定按钮的大小。设置此属性将更改按钮的高度和填充。

¥This property specifies the size of the button. Setting this property will change the height and padding of a button.

图标

¥Icons

主题化

¥Theming

颜色

¥Colors

CSS 自定义属性

¥CSS Custom Properties

无障碍

¥Accessibility

按钮被设计为易于访问,但可能需要根据其内容进行一些调整。按钮组件渲染原生 按钮元素,使其能够利用原生按钮提供的功能。

¥Buttons are built to be accessible, but may need some adjustments depending on their content. The button component renders a native button element which allows it to take advantage of the functionality that a native button provides.

文本内容溢出

¥Overflowing Text Content

在很多情况下,按钮的文本内容可能会溢出容器。建议在发生这种情况时将文本封装在按钮内,以便仍然可以阅读所有文本。按钮组件将自动调整其高度以容纳额外的文本行。

¥There are many cases where a button's text content may overflow the container. It is recommended to wrap the text inside of the button when this happens so that all of the text can still be read. The button component will automatically adjust its height to accommodate the extra lines of text.

当文本太长而无法容纳时,按钮文本不会自动换行到下一行。为了使文本换行,可以添加 ion-text-wrap 类,这会将 white-space 属性设置为 "normal"。这将成为未来主要版本中的默认设置。

¥The button text does not automatically wrap to the next line when the text is too long to fit. In order to make the text wrap, the ion-text-wrap class can be added, which will set the white-space property to "normal". This will become the default in a future major release.

信息

在下面的按钮上设置 max-width 样式仅用于演示目的。文本换行将与动态按钮宽度一起使用。

¥The max-width style is set on the button below for demo purposes only. Text wrapping will work with a dynamic button width.

属性

¥Properties

buttonType

DescriptionThe type of button.
Attributebutton-type
Typestring
Default'button'

color

DescriptionThe color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.
Attributecolor
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined
Defaultundefined

disabled

DescriptionIf true, the user cannot interact with the button.
Attributedisabled
Typeboolean
Defaultfalse

download

DescriptionThis attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want).
Attributedownload
Typestring | undefined
Defaultundefined

expand

DescriptionSet to "block" for a full-width button or to "full" for a full-width button with square corners and no left or right borders.
Attributeexpand
Type"block" | "full" | undefined
Defaultundefined

fill

DescriptionSet to "clear" for a transparent button that resembles a flat button, to "outline" for a transparent button with a border, or to "solid" for a button with a filled background. The default fill is "solid" except inside of a toolbar, where the default is "clear".
Attributefill
Type"clear" | "default" | "outline" | "solid" | undefined
Defaultundefined

form

DescriptionThe HTML form element or form element id. Used to submit a form when the button is not a child of the form.
Attributeform
TypeHTMLFormElement | string | undefined
Defaultundefined

href

DescriptionContains a URL or a URL fragment that the hyperlink points to. If this property is set, an anchor tag will be rendered.
Attributehref
Typestring | undefined
Defaultundefined

mode

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" | "md"
Defaultundefined

rel

DescriptionSpecifies the relationship of the target object to the link object. The value is a space-separated list of link types.
Attributerel
Typestring | undefined
Defaultundefined

routerAnimation

DescriptionWhen using a router, it specifies the transition animation when navigating to another page using href.
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) | undefined
Defaultundefined

routerDirection

DescriptionWhen using a router, it specifies the transition direction when navigating to another page using href.
Attributerouter-direction
Type"back" | "forward" | "root"
Default'forward'

shape

DescriptionSet to "round" for a button with more rounded corners.
Attributeshape
Type"round" | undefined
Defaultundefined

size

DescriptionSet to "small" for a button with less height and padding, to "default" for a button with the default height and padding, or to "large" for a button with more height and padding. By default the size is unset, unless the button is inside of an item, where the size is "small" by default. Set the size to "default" inside of an item to make it a standard size button.
Attributesize
Type"default" | "large" | "small" | undefined
Defaultundefined

strong

DescriptionIf true, activates a button with a heavier font weight.
Attributestrong
Typeboolean
Defaultfalse

target

DescriptionSpecifies where to display the linked URL. Only applies when an href is provided. Special keywords: "_blank", "_self", "_parent", "_top".
Attributetarget
Typestring | undefined
Defaultundefined

type

DescriptionThe type of the button.
Attributetype
Type"button" | "reset" | "submit"
Default'button'

事件

¥Events

NameDescriptionBubbles
ionBlurEmitted when the button loses focus.true
ionFocusEmitted when the button has focus.true

方法

¥Methods

No public methods available for this component.

CSS 阴影部分

¥CSS Shadow Parts

NameDescription
nativeThe native HTML button or anchor element that wraps all child elements.

CSS 自定义属性

¥CSS Custom Properties

NameDescription
--backgroundBackground of the button
--background-activatedBackground of the button when pressed. Note: setting this will interfere with the Material Design ripple.
--background-activated-opacityOpacity of the button when pressed
--background-focusedBackground of the button when focused with the tab key
--background-focused-opacityOpacity of the button when focused with the tab key
--background-hoverBackground of the button on hover
--background-hover-opacityOpacity of the background on hover
--border-colorBorder color of the button
--border-radiusBorder radius of the button
--border-styleBorder style of the button
--border-widthBorder width of the button
--box-shadowBox shadow of the button
--colorText color of the button
--color-activatedText color of the button when pressed
--color-focusedText color of the button when focused with the tab key
--color-hoverText color of the button when hover
--opacityOpacity of the button
--padding-bottomBottom padding of the button
--padding-endRight padding if direction is left-to-right, and left padding if direction is right-to-left of the button
--padding-startLeft padding if direction is left-to-right, and right padding if direction is right-to-left of the button
--padding-topTop padding of the button
--ripple-colorColor of the button ripple effect
--transitionTransition of the button

插槽

¥Slots

NameDescription
``Content is placed between the named slots if provided without a slot.
endContent is placed to the right of the button text in LTR, and to the left in RTL.
icon-onlyShould be used on an icon in a button that has no text.
startContent is placed to the left of the button text in LTR, and to the right in RTL.