Reasonable structure css for website design
Architecture CSS
Under the premise that current browsers generally support it, CSS has been given an unprecedented mission. However, the more you rely on CSS, the larger and more complex the style sheet file will become. Along with this comes the challenge of file maintenance and organization.
(Once upon a time) only one css file was enough - all the rules were gathered together, and it was easy to add, delete or modify them - but these days are long gone. When building a new website (now), you have to spend some time planning how to organize and structure the CSS.
Organization of files
The first step in building a CSS system is the formulation of an outline. (I think) the importance of CSS organization planning is comparable to the website directory structure. (htmlor note: use exaggerated words to enhance your memory) There is no one-size-fits-all solution, so we will discuss some basic organizational solutions and their respective pros and cons.
Main css file
Usually you can use a main css file to place the rules shared by all pages. This file will contain default fonts, links, headers, and other styles. With the main css file in place, we started exploring high-level organizational strategies.
Method 1: Based on prototype
The most basic strategy is to separate css files based on archetype page. If a website's homepage, subpages, and portfolio pages are designed differently, a prototype-based strategy can be used. (Under this strategy) Each page will have its own css file.
When the number of prototypes is not large, this method is simple, clear and effective. However, problems arise when page elements are not located in each prototype page step by step. If the subpages and the combination page share some elements, but the homepage does not, what should we do?
Put the shared elements into the main css file. This isn't the purest solution, but it works for some specific situations. But if the site is huge, the main css file will quickly bloat - which defeats the purpose of separating files: to avoid importing unnecessarily large files.
Put a copy of the style code in the css files of the combination page and sub-page. (Doing this) means maintaining redundant code, and obviously we don't want that.
Create a new file to be shared by these two pages. sounds great. But if there are only 10 lines of code, do we create this file just to share these 10 lines of code? (htmlor note: Killing a chicken with a knife?) This method is very pure, but if the website is huge and there are many pages sharing a small number of elements ( htmlor note: For example, if 30 pairs of pages each share 10 lines of code), it will appear very cumbersome.
Create a separate css file containing styles for all shared elements. This method may be simpler, but it depends on the size of the site and the number of shared elements. There is a very annoying situation: a large css file is imported, but only a small part of the style is used on the page - again, this defeats the original purpose of separating files.
This is what I call the overlap dilemma. There's a lot of overlap in fragmented CSS rules, and there's no completely clear-cut way to organize them.
Method 2: Based on page elements/blocks
If the website uses server-side include, this method will be very good. For example, if you use header include, it will have its own corresponding css file. The include in the footer or other parts can be done in the same way, just import your own css file. This method is simple and clean, but it may produce a lot of small css files.
For example, if the footer style only requires 20 lines of CSS code, it is not worthwhile to create a separate file. And this method will cause each page to contain a bunch of css files - because there are as many css files as there are include.
Method 3: Based on tags
This solution is intuitive and practical, similar to the previous one. If the website has a total of 30 pages, 10 of which contain forms, then you can create a css file to specifically handle the style of the form, and import it only on these 10 pages. If the other 10 pages contain tables, create a file specifically to handle table styles...and so on.
Additional Organization Tips
In addition to subjective methods of organizing documents, we also need to consider multiple media types such as print, handheld devices, and screens. Although this is clearly defined, it is still a factor that should be considered when establishing the file structure. Once multiple media types must be supported, some rules in the main CSS file may need to be reconsidered.
In addition, brand co-operation may also be an important factor. (htmlor note: such as joga jointly launched by Google and Nike) If it involves brand co-branding, you have to consider which elements should be adjusted to suit the other brand. For example, use different css files respectively.
Another often-overlooked tip: use nested @import statements. A css file can be created by just containing a series of @import statements, or adding a few css rules. This method can completely create the main css file of the website (use @import to import the style files of each part). If each page of your website imports 4 or 5 different css files, you should undoubtedly consider using this technique.
Organization of rules and selectors
After talking about file organization, let’s discuss how to organize the things in the file. Naturally, we want to browse unimpeded in the file and quickly find the selector or rule to be edited.
Redundancy vs. Dependency
As Dave Shea said in his article "Redundancy vs. Dependency", you must constantly understand the cascade. You have to decide whether to group selectors (meaning dependency) or separate them (meaning redundancy). Grouping can keep code concise and concise, but it will establish dependency relationships, resulting in increased maintenance overhead. Without grouping, you increase file size and make it difficult to keep similar selectors consistent. Only by making these trade-offs and trade-offs can we make the right decision every time.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
