> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# `__GetComputedStyleByKey`

APISummary
## 介绍

返回当前 Element 某个 CSS 属性的解析值

## 语法

```jsx
__GetComputedStyleByKey(element: Element, key: string) : string;
```

### 参数

|   Key   | Description                                                   |
| :-----: | ------------------------------------------------------------- |
| element | 任意 Element 对象引用。                                              |
|   key   | 要获取的样式值对应的 CSS 属性键，是一个 String 类型，目前尚未支持所有 CSS 属性，支持情况请看兼容性部分。 |

### 返回值

当前 Element CSS 属性键所有对应的样式解析值，是一个 String 类型。

:::caution
不同于浏览器, 这个 API 不会触发页面样式更新。
:::

## 示例

前端框架可以按下如下的方法获取样式解析值。

```jsx
// main-thread.js
let page = __CreateElement('page', 0, {});

let element = __CreateElement('view', 0, {});
__SetInlineStyles(element, {
  top: '10px',
  left: '10px',
  right: '10px',
  bottom: '10px',
});

__AppendElement(page, element);
__FlushElementTree(page, {});

let width = __GetComputedStyleByKey(element, 'width');
```

## 兼容性

**Compatibility Table**

**Query:** `elements.get-computed-style-supported-properties`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/get-computed-style-supported-properties.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| get-computed-style-supported-properties | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| top | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| left | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| width | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| height | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| right | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| bottom | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| transform | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| transform-origin | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| opacity | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| color | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| background-color | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes (3.5) | Yes |
| direction | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| z-index | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| background-position | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| filter | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| margin &#38; margin-left &#38; margin-right &#38; margin-top &#38; margin-bottom | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| padding &#38; padding-left &#38; padding-right &#38; padding-top &#38; padding-bottom | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| border-width &#38; border-top-width &#38; border-bottom-width &#38; border-left-width &#38; border-right-width | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| border-radius &#38; border-top-left-radius &#38; border-top-right-radius &#38; border-bottom-right-radius &#38; border-bottom-left-radius | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| border-color &#38; border-top-color &#38; border-right-color &#38; border-bottom-color &#38; border-left-color | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes (3.6) | Yes |
| Other CSS Properties | No | No | No | Unknown | Unknown | Yes |

**`get-computed-style-supported-properties`**

__GetComputedStyleByKey

**Status:** Experimental

**`top`**

top

**Status:** Experimental

**`left`**

left

**Status:** Experimental

**`width`**

width

**Status:** Experimental

**`height`**

height

**Status:** Experimental

**`right`**

right

**Status:** Experimental

**`bottom`**

bottom

**Status:** Experimental

**`transform`**

transform

**Status:** Experimental

**`transform-origin`**

transform-origin

**Status:** Experimental

**`opacity`**

opacity

**Status:** Experimental

**`color`**

color

**Status:** Experimental

**`background-color`**

background-color

**Status:** Experimental

**`direction`**

direction

**Status:** Experimental

**`z-index`**

z-index

**Status:** Experimental

**`background-position`**

background-position

**Status:** Experimental

**`filter`**

filter

**Status:** Experimental

**`margin & margin-left & margin-right & margin-top & margin-bottom`**

margin & margin-left & margin-right & margin-top & margin-bottom

**Status:** Experimental

**`padding & padding-left & padding-right & padding-top & padding-bottom`**

padding & padding-left & padding-right & padding-top & padding-bottom

**Status:** Experimental

**`border-width & border-top-width & border-bottom-width & border-left-width & border-right-width`**

border-width & border-top-width & border-bottom-width & border-left-width & border-right-width

**Status:** Experimental

**`border-radius & border-top-left-radius & border-top-right-radius & border-bottom-right-radius & border-bottom-left-radius`**

border-radius & border-top-left-radius & border-top-right-radius & border-bottom-right-radius & border-bottom-left-radius

**Status:** Experimental

**`border-color & border-top-color & border-right-color & border-bottom-color & border-left-color`**

border-color & border-top-color & border-right-color & border-bottom-color & border-left-color

**Status:** Experimental

**`Other CSS Properties`**

Other CSS Properties

