search
HomeWeb Front-endHTML Tutorialdiv css layout_html/css_WEB-ITnose

The spring breeze of "reconstruction" is blowing all over the country, and the Internet is in a state of turmoil for a while. "div CSS" has become a "fashion". Countless websites have started their own "reconstruction" invariably. However, opening up this variety of The source code of the website often makes people laugh??


We see div layouts with 6 or 7 layers of nesting, tables without tables, pages composed of pure div a, and hundreds of Thousands of presentation layer classes... Nowadays, there are more and more books about standards. Except for a few books that advertise "advanced techniques", there are very few people who will not emphasize such a sentence in the first few chapters of their books..." "Separation of structure and performance". However, how many readers of these books have read the first few chapters seriously? Or more often they just skip the boring structure explanations and dive into the seemingly advanced layout techniques and Hack?


In fact, the term div CSS has misled too many people from the beginning, and the quick success mentality is the culprit of this phenomenon. A web page that is accustomed to table layout. The first step in making contact standards should not be to blindly seek CSS techniques to implement various layouts, but to work hard to change your way of thinking.


I will talk about it based on my personal experience. Comply with the standard way of thinking, many of which are detours I have taken. I hope it will be helpful to XDJMs who have just come into contact with standards:


1. "Saving code" is a marketing tool, not a purpose

"Using div layout can save more code than table layout." I have seen this sentence in many books and websites. This sentence itself is correct, and it can "save code". It is one of the benefits brought by web page standardization. However, remember that it is only "one of the benefits", not the "only benefit", and it is not the purpose of "saving code". It is more often used by us to persuade those who are stubborn. The boss's marketing method. The only purpose of web page standardization is "separation of structure and performance", and it is not to save code for the sake of saving code. I once used a unified class because the presentation form of the website sidebar and even the main content is the same (still do). Some books teach this), which indeed saves code than naming IDs separately. However, the cost of doing so is that the code loses its good structure. The consequences of losing its good structure are: 1. The source code is no longer readable; 2. , the website increases unknown maintenance costs. Just imagine, when a certain piece of content changes in presentation due to needs, such as the color of links, etc., we have to modify the page source file and add additional classes. The workload is compared to Just adjusting the id grouping will make it much bigger. And if things go on like this, the structure will get worse and worse, forming a vicious cycle that is difficult to reverse. There is another situation that occurs in the naming of ids. Mistakes I have made. At that time, in order to "save code", the main menu was named "mm", the secondary menu was named "m2", and the third-level menu was named "m3". As a result, the readability of the web page was seriously reduced, making it difficult for other colleagues to Taking over, trying to save trouble but tiring myself. In the same way, it is not advisable to oversimplify the naming of files and folders. For example, "Website Reconstruction" recommends storing all images in the "i" directory. Personally, I think it is not advisable unless you can write for such a highly abbreviated directory structure. Explain in detail and ensure that everyone involved, including other production staff, developers, and even knowledgeable bosses... can understand and implement it, otherwise it will only add unnecessary trouble to yourself.


2. ID is a sniper rifle, and class is a double-edged sword

If you want to have a good web page structure, both id and class must be mastered proficiently. The so-called "grasp with both hands, grasp with both hands" All must be hard." ID is like a sniper rifle, which can help us accurately locate the elements we want to load styles; and class is the knight's sword, which is lighter and more flexible at hand. The combination of the two can achieve a page with good structure and rich performance. However, there is a wrong view now that id can be completely replaced by class. In fact, this is true for many web page source codes. When you open the entire class, you cannot find an id. There are many reasons for this phenomenon, but the deep-rooted concept of "class=CSS" passed down from the table era is the root cause. It is true that class is more versatile and flexible than id, but it must also be realized that class is far less effective than id in building a good web page structure. The mandatory uniqueness of id makes it easy for us to retrieve any module we need through id, while class does not have this advantage. Although we can define a unique class name for the module, the premise is that only the producer himself can change the web page style. Otherwise, let's find a slightly lazy guy. When he sees that the styles are the same, he will directly apply the previous class. The result is that we find that there are more than a dozen modules in the web page called "gonggao" or "xinwen", so that it is difficult to distinguish them. Without adding a lot of html comments, this result is obviously not what we want. Furthermore, as mentioned earlier, the code saved through universal classes has to be squandered in each individually defined class.

ID is a sniper rifle, and class is a double-edged sword. Together, we both benefit, and apart, we both lose.
3. Not all content requires div as a "container"


Should the main menu use

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

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.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor