最近在读《Basic Visual Formatting in CSS》,结合以前看的《css权威指南》和css标准。今天就做个笔记。
以前在遇到一些宽度不明确指明的一些布局的时候,虽然凭感觉能猜出个大概,但是总是有点不是很靠谱。直到最近看到这一本书,觉得总觉得挺好的。
首先要知道,元素除了通过display来指定block、inline、inline-block这一些属性之外,还有一种能在的特性--替换还是非替换。
替换元素:像img、video、canvas等稳定种指定的内容只是占位,真正的内容实在后面替换上去的。像img内容是图片加载完成之后替换上去的。
非替换元素:像div、p、span这一些内容就写在文档中。
而这里要说到的主要是块级非替换元素既display:block的非替换元素,如p、div;还有就是display:list-item,如li。li虽然看display像是和div、p这一些是两类,但是其实li除了多了前面的标志之外,别的行为基本都是一样的。
下面进入正题,文档流中块级非替换元素的水平格式化和包含块(containing block)还有七个属性有关(border-left、margin-left、padding-left、width、padding-right、margin-right、border-right)。文档流中块级元素的containing block一般指的是父级块级元素的内容区域(content area)。也就是在box-sizing:content-box时,width指定的区域。下面有一条公式:
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
上面的公式在所有情况下都要成立。但是很快问题就来了,要是我把7个属性的值都设了值,但是加起来不等于containing block的width怎么办;又或者我把值都设置为auto,那又怎么样去计算呢?其实在这七个值中,只有三个值margin-left、margin-right、width能够设置为auto。我们首先看看把这三个属性设置为auto的情况,由于这三个属性可以设置为auto或者是非auto,那么就是说一共有23,8种情况。下面来分别说下:
1、一个值设置为auto,也就是margin-left、margin-right或者width设置为auto。这三种情况最简单了,直接套上面的公式一算就知道了。
2、两个值设置为auto。
2.1、margin-left和margin-right设置为auto,width指定一个非auto的值。这种情况就是我们平时的水平居中,margin-left和margin-right获得相同的值。
2.2、margin-left和width设置为auto,margin-right指定一个非auto的值。margin-left重设为0,然后就变成了1情况了。
2.3、margin-right和width设置为auto,margin-left指定一个非auto的值。margin-right重设为0,然后又变成了1情况了。
3、三个值设置为auto。margin-left和margin-right都重设为0,然后根据1来计算。
4、假如没有一个设置为auto,在css中叫"over-constrained"(过度约束)。那么在文档流方向为左到右的时候margin-right的值会被忽略,然后还是1情况。这种情况最容易理解错,容易吧"over-constrained"理解成指定了所有的值后使得上面公式左边小于右边。正确的理解应该是"指定了三个值,都没有变通的余地了"。所以只要给margin-left、width和margin-right都指定了auto之外的值(就算是0),也是"over-constrained"了。
上面的内容似乎已经覆盖了所有的情况了,其实不然,还有一种特殊情况就是margin-left,margin-right设置为auto,width有指定值,但是border-left+padding-left+width+padding-right+border-right> width of containing block。按照上面的说法,margin-left和margin-right获得相同的值,但事实是,margin-left和margin-right重设为0,然后过度约束,然后忽略掉一个。

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.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

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.

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.


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

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

SublimeText3 English version
Recommended: Win version, supports code prompts!
