# border

CSS 的 border 是设置元素边框属性的简写形式,用于设置一个或多个以下属性的值:border-width、border-style、border-color。

# uni-app x 兼容性

Web Android iOS
4.0 3.9 4.11

# 语法

border: <line-width> || <line-style> || <color>;

# 默认值

平台 默认值
uvue 0

# 示例

hello uni-app x

该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验

<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view style="flex-grow: 1;">
      <view>
        <text>border: 5px dotted blue</text>
        <view class="common" style="border: 5px dotted blue;"></view>
      </view>
      <view>
        <text>border与background-image同时设置</text>
        <view class="common"
          style="border-style: solid;border-color: rgba(0, 0, 255, 0.1);background-image: linear-gradient(to right, #00ff00, #00bc79)">
        </view>
      </view>
      <view>
        <text>设置border的view,通过v-show控制显示</text>
        <view v-show="shown">
          <view class="common" style="border: 5px dotted blue;">
          </view>
        </view>
      </view>
      <view>
        <text>设置border 多次赋值的场景</text>
        <view>
          <view class="common multi-times-border">
          </view>
          <view class="multi-times-border" style="width: 250px;height: 250px;">
          </view>
          <view class="multi-times-border" style="border-right: 6px solid blue; width: 250px;height: 250px;">
          </view>
          <view class="common multi-times-border" style='border: dashed'></view>
        </view>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script setup lang="uts">
  const shown = ref(false)
  setTimeout(() => {
    shown.value = true
  }, 1000);
</script>

<style>
  .common {
    width: 250px;
    height: 250px;
    background-color: gray;
  }

  .multi-times-border {
    border: 3px solid red;
    border-right-color: blue;

  }

  .common.multi-times-border {
    border-right-color: green;
  }

  .multi-times-border {
    border-right: 6px solid green;
  }
</style>

# 参见