General CSS Notes, Advice and Guidance_html/css_WEB-ITnose
When working on large-scale, long-term projects with many people, it is extremely important that all developers adhere to the following rules:
**Keep CSS accessible Maintainability**
**Keep the code clear and easy to understand**
**Keep the code scalable**
In order to achieve this To achieve this goal, we must adopt many methods.
The first part of this document will discuss syntax, format and CSS analysis; the second part will start with methodology, thinking framework and attitude towards writing and planning CSS.
## Directory
* CSS document analysis
* Overview
* Single file and multiple File
* Directory
* Chapter title
* Code sequence
* Rule analysis
* Naming convention
* JavaScript hooks
* I18n
* Comments
* Extended usage of comments
* Quasi-modified selector
* Code Tags
* Inherit tags
* Write CSS
* Add new section
* Object-oriented CSS
* Layout
* Interface size
* Font size adjustment
* Abbreviation
* IDs
* Selector
* Modified selection Selector
* Selector performance
* Selector inheritance
* `!important`
* Magic number and absolute ratio
* Conditional judgment
* Debugging
* Preprocessing
---
## CSS document analysis
No matter what document we write, we should try our best to maintain a unified style, including unified comments, unified grammar and unified naming convention.
### General
Try to keep the line width under 80 bytes. Gradient-related syntax and URLs in comments can be counted as exceptions. After all, there is nothing we can do about this part.
I prefer to use 4 spaces instead of tab indentation, and split declarations into multiple lines.
### Single file vs. multiple files
Some people like to write styles as one big file, which is not bad, and if you follow You will not encounter any problems if you write the following rules. After I moved to Sass, I started splitting my styles into many small files. That's not bad either. Whichever way you go, the rules below will apply. The two writing methods only differ in the directory and block titles.
### Table of contents
At the beginning of the CSS, I would write a table of contents, for example:
/*--------------------------------*
$ CONTENTS
*--------------------------------*/
/**
* CONTENTS............You’re reading it!
* RESET...............Set our reset defaults
* FONT-FACE...........Import brand font files
*/
This directory can tell other developers what content is contained in this file. Each item in this directory has the same block title as its corresponding block.
If you are maintaining a larger single-file CSS, the corresponding blocks will also be in the same file. If you are writing a set of small files, then each item in the directory should have a corresponding @include statement.
### Block title
The table of contents should correspond to the title of the block. Please see the following example:
/*---------------------------------- -----*
$RESET
*----------------------------- -------*/
The block title prefix `$` allows us to use the ([Cmd|Ctrl] F) command to find `$[SECTION-NAME]` , while limiting the search to block titles.
If you are maintaining a large file, then leave 5 empty lines between blocks, like this:
/*--- ----------------------------------*
$RESET
*- ----------------------------------*/
[Our
reset
styles]
/*-- ----------------------------------*
$FONT-FACE
*----------------------------------------*/
These large gaps help distinguish chunks when flipping quickly through large files.
If you are maintaining multiple copies of CSS connected with @include, just add a title to the header of each file without having to leave a blank line like this.
## Order
Try to write the rules in a specific order. This will ensure that you get the most out of the first C in the CSS abbreviation: cascade , cascading.
A well-planned CSS should be arranged as follows:
1. **Reset** The root of all things
2. **Element type** `h1`, `ul`, etc. without class setting
3. **Object and abstract content** The most general and basic design pattern
4. **Sub-elements** All expansions and sub-elements extended from the object
5. **Fix** For abnormal conditions
like this Now, when you write CSS sequentially, each block can automatically inherit the properties of the block before it. In this way, the parts of the code that offset each other can be reduced, some special problems can be reduced, and a more ideally designed CSS structure can be formed.
For more information on this, Jonathan Snook’s [SMACSS](http://smacss.com) is highly recommended.
## CSS rule set analysis
[selector]{
[property]:[value];
[]
}
[Selector]{
[Attribute]:[Value] ;
[]
}
When writing CSS styles, I like to follow these rules:
* Class names are connected with hyphens (-), except for the BEM nomenclature mentioned below;
* Indent 4 spaces;
* Declaration split into multiple lines;
* declarations are arranged in relevance order, not alphabetical order;
* prefixed declarations are indented appropriately, aligning their values;
* indented Improve the style to reflect the DOM;
* Keep the semicolon at the end of the last declaration.
For example:
.widget{
padding:10px;
border:1px solid # BADA 55; radius:4px;
}
.widget-heading{
font-size:1.5rem;
line-height:1;
font - weight: bold; padding: 0.25em;
}
We can find that `.widget-heading` is a child element of `.widget`, because the former is more indented than the latter Level one. This allows developers to quickly access information when reading these styles.
We can also find that the declarations of `.widget-heading` are arranged according to their relevance: `.widget-heading` is a text element, so we add font-related styles first Statement, then comes the rest.
The following is an example without splitting into multiple lines:
.t10 { width:10% }
.t20 { width:20% }
.t25 { width:25% } /* 1/4 */
.t30 { width:30% }
. t33 { width:33.333% } /* 1/3 */
.t40 { width:40% }
.t50 { width:50% } /* 1/2 */
.t60 { width:60% }
.t66 { width:66.666% } /* 2/3 */
.t70 { width:70% }
.t75 { width:75% } /* 3/4*/
.t80
In this example (from [inuit.css's table grid system](https://github.com/csswizardry/inuit.css/blob/master/inuit.css/partials/base/_tables .scss#L88)), placing CSS on one line can make the code more compact.
## Naming convention
Generally, I connect class names with hyphens (-) (for example `.foo- bar` instead of `.foo_bar` or `.fooBar`), but in certain situations I will use the BEM (Block, Element, Modifier) nomenclature.
BEM The nomenclature can make the selector more standardized, clearer and more semantic.
The nomenclature follows the following format:
.block{}
.block__element{}
.block--modifier{}
Where:
* `.block` represents a basic abstract element;
* `.block__element` represents a sub-element of `.block` as a whole;
* `.block--modifier` represents a different state of `.block`.
For example:
.person{}
.person--woman{}
.person__hand{}
.person__hand--left{}
.person__hand--right{}
The best thing we describe in this example The basic element is a person, and then that person might be a woman. We also know that people have hands, which are part of the human body, and the hands also have different states, like the left hand and the right hand.
This way we can specify the namespace of the selector based on the parent element and convey the function of the selector, whether it is a child element (`__`) or a different state (`- -`)?
Thus, `.page-wrapper` is an independent selector. This is a standard name, because it is not a child element or other state of other elements; however `.widget-heading` is related to other objects, it should be a child element of `.widget`, so we should use it Renamed to `.widget__heading`.
Although the BEM nomenclature is not pretty and quite verbose, it allows us to quickly learn the functions of elements and the relationships between elements through names. At the same time, the repeated parts in the BEM syntax greatly benefit the gzip compression algorithm.
Whether you use BEM nomenclature or not, you should ensure that classes are named appropriately, with no more words and less words; abstract element naming to improve reusability (e.g. `.ui-list`, `.media`). The naming of elements extending from this should be as precise as possible (for example `.user-avatar-link`). Don't worry about the number or length of class names, as well-written code can be compressed effectively by gzip.
### class in HTML
To ensure readability, use two spaces to separate class names in HTML tags. For example:

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

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.

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools