search
HomeWeb Front-endHTML Tutorial[Reading Notes] Proficient in CSS Second Edition_html/css_WEB-ITnose

div and span:

div is used to group block-level elements, and span is used to group row-level elements. div stands for division, which can separate the document into several meaningful parts. div should only be used when no existing elements can achieve area separation.

Microformat:

There are no corresponding elements in HTML, making it difficult to highlight information such as people, places, dates, etc.

Reference: Microformat

Document Type Definition DTD:

DTD is a set of machine-readable rules that define what is allowed and what is not allowed in a specific version of XML or HTML. When parsing a web page, the browser will Use these rules to check the validity of the page and take appropriate actions

  • DOCTYPE currently has two styles, strict and transitional
  • Browser manufacturers began to create standards-compliant browsers, they wanted to ensure backward compatibility, they created

  • Standards mode
  • quirks mode
  • almost standard mode
  • Selector:

  • Element selector
  • Descendant selector: represented by a space between the two selectors
  • ID selector
  • Class selector
  • Pseudo-class selector:
  •                                                                                       : hover: active and: focus are called dynamic pseudo-classes, which can theoretically be used for any element

    Universal selector: *, which can be used to apply styles to all descendants of an element, or skip one level of descendants

  • Child selector: > , only selects the direct descendants of the element, that is, child elements
  • Adjacent sibling selector: , used to locate elements after an element under the same parent element
  • Attribute selector: Find elements based on the presence or value of an attribute
  • Cascade and specificity:
  • ! important increases the importance.

    The author's style sheet, i.e. the site developer, is the most important, followed by the user, and finally the default style sheet used by the browser or user agent

    If the specificity of the two rules is the same, then the last definition The priority

    cascade adopts the following order of importance:

    is marked with! important user style
    1. is marked with! author styles
    2. author styles
    3. user styles
    4. styles applied by the browser/user agent
    5. Inherited from:

    Descendants of the element to which the style is applied inherit some properties of the style

    Any style applied directly to an element will always override the inherited style because the inherited style specificity is null

    Planning for Organizing and Maintaining Stylesheets: Ways to Manage Your Code

    Recent browser benchmarks have shown that importing stylesheets is slower than linking stylesheets

    Multiple files can cause problems from The server sends more packets and the number of these packets (not the content) affects the download time

    Browsers can only download a limited number of files from the same domain at the same time (2 for old browsers, 2 for modern 8 browsers)

    CSS uses c-style /* */ comments. It is recommended to add a flag @ comment in each comment header to facilitate search

    Link: CSSDoc Project: CSS Module Annotations

    CSS document structure

    /* @group general styles General styles

    ------------------ -------------------------------------------------- -*/

    Body style
    1. reset style
    2. Links
    3. Title
    4. Other elements
    5. /* @group helper styles auxiliary styles

    --------------------------------- ------------------------------------*/

    Forms
    1. Notifications and errors
    2. Consistent entries
    3. /* @group page structures Page structures

    ----- -------------------------------------------------- ---------------*/

    Header, footer and navigation
    1. Layout
    2. Other page structure elements
    3. /* @group page componentsPage components

    ----------------------- --------------------------------------------------*/

    Each page
    1. /* @group overrides coverage

    ------------- -------------------------------------------------- -----*/

    Color reference value table

    Add a color lookup table as a comment at the head of the style sheet before development, delete it after completion

    /* Color Variables

    @colordef #434343; dark gray;

    @………………………………………….

    */

    CSS Optimization

    Remove comments, delete whitespace

    Link:

    Server-side compression: Apache’s mod_gzip or mod_deflate

    Box Model

    If you add a background on an element, the background is applied to an area consisting of content and padding, so we often use padding to create an isolation band around the element, making the content It will not be mixed with the background. Adding a border will add a line outside the inner margin. Outside the border is the outer margin. The outer margin is transparent. It is generally used to control the spacing between elements.

    css2.1 also includes the outline attribute, unlike the border attribute, outlines are drawn above the element box, so they do not affect the size and positioning of the element, so outline helps fix bugs because they do not affect the page layout, most modern browsers (including IE8) support outlines.

    Padding, borders, and margins are all optional and default to 0. But many elements will have margins and padding set by user-agent stylesheets.

    Margins can be negative

    Margin stacking: when two or more vertical margins meet, they will form a margin with a height equal to two The larger of the heights of the margins at which overlapping occurs. When an element is contained within another element, their top and bottom margins will also overlap, assuming there is no padding or border separating them. If an empty element only has margins but no padding and borders, its own top and bottom margins will also overlap.

    Margin overlay actually has important meaning, it makes the distance everywhere on the text page consisting of several paragraphs consistent.

    Only the vertical margins of block boxes in ordinary documents will overlap. The margins between inline boxes, floating boxes or absolutely positioned boxes will not overlap.

    Visual format model

    display: change the type of generated box

  • block: block-level elements, block boxes, arranged vertically one after another from top to bottom, between boxes The vertical distance between is calculated from the vertical margin of the box, =
  • inline: Inline elements, inline boxes, arranged horizontally in a row, the horizontal spacing can be adjusted with horizontal padding, border and margin, but Vertical padding, borders, and margins do not affect the height of the inline box. Setting the display height or width on the inline box has no effect.
  • The horizontal box formed by a line is called a line box. The height of the line box is always enough to accommodate all the inline boxes it contains, but setting the line height can increase the height of this box, so modify the size of the inline box. The only way is to change the line height or horizontal border padding and margins.

  • none: Not displayed, the generated element has no box at all and does not occupy document space
  • inline-block As the name suggests, this statement allows the elements to be arranged horizontally like inline elements, but the behavior of the box is still consistent Block-level box behavior
  • Understand that everything seen on the screen forms some kind of box

  • Anonymous block box: when adding some text to the beginning of a block-level element (like a div) , these texts will be treated as block-level elements
  • Anonymous line boxes: lines of text within block-level elements, assuming a paragraph containing three lines of text, each line of text forms an anonymous line box
  • It is not possible to apply styles directly to anonymous blocks or line boxes, except by using the less common: first-line pseudo-element

    CSS three positioning mechanisms:

  • Normal flow: the position of the element box is determined by the element Position determination in HTML
  • Relative positioning: position: relative;

    Relative positioning is actually considered part of the normal flow positioning model, because the position of an element is relative to its position in the normal flow The initial position is offset, but regardless of whether it is moved or not, the element still occupies the original space, so moving the element will cause it to cover other boxes.

  • Floating:
  • A floating box can be moved left or right until its outer edge touches the edge of the containing box or another floating box. Because the floating box is not in the ordinary document flow, the block box in the ordinary document flow behaves as if the floating box does not exist

    In fact, the floating box does not affect the non-floating elements at all. If the floating box If there is an element in the document flow behind the element, then the box of this element will behave as if the float does not exist at all. However, the text content of the box will be affected by the floating element and will move to leave space. In technical terms, the line box next to the floated element is shortened to make room for the floated element, so the line box wraps around the floated box (floats are actually designed to achieve a text wrapping effect).

    To prevent line boxes from surrounding the outside of the floating box, you need to apply the clear attribute to the elements containing these line boxes. The value of the clear attribute can be left, right, both, and none, which represents which parts of the box The edges should not be next to the floated box. When clearing an element, the browser adds enough margin to the top of the element so that the top edge of the element drops vertically below the floated box.

    A floated element breaks out of the document flow and does not affect surrounding elements, but cleaning the element actually leaves vertical space for the floated element in front of it.

  • Absolute positioning: position: absolute;
  • Absolute positioning makes the position of the element independent of the document flow. It does not occupy space. The layout of other elements in the ordinary document flow is as if the absolutely positioned element does not exist. . If an absolutely positioned box is enlarged (e.g. by increasing the font size) the surrounding boxes will not be repositioned, so any change in size has the potential to cause the absolutely positioned boxes to overlap, ruining a carefully tuned layout

    An absolutely positioned element is positioned relative to its nearest positioned ancestor, or, if none exists, relative to the initial containing block.

    Because absolutely positioned boxes have nothing to do with document flow, they can cover other elements on the page. The stacking order of these boxes can be controlled through the z-index attribute. The higher the z-index value, the better the frame is. The higher the position in the stack.

    Fixed positioning: position: fixed;

    Fixed positioning is a type of absolute positioning. The difference is that the containing block of the fixed element is the browser window (viewport), which allows us to create an overall Is a floating element that appears in the same position in the window

    IE and the box model

    Earlier versions of IE, including IE6, use their own non-standard box model in promiscuous mode, and the width attribute of these browsers Not the width of the content, but the sum of the widths of the content, padding and borders. So IE's proprietary box model makes elements smaller than expected.

    IE6 does not support fixed positioning, IE7 partially supports it, and has many bugs

    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
    What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

    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.

    How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

    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 vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

    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.

    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.

    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

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

    EditPlus Chinese cracked version

    EditPlus Chinese cracked version

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