Skip to content

Style Development Documentation

Overview

This document details the style processing mechanism and customization methods of the VJSP Vue3 framework. The framework adopts a modern CSS architecture, combining Tailwind CSS, Less preprocessor, and CSS variable system to provide a flexible and maintainable style solution.

Style Architecture

1. Style File Structure

shell
src/styles/
├── components/           # Component styles
   ├── nprogress.less   # Progress bar styles
   ├── tables.less      # Table-related styles
   └── tools.less       # Utility class styles
├── element/              # Element Plus theme customization
   ├── dark.less        # Dark theme
   └── index.less       # Element Plus theme entry
├── index.less           # Global style entry
└── variables.module.less # CSS variable system

2. Style Processing Flow

  1. CSS Variable Definition: Define global CSS variables in variables.module.less
  2. Tailwind Integration: Import Tailwind base styles through index.less
  3. Component Styles: Organize component styles by functional modules
  4. Theme Customization: Element Plus theme customization through CSS variable overrides

Core Style Mechanisms

1. CSS Variable System

The framework uses CSS custom properties (CSS Variables) as the style foundation, supporting light/dark theme switching. All CSS variables are defined in the [variables.module.less] file.

Complete CSS Variable Table

Variable NameDefault ValueFunction DescriptionTheme Support
--left-menu-max-width200pxLeft menu maximum widthGeneral
--navbar-height64pxDesktop navigation bar heightGeneral
--navbar-height-mobile56pxMobile navigation bar heightGeneral
--tags-view-height36pxDesktop tag page heightGeneral
--tags-view-height-mobile32pxMobile tag page heightGeneral
--global-btn-radius6pxGlobal button border radiusGeneral
--spacing-xs4pxExtra small spacing for tight arrangementsGeneral
--spacing-sm8pxSmall spacing for internal element spacingGeneral
--spacing-md16pxMedium spacing for regular element spacingGeneral
--spacing-lg24pxLarge spacing for block spacingGeneral
--spacing-xl32pxExtra large spacing for large block spacingGeneral
--font-size-xs12pxExtra small font for auxiliary textGeneral
--font-size-sm14pxSmall font for body contentGeneral
--font-size-md16pxMedium font for titlesGeneral
--font-size-lg18pxLarge font for large titlesGeneral
--font-size-xl20pxExtra large font for page titlesGeneral
--shadow-sm0 1px 2px rgba(0, 0, 0, 0.05)Small shadow for card hoverGeneral
--shadow-md0 4px 6px -1px rgba(0, 0, 0, 0.1)Medium shadow for modal boxesGeneral
--shadow-lg0 10px 15px -3px rgba(0, 0, 0, 0.1)Large shadow for dropdown menusGeneral
--shadow-xl0 20px 25px -5px rgba(0, 0, 0, 0.1)Extra large shadow for large componentsGeneral
--bg-primary#ffffffPrimary background colorLight theme
--bg-secondary#f5f7faSecondary background colorLight theme
--bg-tertiary#f0f2f5Tertiary background colorLight theme
--bg-card#ffffffCard background colorLight theme
--bg-hover#f5f7faHover background colorLight theme
--bg-active#ecf5ffActive state background colorLight theme
--text-primary#303133Primary text colorLight theme
--text-secondary#606266Secondary text colorLight theme
--text-tertiary#909399Tertiary text colorLight theme
--text-disabled#c0c4ccDisabled text colorLight theme
--border-color#dcdfe6Border colorLight theme
--border-light#e4e7edLight borderLight theme
--border-dark#c0c4ccDark borderLight theme
--color-primary#409effPrimary colorGeneral
--color-success#67c23aSuccess colorGeneral
--color-warning#e6a23cWarning colorGeneral
--color-danger#f56c6cDanger colorGeneral
--color-info#909399Info colorGeneral
--shadow-colorrgba(0, 0, 0, 0.1)Shadow colorLight theme
--shadow-color-darkrgba(0, 0, 0, 0.2)Dark shadowLight theme
--mask-colorrgba(0, 0, 0, 0.8)Mask colorGeneral
--mask-color-lightrgba(0, 0, 0, 0.3)Light maskGeneral
--striped-bgrgba(255, 255, 255, 0.02)Striped backgroundLight theme
--loading-gradientlinear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent)Loading animation gradientLight theme
--bg-primary#141414Primary background colorDark theme
--bg-secondary#1f1f1fSecondary background colorDark theme
--bg-tertiary#262626Tertiary background colorDark theme
--bg-card#1f1f1fCard background colorDark theme
--bg-hover#2a2a2aHover background colorDark theme
--bg-active#2a2a2aActive state background colorDark theme
--text-primary#e5e5e5Primary text colorDark theme
--text-secondary#a3a3a3Secondary text colorDark theme
--text-tertiary#737373Tertiary text colorDark theme
--text-disabled#525252Disabled text colorDark theme
--border-color#404040Border colorDark theme
--border-light#525252Light borderDark theme
--border-dark#303030Dark borderDark theme
--shadow-colorrgba(0, 0, 0, 0.3)Shadow colorDark theme
--shadow-color-darkrgba(0, 0, 0, 0.5)Dark shadowDark theme
--transition-theme0.3s easeTheme switching transition timeGeneral
--transition-fast0.15s easeFast transition animationGeneral
--transition-slow0.5s easeSlow transition animationGeneral
--bg-gradient-start#f5f7faGradient background start colorLight theme
--bg-gradient-end#c3cfe2Gradient background end colorLight theme
--card-shadow0 4px 6px -1px rgba(0, 0, 0, 0.1)Card shadowLight theme
--primary-color#409effPrimary colorGeneral
--bg-gradient-start#1f1f1fGradient background start colorDark theme
--bg-gradient-end#2a2a2aGradient background end colorDark theme
--card-shadow0 4px 6px -1px rgba(0, 0, 0, 0.3)Card shadowDark theme

Variable Usage Examples

less
// Using CSS variables
.component {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--global-btn-radius);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

// Responsive spacing
.responsive-spacing {
  padding: var(--spacing-sm);
  
  @media (min-width: 768px) {
    padding: var(--spacing-md);
  }
  
  @media (min-width: 1024px) {
    padding: var(--spacing-lg);
  }
}

2. Tailwind CSS Integration

The framework integrates Tailwind CSS, providing atomic CSS class names:

less
// Tailwind configuration extensions
tailwind.config.js defines:
- Color extensions: primary, success, warning, etc.
- Animation configuration: fade, slide, and other transition effects
- Shadow system: sm, md, lg, etc. shadow levels
- Responsive breakpoints: sm, md, lg, xl, 2xl

3. Responsive Design

Adopts a mobile-first responsive strategy:

less
// Breakpoint definitions
@screen-sm: 640px;
@screen-md: 768px;
@screen-lg: 1024px;
@screen-xl: 1280px;
@screen-2xl: 1536px;

// Responsive utility classes
.responsive-grid {
  display: grid;
  grid-template-columns: 1fr;
  
  @media (min-width: @screen-md) {
    grid-template-columns: repeat(2, 1fr);
  }
  
  @media (min-width: @screen-lg) {
    grid-template-columns: repeat(3, 1fr);
  }
}

Business Module Style Development Example (Product Module)

1. Page Layout Structure

The product management page adopts a modular layout design:

vue
<template>
  <div class="product-container query-container">
    <!-- Filter condition area -->
    <el-card class="filter-container">
      <!-- Filter form content -->
    </el-card>

    <!-- Data display area -->
    <el-card class="table-container">
      <!-- Desktop table view -->
      <div v-if="!isMobile" class="desktop-view">
        <!-- Table component -->
      </div>

      <!-- Mobile card view -->
      <div v-else class="mobile-view">
        <!-- Card layout -->
      </div>
    </el-card>
  </div>
</template>

2. Responsive Adaptation Implementation

The product page implements complete responsive adaptation:

Desktop Layout:

  • Uses Element Plus table component to display data
  • Fixed column width and header alignment optimization
  • Pagination component displayed at bottom

Mobile Adaptation:

  • Card layout replaces tables
  • Filter conditions can be collapsed
  • Touch-friendly operation buttons
  • Pull-up load more mechanism

3. Style Class Name Conventions

The product module adopts BEM naming convention:

less
// Container class names
.product-container {
  // Page container styles
}

.query-container {
  // Query area styles
}

.filter-container {
  // Filter condition container
}

.table-container {
  // Table container styles
}

// Mobile-specific styles
.mobile-view {
  .mobile-cards-container {
    // Card container
  }
  
  .mobile-card {
    // Single card
    .card-header { /* Card header */ }
    .card-content { /* Card content */ }
    .card-actions { /* Operation area */ }
  }
}

4. Dynamic Style Processing

The product page dynamically adjusts styles based on device type:

vue
<template>
  <el-form
    :inline="!isMobile"
    :label-position="isMobile ? 'top' : 'left'"
    :label-width="isMobile ? '80px' : '100px'"
  >
    <el-input
      :style="{ width: isMobile ? '100%' : '160px' }"
      :size="isMobile ? 'small' : 'default'"
    />
  </el-form>
</template>

Style Customization Guide

1. Theme Color Customization

Modify CSS variables to customize theme colors:

less
// Modify in variables.module.less
:root {
  --color-primary: #your-primary-color;
  --color-success: #your-success-color;
  // ...other color variables
}

2. Component Style Overrides

Override Element Plus component styles through CSS selectors:

less
// Override table styles
.el-table {
  .el-table__header {
    th {
      background-color: var(--bg-color-secondary);
    }
  }
}

3. Responsive Breakpoint Customization

Modify responsive breakpoints in Tailwind configuration:

javascript
// tailwind.config.js
module.exports = {
  theme: {
    screens: {
      'sm': '640px',
      'md': '768px',
      'lg': '1024px',
      'xl': '1280px',
      '2xl': '1536px',
    }
  }
}

Best Practices

1. Style Organization Principles

  • Modularity: Organize style files by functional modules
  • Reusability: Extract common styles as utility classes
  • Maintainability: Use CSS variables and preprocessors
  • Performance Optimization: Avoid deep nested selectors

2. Responsive Design Recommendations

  • Mobile-first design strategy
  • Use relative units (rem, em)
  • Set reasonable breakpoint thresholds
  • Test multi-device compatibility

3. Theme Switching Implementation

The framework supports light/dark theme switching by modifying the data-theme attribute:

javascript
// Switch theme
document.documentElement.setAttribute('data-theme', 'dark');

Common Questions

1. Style Overrides Not Working

Ensure style file loading order is correct, custom styles should load after framework styles.

2. Mobile Adaptation Issues

Use the responsive utility classes and breakpoint system provided by the framework, avoid hardcoding dimensions.

3. Theme Switching Abnormalities

Check if CSS variable definitions are complete, ensure both light and dark theme variables have corresponding values.

Summary

The VJSP Vue3 framework's style system provides a complete solution, combining modern CSS technology and best practices. Through CSS variables, Tailwind CSS, and modular organization, developers can efficiently perform style customization and business development.