Multi-theme application method based on cascading style sheet
By adding theme stylesheet selectors in the application and using the cascading stylesheet language to create independent theme stylesheets for each theme, the problem of multi-theme switching in the existing technology requires modifying the source code and using a large amount of JavaScript, and implementing the problem of multi-theme switching in the existing technology. Efficient and simple multi-theme switching, improving user experience and performance.
Patent Information
- Application Number
- CN202411527248.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When implementing multi-theme switching, existing applications need to modify the source code, which is very laborious and risky, and also requires the use of a large amount of JavaScript code to affect performance and loading speed.
By adding a theme stylesheet selector in the application and using the characteristics of the cascading stylesheet, create an independent theme stylesheet for each theme, and use the cascading stylesheet language to achieve theme switching, avoiding the use of a lot of JavaScript code.
It realizes multi-theme switching of applications, simplifies the development process, avoids the risk of source code modification, improves application performance and loading speed, and improves user experience.
Smart Images

Figure CN119493626A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of front-end development, and in particular to a multi-theme application method based on cascading style sheets. Background Art
[0002] In modern applications, user experience and interface design are becoming increasingly important. Users expect to be able to choose the interface style and appearance theme that suits them according to their preferences. However, there are some problems in implementing multi-theme switching in current applications. First, existing multi-theme solutions often require developers to modify the source code of the application, which is not only labor-intensive but also risky. Second, existing multi-theme solutions often require the use of a large amount of JavaScript code to implement theme switching, which affects the performance and loading speed of the application.
[0003] Therefore, the prior art has defects and needs to be improved. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a multi-theme application method based on cascading style sheets to solve the problems faced by the prior art when implementing multi-theme switching.
[0005] The technical solution of the present invention is as follows: a multi-theme application method based on cascading style sheets is provided, comprising the following steps.
[0006] S1: Add a theme style sheet selector in the application to specify the theme style sheet used by the current application; introduce each theme style sheet in the property file selector and correspond to an alias to provide the configurable logic of the theme style sheet options.
[0007] S2: Using the characteristics of cascading style sheets, create an independent theme style sheet for each theme. Each theme style sheet corresponds to a theme and contains attribute key-value pairs corresponding to all styles under the theme. In the theme style sheet, the naming rule stipulates that English characters starting with "-" are used as attribute names, and the attribute values must be attribute values supported by cascading style sheets.
[0008] S3: Configure different cascading style sheet files on different pages of the application, and use the characteristics of the var() function in the cascading style sheet to call the customized attribute values required by the corresponding page.
[0009] S4: Add, delete and edit themes through the theme manager interface; just click the switch button to automatically load the corresponding theme and automatically update the theme style sheet selector and theme style sheet.
[0010] Furthermore, in step S1, the developer configures different selection logics according to specific needs, and uses the default theme style sheet when no configuration is made.
[0011] The present invention realizes the multi-theme switching of an application program. The present invention realizes the switching of the appearance and style of the application program under different themes by adding a theme style sheet selector in the application program and utilizing the characteristics of the cascading style sheet language. At the same time, the present invention can also be used to manage and maintain multiple themes, so that users can switch themes according to their own preferences.
[0012] Furthermore, the implementation steps of the theme manager are as follows.
[0013] A1: Initialization. The theme manager is initialized when the application is loaded, and reads the default theme configuration and the corresponding theme style sheet selector.
[0014] A2: Display the theme list. In the user interface, the theme manager displays the currently available themes list, including the added themes and the default themes.
[0015] A3: The user operates the subject, including: adding a theme, deleting a theme, and editing a theme. To add a theme, the user adds a new theme through the interface of the theme manager. The interface provides the function of selecting the color corresponding to the module, such as module: button, select: blue, module: navigation bar, select: black. The user configures the configurable options provided by the website one by one, provides the name of the theme, and finally clicks Save to automatically generate the theme style sheet file. To delete a theme, the user selects the added theme and deletes it through the theme manager. After deletion, the style sheet file of the theme will be automatically cleared. To edit a theme, the user selects the added theme and edits it through the theme manager. The user modifies the name of the theme and the module color corresponding to the theme.
[0016] A4: Set the default theme. The user selects an added theme and sets it as the default theme. The default theme will be automatically loaded when the application starts.
[0017] A5: Switch themes. Users switch the current theme through the interface of the theme manager. By selecting a different theme, the theme manager updates the theme style sheet selector and loads the corresponding style sheet.
[0018] A6: Automatically update the selector and style sheet; when the user adds, deletes, edits, or switches themes, the theme manager automatically updates the theme style sheet selector and theme style sheet to reflect the user's operations.
[0019] A7: Apply theme styles. Each time an application loads or switches a theme, it dynamically loads the corresponding style sheet according to the theme style sheet selector and applies it to various elements and components of the application, thereby changing the appearance and style.
[0020] Furthermore, switching the topic includes the following steps.
[0021] B1: The user selects the target theme in the theme manager and clicks the switch button.
[0022] B2: The theme manager obtains the style sheet file path of the target theme.
[0023] B3: Theme Manager updates the theme style sheet selector and sets the target theme's style sheet file path to that of the currently selected theme.
[0024] B4: The theme manager loads the target theme's style sheet file from the new path.
[0025] B5: The theme manager applies new style sheets to various elements and components of the application and changes the look and feel accordingly.
[0026] B6: The theme manager notifies the application that the theme has been successfully switched;
[0027] Furthermore, in step S3, a custom attribute value can be used in multiple cascading style sheet files.
[0028] By adopting the above scheme, the present invention provides a multi-theme application method based on cascading style sheets. By adopting the method of the present invention, users can easily switch different themes according to their preferences to achieve personalized customization of the appearance and style of the application. At the same time, the scheme can also effectively optimize the loading speed and performance of the application and improve the user experience. The simplicity and flexibility of the multi-theme application scheme make it suitable for the development and design of various applications, providing users with a richer and more diverse application experience. The present invention has the following technical effects:
[0029] Simplicity: No need to modify source code, just manage and edit style sheets to switch between multiple themes.
[0030] Flexibility: Users can quickly switch between different themes according to their preferences to enhance the personalized experience of the application.
[0031] Performance optimization: Use Cascading Style Sheets (CSS) to avoid using large amounts of JavaScript code, thereby improving the loading speed and performance of the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0033] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0034] See also Figure 1 The present invention provides a multi-theme application method based on cascading style sheets, including the following steps.
[0035] S1: Add a theme style sheet selector in the application to specify the theme style sheet used by the current application; introduce each theme style sheet in the property file selector and correspond to an alias to provide the configurable logic of the theme style sheet options.
[0036] S2: Using the characteristics of cascading style sheets, create an independent theme style sheet for each theme. Each theme style sheet corresponds to a theme and contains attribute key-value pairs corresponding to all styles under the theme. In the theme style sheet, the naming rule stipulates that English characters starting with "-" are used as attribute names, and the attribute values must be attribute values supported by cascading style sheets.
[0037] S3: Configure different cascading style sheet files on different pages of the application, and use the characteristics of the var() function in the cascading style sheet to call the customized attribute values required by the corresponding page.
[0038] S4: Add, delete and edit themes through the theme manager interface; just click the switch button to automatically load the corresponding theme and automatically update the theme style sheet selector and theme style sheet.
[0039] In this embodiment, in step S1, the developer configures different selection logics according to specific needs, and uses the default theme style sheet when no configuration is made.
[0040] In this embodiment, the implementation steps of the theme manager are as follows.
[0041] A1: Initialization. The theme manager is initialized when the application is loaded, and reads the default theme configuration and the corresponding theme style sheet selector.
[0042] A2: Display the theme list. In the user interface, the theme manager displays the currently available themes list, including the added themes and the default themes.
[0043] A3: The user operates the subject, including: adding a theme, deleting a theme, and editing a theme. To add a theme, the user adds a new theme through the interface of the theme manager. The interface provides the function of selecting the color corresponding to the module, such as module: button, select: blue, module: navigation bar, select: black. The user configures the configurable options provided by the website one by one, provides the name of the theme, and finally clicks Save to automatically generate the theme style sheet file. To delete a theme, the user selects the added theme and deletes it through the theme manager. After deletion, the style sheet file of the theme will be automatically cleared. To edit a theme, the user selects the added theme and edits it through the theme manager. The user modifies the name of the theme and the module color corresponding to the theme.
[0044] A4: Set the default theme. The user selects an added theme and sets it as the default theme. The default theme will be automatically loaded when the application starts.
[0045] A5: Switch themes. Users switch the current theme through the interface of the theme manager. By selecting a different theme, the theme manager updates the theme style sheet selector and loads the corresponding style sheet.
[0046] A6: Automatically update the selector and style sheet; when the user adds, deletes, edits, or switches themes, the theme manager automatically updates the theme style sheet selector and theme style sheet to reflect the user's operations.
[0047] A7: Apply theme styles. Each time an application loads or switches a theme, it dynamically loads the corresponding style sheet according to the theme style sheet selector and applies it to various elements and components of the application, thereby changing the appearance and style.
[0048] In this embodiment, switching the topic includes the following steps.
[0049] B1: The user selects the target theme in the theme manager and clicks the switch button.
[0050] B2: The theme manager obtains the style sheet file path of the target theme.
[0051] B3: Theme Manager updates the theme style sheet selector and sets the target theme's style sheet file path to that of the currently selected theme.
[0052] B4: The theme manager loads the target theme's style sheet file from the new path.
[0053] B5: The theme manager applies new style sheets to various elements and components of the application and changes the look and feel accordingly.
[0054] B6: The theme manager notifies the application that the theme has been successfully switched;
[0055] In this embodiment, in step S3, a custom attribute value can be used in multiple cascading style sheet files.
[0056] Let's take a simple web application as an example. The web application contains four parts: title, menu, content, and footer. In traditional design, these parts may have fixed colors and styles.
[0057] Using the solution of the present invention, the application first references the theme style sheet selector in the theme style sheet. Then, an independent theme attribute file is created for each theme, and different colors and styles are set. Next, through the theme manager, the user can add, delete and edit multiple themes.
[0058] When the user chooses to switch themes, the application will read the currently selected theme and dynamically load the corresponding theme property file. At this time, the appearance and style of the application will change accordingly based on the theme selected by the user.
[0059] In summary, the present invention provides a multi-theme application method based on cascading style sheets. By using the method of the present invention, users can easily switch different themes according to their preferences to achieve personalized customization of the appearance and style of the application. At the same time, the solution can also effectively optimize the application loading speed and performance, and improve the user experience. The simplicity and flexibility of the multi-theme application solution make it suitable for the development and design of various applications, providing users with a richer and more diverse application experience.
[0060] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A multi-theme application method based on cascading style sheets, characterized in that: The following steps are involved: S1: Add a theme style sheet selector in the application to specify the theme style sheet used by the current application; introduce each theme style sheet in the property file selector and correspond to an alias to provide the configurability of the theme style sheet option logic; S2: Using the characteristics of cascading style sheets, create an independent theme style sheet for each theme. Each theme style sheet corresponds to a theme and contains attribute key-value pairs corresponding to all styles under the theme. In the theme style sheet, the naming rule is to use English characters starting with "-" as the attribute name, and the attribute value must be an attribute value supported by the cascading style sheet. S3: Configure different cascading style sheet files on different pages of the application, and use the characteristics of the var() function in the cascading style sheet to call the customized attribute values required by the corresponding page; S4: Add, delete and edit themes through the theme manager interface; just click the switch button to automatically load the corresponding theme and automatically update the theme style sheet selector and theme style sheet.
2. A multi-theme application method based on cascading style sheets according to claim 1, characterized in that: In step S1, the developer configures different selection logics according to specific needs, and uses the default theme style sheet when no configuration is made.
3. The multi-theme application method based on cascading style sheets according to claim 1, characterized in that: The implementation steps of the theme manager are as follows A1: Initialization: The theme manager is initialized when the application is loaded, and reads the default theme configuration and the corresponding theme style sheet selector; A2: Display the theme list. In the user interface, the theme manager displays the currently available theme list, including the added themes and the default theme. A3: The user operates the subject, including: adding a theme, deleting a theme, and editing a theme. To add a theme, the user adds a new theme through the interface of the theme manager. To delete a theme, the user selects an added theme and deletes it through the theme manager. After deletion, the style sheet file of the theme will be automatically cleared. To edit a theme, the user selects an added theme and edits it through the theme manager. The user modifies the name of the theme and the module color corresponding to the theme. A4: Set the default theme. The user selects an added theme and sets it as the default theme. The default theme will be automatically loaded when the application starts. A5: Switch themes. Users switch the current theme through the theme manager interface. By selecting a different theme, the theme manager updates the theme style sheet selector and loads the corresponding style sheet. A6: Automatically update the selector and style sheet; when the user adds, deletes, edits, or switches themes, the theme manager automatically updates the theme style sheet selector and theme style sheet to reflect the user's operation; A7: Apply theme styles. Each time an application loads or switches a theme, it dynamically loads the corresponding style sheet according to the theme style sheet selector and applies it to various elements and components of the application, thereby changing the appearance and style.
4. The multi-theme application method based on cascading style sheets according to claim 3, characterized in that: Switching themes involves the following steps: B1: The user selects the target theme in the theme manager and clicks the switch button; B2: The theme manager obtains the style sheet file path of the target theme; B3: The theme manager updates the theme style sheet selector and sets the target theme's style sheet file path to the path of the currently selected theme; B4: The theme manager loads the style sheet file of the target theme from the new path; B5: The theme manager applies the new style sheet to various elements and components of the application and changes the look and feel accordingly; B6: The Theme Manager notifies the application that the theme has been successfully switched.
5. The multi-theme application method based on cascading style sheets according to claim 1, characterized in that: In step S3, a custom attribute value can be used in multiple cascading style sheet files.
Citation Information
Patent Citations
Page theme style switching method and device, electronic equipment and computer storage medium
CN111104117A
Theme switching method and device of user interface, terminal and storage medium
CN111240792A
Page display method and device and terminal equipment
CN114647473A
Method and system for online updating color theme at webpage side and storage medium
CN117407614A
Web application theme preview based on live previews
US20150149891A1