Skip to content
  • Promote Your Product

Style Guide ​

CSS Approach ​

The project uses UnoCSS + SCSS styling approach:

  • UnoCSS: Atomic CSS engine, similar to Tailwind CSS
  • SCSS: Traditional preprocessor for complex style logic
  • wot-ui Style Variables: UI component library theme variables

UnoCSS Configuration ​

Configuration file: uno.config.ts

Basic Configuration ​

typescript
// uno.config.ts
import {
  defineConfig,
  presetUno,
  presetAttributify,
  presetIcons,
} from 'unocss'
import presetWot from '@wot-ui/unocss-preset'

export default defineConfig({
  presets: [
    presetUno(),            // Default preset (Tailwind compatible)
    presetAttributify(),    // Attribute mode
    presetIcons(),          // Icon support
    presetWot(),           // wot-ui preset
  ],
  // Custom shortcuts
  shortcuts: {
    // Center flex
    'flex-center': 'flex items-center justify-center',
    // Space between
    'flex-between': 'flex items-center justify-between',
    // Common text styles
    'text-primary': 'text-[--color-primary]',
    'text-secondary': 'text-gray-500',
  },
})

Atomic Class Usage Guide ​

Layout ​

vue
<template>
  <!-- Flex layout -->
  <view class="flex items-center justify-between p-4">
    <text class="text-lg font-bold">Title</text>
    <button text-sm>Button</button>
  </view>
  
  <!-- Grid layout -->
  <view class="grid grid-cols-3 gap-4">
    <view class="item">1</view>
    <view class="item">2</view>
    <view class="item">3</view>
  </view>
</template>

Sizing ​

scss
.container {
  /* Fixed width */
  w-full;          /* 100% */
  w-screen;        /* 100vw */
  
  /* Fixed height */
  h-full;          /* 100% */
  h-screen;        /* 100vh */
  
  /* Custom sizes */
  w-100px;
  h-50%;
  
  /* Max/min sizes */
  max-w-screen-md;
  min-h-screen;
}

Spacing ​

scss
/* Padding */
p-4;        /* padding: 1rem */
px-4;       /* padding-left/right: 1rem */
py-2;       /* padding-top/bottom: 0.5rem */

/* Margin */
m-4;        /* margin: 1rem */
mt-4;       /* margin-top: 1rem */
mb-auto;    /* margin-bottom: auto */

/* Gap (Flex/Grid child spacing) */
gap-2;      /* gap: 0.5rem */
gap-x-4;    /* column-gap: 1rem */

Typography ​

scss
/* Size */
text-xs;    /* 0.75rem */
text-sm;    /* 0.875rem */
text-base;  /* 1rem */
text-lg;    /* 1.125rem */
text-xl;    /* 1.25rem */
text-2xl;   /* 1.5rem */

/* Weight */
font-normal;    /* 400 */
font-medium;    /* 500 */
font-semibold;  /* 600 */
font-bold;      /* 700 */

/* Alignment */
text-left;
text-center;
text-right;

/* Other */
leading-tight;     /* Tight line height */
leading-relaxed;   /* Loose line height */
tracking-wide;    /* Letter spacing */
truncate;         /* Text truncation with ellipsis */

Colors ​

scss
/* Named colors */
text-red-500;
bg-blue-100;
border-gray-300;

/* Opacity */
text-black/50;       /* rgba(0,0,0,0.5) */
bg-white/80;

/* CSS variables */
text-[--color-primary];
bg-[--bg-color];

/* Arbitrary values */
text-[#1890ff];
bg-[rgb(24,144,255)];

Borders ​

scss
:border;             /* 1px solid currentColor */
border-2;           /* 2px solid */
border-t;           /* Top border */
border-dashed;      /* Dashed */
rounded;            /* Border radius */
rounded-full;       /* Circle */
rounded-lg;         /* Large radius */

Display & Positioning ​

scss
/* Display */
:block;
:inline-block;
:inline-flex;
:hidden;             /* display: none */

/* Positioning */
:relative;
:absolute;
:fixed;
:sticky;
top-0;
left-0;
right-0;
bottom-0;

/* Overflow */
overflow-hidden;
overflow-auto;
overflow-x-auto;

Responsive Breakpoints ​

scss
/* Mobile adaptation */
sm:text-base;       /* >= 640px */
md:text-lg;         /* >= 768px */
lg:text-xl;         /* >= 1024px */
xl:text-2xl;        /* >= 1280px */

SCSS Usage ​

Global Variables ​

Define variables in uni.scss or components:

scss
/* uni.scss */
$primary-color: #1890ff;
$success-color: #52c41a;
$warning-color: #faad14;
$error-color: #f5222d;
$text-color: #333333;
$text-color-secondary: #666666;
$border-color: #d9d9d9;
$bg-color: #f5f5f5;

/* Safe area */
$safe-area-inset-bottom: constant(safe-area-inset-bottom);
$safe-area-inset-bottom-env: env(safe-area-inset-bottom);

Using in Components ​

vue
<style lang="scss" scoped>
.container {
  background-color: $bg-color;
  border: 1px solid $border-color;
  padding: $spacing-md;
  
  .title {
    color: $text-color;
    font-size: $font-size-lg;
    font-weight: bold;
  }
  
  &.active {
    background-color: $primary-color;
    color: white;
  }
}
</style>

Mixins ​

Common Mixin examples:

scss
/* mixins.scss */
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

@mixin text-ellipsis($lines: 1) {
  @if $lines == 1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  } @else {
    display: -webkit-box;
    -webkit-line-clamp: $lines;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@mixin safe-area-bottom {
  padding-bottom: $safe-area-inset-bottom;
  padding-bottom: $safe-area-inset-bottom-env;
}

/* Usage */
.card {
  @include flex-center;
  
  .title {
    @include text-ellipsis(2);
  }
}

wot-ui Theme Customization ​

CSS Variable Override ​

Customize wot-ui component styles via CSS variables:

css
:root {
  --color-primary: #1890ff;
  --color-success: #52c41a;
  --color-warning: #faad14;
  --color-danger: #ff4d4f;
  
  --navbar-height: 44px;
  --tabbar-height: 50px;
}

Component-level Style Override ​

vue
<style scoped>
/* Override wot-ui internal styles (requires :deep()) */
::deep(.wd-button) {
  border-radius: 8px;
}

::deep(.wd-navbar__title) {
  font-weight: 600;
}
</style>

Mobile Adaptation ​

rpx Units ​

UniApp-specific unit, adapts to screen width:

scss
.box {
  width: 750rpx;      /* Relative to screen width */
  height: 200rpx;
  font-size: 28rpx;
  padding: 30rpx;
}

Design Draft Adaptation ​

Design draft width 750rpx, conversion relationship:

  • Design draft 1px = 1rpx
  • On iPhone 6/7/8, 1rpx = 0.5px
  • On iPhone X and above, 1rpx calculated based on actual width

Safe Area ​

Bottom safe area adaptation:

scss
.page-content {
  padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
  padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
}

Style Best Practices ​

1. Prioritize Atomic Classes ​

Use UnoCSS atomic classes for simple styles:

vue
<!-- Recommended -->
<view class="flex items-center p-4 bg-white rounded-lg shadow">

<!-- Not recommended -->
<view class="container">

2. Use SCSS for Complex Styles ​

Use SCSS when nesting, loops, conditionals are needed:

scss
.list-item {
  &:nth-child(even) {
    background-color: #fafafa;
  }
  
  &.active {
    .title {
      color: $primary-color;
    }
  }
}

3. BEM Naming ​

Use BEM convention for complex components:

scss
/* Block */
.card {}

/* Element */
.card__header {}
.card__body {}
.card__footer {}

/* Modifier */
.card--primary {}
.card--hidden {}

4. Avoid Deep Selectors ​

Limit scoped style depth for better performance:

scss
/* Selector too deep */
.parent .child .grand-child .target {}

/* Better, flatter */
.target {}

5. Mobile-first Responsive Design ​

Use min-width media queries for mobile-first design:

scss
/* Base styles (mobile) */
.container {
  padding: 16px;
}

/* Tablet and above */
@media (min-width: 768px) {
  .container {
    padding: 32px;
  }
}