Html开发常用习惯之(二)_html/css_WEB-ITnose
Html开发常用习惯:
引入CSS, JS
根据HTML5规范, 通常在引入CSS和JS时不需要指明 type,因为 text/css 和 text/javascript 分别是他们的默认值。
HTML5 规范链接
?使用link
?使用style
?使用script
<!-- External CSS --><link rel="stylesheet" href="code_guide.css"><!-- In-document CSS --><style> ... </style><!-- External JS --><script src="code_guide.js"></script><!-- In-document JS --><script> ... </script>
属性顺序
属性应该按照特定的顺序出现以保证易读性;
?class
?id
?name
?data-*
?src, for, type, href, value , max-length, max, min, pattern
?placeholder, title, alt
?aria-*, role
?required, readonly, disabled
class是为高可复用组件设计的,所以应处在第一位;
id更加具体且应该尽量少使用,所以将它放在第二位。
<a class="..." id="..." data-modal="toggle" href="#">Example link</a><input class="form-control" type="text"><img src="/static/imghw/default1.png" data-src="..." class="lazy" alt="...">
boolean属性
boolean属性指不需要声明取值的属性,XHTML需要每个属性声明取值,但是HTML5并不需要;
更多内容可以参考 WhatWG section on boolean attributes:
boolean属性的存在表示取值为true,不存在则表示取值为false。
<input type="text" disabled><input type="checkbox" value="1" checked><select> <option value="1" selected>1</option></select>
JS生成标签
在JS文件中生成标签让内容变得更难查找,更难编辑,性能更差。应该尽量避免这种情况的出现。
减少标签数量
在编写HTML代码时,需要尽量避免多余的父节点;
很多时候,需要通过迭代和重构来使HTML变得更少。
<!-- Not well --><span class="avatar"> <img src="/static/imghw/default1.png" data-src="..." class="lazy" alt="Html开发常用习惯之(二)_html/css_WEB-ITnose" ></span><!-- Better --><img class="avatar lazy" src="/static/imghw/default1.png" data-src="..." alt="Html开发常用习惯之(二)_html/css_WEB-ITnose" >
上一篇:前端开发常用命名规范`
下一篇:Html开发常用习惯之(一)
该文本人以上希望对初学朋友有些帮助同时自己笔记留用,谢谢!
更多关注付义方技术博客:
或者直接用手机扫描二维码查看更多博文:
版权声明:本文为博主原创文章,未经博主允许不得转载, 更多关注付义方技术博客:http://blog.csdn.net/fuyifang

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











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 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.

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.

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, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

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

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.
