说明,本篇内容为书籍《高流量网站CSS开发技术》的学习总结,文字出自书本
书不错,推荐阅读学习
也可参阅网上的博文
原载:彬Go
链接:http://blog.bingo929.com/css-coding-semantic-naming.html
class和id是用来建立CSS到HTML文件内部的衔接
注意,有些选择器的写法应考虑浏览器兼容问题,如nth-child选择器,多class选择器.classA.classB(IE6和以前的版本不能理解)
对于元素class和id命名,有几件事要放在心上:
1.首先说说语义性
所谓语义性,即名字应当描述内容,而不是描述表现,例子如下
♦表现型(不提倡)
PurpleBold(紫色粗体)
BigHeading(大号标题)
top-left-box(左上方框)
underlined-and-green(下划线绿色)
boxLeft(左侧框)
red(红色)
红色标示涉及元素的表现形式,这在命名里是不允许的,因为表现形式是变化的,当变化发生,不仅要修改CSS的class和id名,还要修改html相应元素的class和id名,相当麻烦,当你所编辑的是大型网站,出现多处这样的修改,是非常耗时且头疼的。所以应该尽可能采用适应变化的命名,即命名与内容紧密相关。
♦语义型(提倡)
sidebar(侧边栏)
warning(警告)
当然,有些时候适当运用表现来命名会更灵活。如,用bordered(带边框)的表现名给网站多处添加同样的样式。
记住,最佳方案不是最干净的那个,也不是最漂亮的那个,与其拘泥成法,不如将思路放开一些。
2.可接受的字符
最佳规则:始终使用字母、数字或连字符,并且始终以字母开头
记住,class和id名称是区分大小写的。
不要使用下划线,不要以数字或连字符打头,不接受“*”,“/”,“\”。虽然新的浏览器对生僻字符集的支持功能更多,但不是所有的浏览器如此,为了保证兼容性,请遵循最佳规则吧。
3.惯例
使用一些约定俗称的惯例名称,可提高代码可预测性,既让自己和他人容易理解,也有助于屏幕阅读器和分析器的工作,提高SEO(搜索引擎优化)
惯例参照Web前端开发规范手册
4.大小写
驼峰式(缩写单词的每个字母采用同样的大小写:pdfLink linkPDF)
连字符
5.命名空间
加前缀,如:wp-users。命名空间需要制定团队内的命名空间约定。
这是防御式CSS采用的技术之一,通过命名空间隔离代码,避免冲突,使其不影响原有和未来的代码。
后续阶段的学习:
Microformat(微格式) http://microformats.org/

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

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

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.

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.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools