js-components-basic-span.md 2.9 KB
Newer Older
E
ester.zhou 已提交
1
# span
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3 4 5
>  **NOTE**
>
>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6

E
ester.zhou 已提交
7 8 9
As a child component of **[\<text>](../arkui-js/js-components-basic-text.md)**, the **\<span>** component is used as a text modifier.

## Required Permissions
Z
zengyawen 已提交
10 11 12

None

E
ester.zhou 已提交
13 14

## Child Component
Z
zengyawen 已提交
15 16 17 18

Not supported


E
ester.zhou 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
## Attributes

The [universal attributes](../arkui-js/js-components-common-attributes.md) are supported.

>  **NOTE**
>
>  The **focusable** and **disabled** attributes are not supported.


## Styles

Only the following styles are supported.

| Name             | Type                        | Default Value       | Mandatory  | Description                                      |
| --------------- | -------------------------- | ---------- | ---- | ---------------------------------------- |
| color           | &lt;color&gt;              | -          | No   | Font color of the modified text.                            |
| font-size       | &lt;length&gt;             | 30px       | No   | Font size of the modified text.                            |
| allow-scale     | boolean                    | true       | No   | Whether the font size of the modified text changes with the system's font size settings.<br>If the **config-changes** tag of **fontSize** is configured for abilities in the **config.json** file, the setting takes effect without application restart.|
| font-style      | string                     | normal     | No   | Font style of the modified text. For details, see **font-style** of the [**\<text>**](../arkui-js/js-components-basic-text.md#styles) component.|
| font-weight     | number \| string | normal     | No   | Font weight of the modified text. For details, see **font-weight** of the [**\<text>**](../arkui-js/js-components-basic-text.md#styles) component.|
| text-decoration | string                     | none       | No   | Text decoration of the modified text. For details, see **text-decoration** of the [**\<text>**](../arkui-js/js-components-basic-text.md#styles) component.|
| font-family     | string                     | sans-serif | No   | Font family, in which fonts are separated by commas (,). Each font is set using a font name or font family name. The first font in the family or the specified [custom font](../arkui-js/js-components-common-customizing-font.md) is used for the text.|


## Events

Only the click event in [Universal Events](../arkui-js/js-components-common-events.md) is supported.


## Methods

Not supported


## Example

```html
Z
zengyawen 已提交
56 57 58 59 60 61 62 63
<!-- xxx.hml -->
<div class="container">
  <text class="title">
    <span class="spanTxt">span</span>
  </text>
</div>
```

E
ester.zhou 已提交
64
```css
Z
zengyawen 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
/* xxx.css */
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
.title {
  font-size: 30px;
  text-align: center;
  width: 100%;
  height: 100px;
}
.spanTxt{
  color: chartreuse;
  font-size: 100px;
}
```

E
ester.zhou 已提交
83
![en-us_image_0000001152588626](figures/en-us_image_0000001152588626.png)