《从0到1:CSS进阶之旅》作者根据自己多年的前后端开发经验,详尽介绍了CSS的进阶知识和高级开发技巧。本书的正文部分共12章,分别讲解了CSS的基础知识、CSS规范、盒子模型、display属性、文本效果、表单效果、浮动布局、定位布局、CSS图形、性能优化、CSS技巧,以及CSS的一些重要概念。除了正文部分,本书还包括两个附录,附录1介绍了HTML的进阶知识,附录2是作者结合实际工作和前端面试经验,精心挑选的前端面试题。本书还配备了所有案例的源代码和PPT教学课件,以方便学校老师教学。本书适合作为前端开发人员的参考书,也可以作为大中专院校相关专业的教材及教学参考书。
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# 【One-Line Pitch】
A practical, example-driven CSS intermediate guide that takes you from basic selectors and units through box model, display tricks, float/positioning layouts, and CSS-drawn graphics — ideal for front-end developers who know some CSS but want to master the "why" behind layout behavior and pick up battle-tested techniques.
# 【Book Arc】
- **Opening (~0%–9%)**: Covers CSS fundamentals — units (px, em, rem, %), cascade and specificity rules, selector types (descendant, child, sibling), pseudo-elements, and the three stylesheet approaches. Solves the "why does my style not apply" confusion.
- **Early (~17%–26%)**: Deep dive into the box model — content, padding, border, margin, margin collapsing (sibling, parent-child, empty elements), negative margin techniques, and the first look at clearing floats with overflow:hidden. Establishes the mental model for all layout work.
- **Early (~26%–30%)**: Explores the display property — inline-block behavior, simulating buttons with anchors, display:none vs visibility:hidden, and the powerful display:table-cell for vertical centering, equal-height columns, and auto-even distribution.
- **Middle (~35%–43%)**: Text effects — text-indent tricks (including the -9999px SEO technique), text-align vs margin:auto for centering, and line-height inheritance quirks. Also touches form styling (textarea resize control).
- **Middle (~48%–52%)**: Float and positioning layouts — normal flow vs out-of-flow, float behavior with siblings, the "height collapse" side effect, and the recommended ::after clearfix solution. Then positioning: relative parent + absolute child patterns for sub-navigation and precise placement.
- **Late (~52%+)**: CSS graphics — triangles, rounded corners, circles, and ellipses built purely with CSS to avoid image HTTP requests, plus performance rationale for "fewer images" design.
# 【Key Takeaways】
- **Units have precise reference points** (Early): px is absolute, % refers to the parent's same property, em refers to the current element's font-size, rem refers to the root html font-size. Mixing them wrongly causes mysterious sizing bugs — check the reference before writing.
- **Cascade follows "last one wins" only under equal weight** (Early): For the same element and property, the later rule wins only when selector weights match. Weight calculation applies to specified styles, not inherited ones — inherited styles always lose to specified styles.
- **Selector weight cannot judge inherited styles** (Early): A high-weight selector targeting an ancestor does not override a lower-weight selector targeting the element itself. Understand the difference between "specified" and "inherited" to debug style conflicts.
- **Margin collapsing is a three-case trap** (Early): Adjacent siblings, parent-child pairs without padding/border separation, and empty elements all merge vertical margins. Negative margins can pull elements or subsequent siblings — a core technique for centering and tab designs.
- **display:table-cell is a layout "artifact"** (Early): It gives elements td-like behavior — perfect for vertical centering of variable-size images, equal-height columns, and auto-even division of list items without specifying widths. IE8+ support makes it safe for modern use.
- **Clearing floats properly requires ::after** (Middle): overflow:hidden works but hides overflowing content (a "small bomb"); clear:both needs extra HTML tags. The .clearfix::after pattern with clear:both, content:"", and display:block is the production-standard solution.
- **Float changes element display behavior** (Middle): Inline elements become block-level when floated, allowing width/height/margin. Floated elements leave normal flow, causing parent height collapse — always plan for clearing.
- **CSS graphics beat images for performance** (Late): Triangles, circles, and ellipses via CSS avoid image file size and extra HTTP requests. Use border tricks and border-radius instead of image assets for simple shapes.
# 【Reading Tips】
- **Skim Chapter 1's selector catalog** if you already know basic CSS; but deep-read the specificity and inheritance sections (1.4) — they explain the most common real-world debugging confusion.
- **Work through the box model chapter with a browser console open** — the book explicitly shows how to verify computed values (e.g., 200px × 50% = 100px). Reproduce the margin collapsing examples yourself.
- **Treat Chapter 4 (display) as a reference for "when to use what"** — the table-cell section is the most valuable; bookmark the three use cases (vertical centering, equal height, even distribution).
- **For float/positioning (Chapters 7–8), focus on the "why"** — normal flow vs out-of-flow is the theoretical foundation. The clearfix pattern is a must-memorize snippet; the positioning patterns (relative parent + absolute child) are reusable for nav menus.
- **Skim Chapter 9 (CSS graphics)** — the triangle and border-radius techniques are quick wins; don't over-invest unless you need custom shapes.
# 【Coverage Limits】
Excerpts cover roughly the first half of the book (through positioning and the start of CSS graphics). Later chapters on performance optimization, CSS techniques, important concepts, HTML appendix, and interview questions are not covered in this guide.
#
Page 20
{ width:200px; height:160px; border:1px solid blue; font-size:2rem; } #son { width:150px; height:100px; border:1px solid red; font-size:2rem; } </style> </he...
View in text
Excerpt 2
,有些小伙伴可能会想到以下方法。 *{padding:0;margin:0;} 在实际开发中,我们并不建议使用这个方法。因为这个方法性能非常低,它其实把所有元素的 padding 和 margin 都去掉了。然而对于表格元素(或者 input 元素)的 margin 和 padding,我们 是不希望去掉的。此外...
View in text
Excerpt 3
{ width:300px; height:100px; background-image:url(img/logo.jpg); text-indent:-9999px; } </style> </head> <body> <h1>绿叶学习网</h1> </body> </html> 预览效果如图 5-1 所示。...
View in text
Excerpt 4
t; 改为 float:right;,此时预览效果如 图 7-14 所示。 图 7-14 同一方向的兄弟元素(右浮动) 相反方向的兄弟元素。 当一个浮动元素碰到相反方向的兄弟元素时,这两个元素会移向两边(如果父元素的宽度足够的 话)。 举例 <!DOCTYPE html> <html> <head> <met...
View in text
Excerpt 5
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> div { width:160px; height:100px; 9.5 图标制作 159 div { width:0...
View in text
Excerpt 6
标效果,如图 11-14 和图 11-15 所示,估计很多人能够想到的是使用 CSS Sprite 结合背景图片来实现。但是在实际开发中,我们都会遵循“少用图片”原则。因为这会导致图片 数据传输量大,并引发一次 HTTP 请求。而且这些小图标,如图 11-14 所示,也可能会有多个尺 寸、多种颜色等,如果要使用背...
View in text
Excerpt 7
。 语义化验证。 HTML5 舍弃的标签。 234 从 0 到 1 系列图书 第 14 章 语义化 语法 <figure> <img src="" alt=""/> <figcaption></figcaption> </figure> 说明 figure 元素用于包含图片和图注,figcaption 元...
View in text
Excerpt 8
从 0 到 1 系列图书 附录 2 前端面试题 4.HTML 顶部中 <!DOCTYPE> 的作用是什么? <!DOCTYPE> 位于 HTML 文档中的第一行,用于告知浏览器应该以什么文档标准来解析这 个文档。在 HTML5 中,我们只需要这样写就可以了。 <!DOCTYPE html> 5.简单说一下你对 H...
View in text
Tags
AI categories
Web Technologycssfrontend
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Generating text preview…
Loading comments...
Reply to Comment
Edit Comment