Some Front-end Writing Standards and Suggestions
Classification Programming Techniques
1. Writing Standards
1.1 Project Structure
---/html/
|---- /index
|---- /index/index.html Home page
|---- /user/ Pages related to users
|---- /user/login.html Login page
---/css/
|---- /base.css Reset browser styles
|---- /page Page-specific CSS
|---- /page/pagename.css Individually written CSS
|---- /common.css Common CSS style library
---/js/
|---- /lib Common components
|---- /lib/jquery.2.2.3.min.js Call jq library file
|---- /page Page-specific JavaScript
|---- /page/pagename.js Individually written JavaScript
|---- /common.js Common methods
---/img/
|---- /page Page-specific images
|---- /page/wap Mobile images folder
|---- /page/wap/wap_icon.png Mobile icon
|---- /logo.png Common images
1.2 Project Naming Conventions
Project: Named with the corresponding English word
Files and folders:
All lowercase English letters, hyphens allowed, no other characters, e.g., login, my-order
Files in
/lib
should include version numbers, minified files should include the keywordmin
, other plugins may not, e.g.,/lib/jquery.1.9.1.js
1.3 Format & Encoding
Text files:
.xxx
UTF-8_(no BOM)_ encodingImage files:
.png
_(PNG-24)_.jpg
_(compression rate 8-12)_Animated images:
.gif
Compressed files:
.tar.gz
.zip
.rar
2. CSS Standards
2.1 CSS Naming Conventions
All names in lowercase English words
Do not use simple directional words for direct naming, e.g., "left", "bottom"
Do not abbreviate words, unless they are immediately recognizable
Long names or phrases can use underscores as connectors
Avoid excessive selector nesting, less than 3 levels
Do not use IDs indiscriminately; they should be used as needed, not overused
Use CSS shorthand properties, e.g., padding:0 10px 5px 5px, etc., to streamline code and improve user reading experience.
Naming references are as follows:
CSS Style Naming | Description |
---|---|
Web page common naming | |
--- | |
wrapper | Page outer control for overall layout width |
container or content | Container, used for the outermost layer |
layout | Layout |
head, header | Header section |
foot, footer | Footer section |
nav | Main navigation |
sub_nav | Secondary navigation |
menu | Menu |
sub_menu | Submenu |
side_bar | Sidebar |
sidebar_l, sidebar_r | Left or right sidebar |
main | Main body of the page |
tag | Tag |
msg message | Prompt message |
tips | Tips |
vote | Voting |
friendlink | Friendship links |
title | Title |
summary | Summary |
login_bar | Login bar |
search_input | Search input box |
hot | Hot spot |
search | Search |
search_output | Search output, similar to search results |
search_bar | Search bar |
search_results | Search results |
copyright | Copyright information |
branding | Branding |
logo | Website logo |
site_info | Website information |
site_info_legal | Legal statement |
site_info_credits | Credit |
join_us | Join us |
partner | Partners |
service | Service |
register | Register |
arr arrow | Arrow |
guild | Guide |
site_map | Site map |
list | List |
home_page | Home page |
sub_page | Subpage, secondary page |
tool, toolbar | Toolbar |
drop | Drop-down |
drop_menu | Drop-down menu |
status | Status |
scroll | Scroll |
tab | Tab page |
left right center | Left, center, right alignment |
news | News |
download | Download |
banner | Banner (top banner) |
2.2 CSS Writing Standards
Adhere to the "no IDs, no levels, no tags" principle to effectively improve reusability, reduce file size, and enhance rendering efficiency.
2.3 CSS Comment Format
Used to distinguish page comments, e.g. /* Product Center */
Module comments, e.g. /*Home page navigation The pages for mobile devices should be designed with a base width of 750px, and the display effect should be optimized for a width of 375px.
5. Image Standards
5.1 Image Specifications
Image size: When cutting images, save them in web format to reduce the file size.
Image dimensions: Use whole numbers for dimensions, such as 20x20, 50x50.
Image merging: Small images should be merged and the corresponding PSD files should be saved for future modifications.
>
Original link: https://lingdianit-com.github.io/Front-End-Standards/