search
HomeWeb Front-endHTML Tutorial'Writing High-Quality Code - How to Practice Web Front-End Development' Reading Notes_html/css_WEB-ITnose

Foreword

In the past two weeks, I have participated in the company's new project, using closed development (project members develop in the conference room), working overtime until late at night , so I don’t have the time and energy to write an original blog. Today I will share my reading notes on "Writing High-Quality Code - How to Practice Web Front-End Development".

Text

If you want to master one line, you must first understand ten lines.

In the field of front-end development, it is very necessary to have one specialty and multiple abilities.

Table layout disadvantages:

  • Large amount of code and confusing structure;
  • The tag semantics are unclear and not useful for search engines. friendly.
  • css layout: div css, or (x)html css.

    Small amount of code, streamlined structure, and fresh semantics.

    The less code, the browser download time will be shorter;

    The clear semantics will be more friendly to search engines.

    First determine the html, determine the semantic tags, and then choose the appropriate CSS.

    The browser will give a default style based on the semantics of the tag.

    A simple way to judge whether the semantics of web page tags is good is to remove the style and see whether the web page structure is well organized and orderly, and whether it is still readable.

    Test whether the CSS settings in the web page are disabled in DevTool? Test the effect of w3c official website after removing the style.

    tag, search engines are more sensitive to it, especially h1 and h2.

    When the tags on the page cannot meet the design needs, non-semantic tags such as div and span will be appropriately added to assist the implementation.

    The table layout is suitable for displaying two-dimensional data.

    Some other issues that should be paid attention to with semantic tags:

  • Use as few semantic tags divs and spans as possible.
  • In places where the semantics are not obvious and you can use either p or div, try to use p, because p has upper and lower spacing by default, and the readability is better after de-styling, which is beneficial for compatibility with special terminals .
  • Instead of using pure style tags, such as b, font, u, etc., use css settings instead. Text that needs semantic emphasis can be included in the strong or em tags.
  • There is no perfect solution to the problem of too scattered and concentrated files. We need to make appropriate compromises based on the actual situation.

    css rest:

  • Not recommended * { margin: 0; padding: 0 }, the recommended ones are listed. It is also not recommended to write: {margin:0; padding:0; color:#000; font-size:12px;}, because this will destroy the inheritance of CSS.
  • .fl { float: left; display: inline } where display: inline is to solve the double margin bug of IE6.
  • .zoom { zoom: 1 } is a proprietary attribute of IE, in order to trigger IE's hasLayout. When zoom is invalid, you can set "position: relative" to trigger hasLayout.
  • Supplement:

    Reset browser default style, recommended: https://github.com/necolas/normalize.css

    Split modules:

  • Try not to include the same parts between modules. If there are the same parts, they should be extracted and split into an independent module.
  • Modules should be as simple as possible while keeping the number as small as possible to improve reusability.
  • Camel case is used to distinguish words, and underlining is used to indicate affiliation. For example: .timeList-lastItem.

    Learn this style of naming:

    .fr { float: right; }

    .w25 { width: 25%; }

    Use composition more and inheritance less.

    When there is a conflict between style settings, the style with higher weight will be used.

    The weight of html tag: 1, the weight of class: 10, the weight of ID: 100.

    When the weights are the same, the nearest definition principle will be used.

    In order to ensure that the style can be easily overridden and improve maintainability, the weight of the CSS selector should be as low as possible.

    CSS hack methods are usually selector prefix method and style attribute prefix method.

    The four states of the tag are defined in order, l(link)ov(visited)e h(hover)a(active)te, which is the love hate principle.

    Block-level elements and inline elements:

  • Block-level elements can set width and height attributes, but inline elements have no effect on setting width and height attributes.
  • Block-level elements can set margin and padding attributes. Inline elements set the horizontal direction of margin and padding, that is, -left and -right are valid, and the vertical direction -top and -bottom are invalid.
  • Switch block-level elements and inline elements by modifying the display attribute.
  • hasLayout:

    is a proprietary attribute designed by IE browser to parse the box model. It was originally designed to be used for blocks. For level elements, if hasLayout of inline elements is triggered, the inline elements will have some characteristics of block-level elements.

    display: inline-block

    An inline block-level element, which has the characteristics of block-level elements: you can set the width, height, margin and The padding value also has the characteristics of inline elements: it does not occupy an exclusive line.

    will trigger hasLayout. Vertical alignment can be solved by setting *vertical-align: -10px.

    In order to make E6, IE7 and other browsers compatible with display: inline-block, there are also certain problems:

  • It can only implement display: inline-block for inline elements; it cannot be Block-level elements.
  • *vertical-align is a hack for IE, which is also unfriendly. Try not to use hacks if you can.
  • Although IE6 and IE7 do not support CSS setting to display: inline-block, in fact the CSS parsing engines of IE6 and IE7 still have display: inline-block. For example, both img tags and button tags have display : Inline-block feature, you can set the width and height without occupying an exclusive line.

    float

    will change the normal document flow arrangement and affect surrounding elements.

    position: absolute and float: left or float: right will implicitly change the display type. No matter what type of element it was before (except display: none), the element will be displayed in display: inline-block mode. : You can set the width and height. The default width does not occupy the parent element.

    Centered

  • Horizontally centered
    (1) Horizontal centering of inline elements such as text and pictures: set text-align to the parent element : center
    (2) Horizontal centering of block-level elements with determined width: Set margin-left: auto and margin-right: auto
    (3) Horizontal centering of block-level elements with uncertain width:
    I. Use the table package and set margin: 0 auto; Advantages: Clever approach. Disadvantages: Added unsemantic tags and deepened the nesting levels of tags.
    II. Use display: inline/inline-block; Advantages: Simple and clear, clear structure. Disadvantages: After using inline, it becomes an inline element and lacks certain features, such as: width, hieght...
    III. Use position: relative, set float, position: relative and left: 50% for the parent element, and set float, position: relative and left: 50% for the child element. Set position:relative and left:-50%. Advantages: Clear structure. Disadvantages: position:relative will bring some side effects.
  • Vertical centering
    (1) Vertical centering of text, pictures, and block-level elements whose parent element height is uncertain: Set the same top and bottom padding to the parent container to achieve this.
    (2) Vertical centering of a single line of text determined by the height of the parent element: line-height: height of the parent element.
    (3) Vertically center multi-line text, pictures, and block-level elements whose parent element height is determined:
    I. Using table wrapping, disadvantages: adding unsemantic tags and increasing the number of nesting levels.
    II. For IE8 and Firefox that support display: table-cell, use display: table-cell and vertical-align: middle to achieve centering. For IE6-7 that does not support it, use a specific format hack: give parent and child two layers The elements are set to { *position: absolute; *top: 50% } and { *position: relative; *top: -50% } to achieve centering. Disadvantages: Using it for hacking is not conducive to maintenance. Setting position: relative; position: absolute; brings some side effects.
  • Grid layout

    No matter who is left or right in style between sidebar and main, in the html tag, make sure that the main tag is in the sidebar was loaded before.

    Only the outermost container is given a specific width, the width of all other containers is set as a percentage ?? Grid layout.

    z-index

    The z-axis is activated after the element sets position to absolute or relative.

    Setting negative margins can cause the positions of adjacent elements to overlap. Which one floats on top depends on the order in which the html tags appear. The tags that appear later float on top of the tags that appear first.

    For the select occlusion problem under IE6, you can use an iframe of the same size to cover the select.

    In order to avoid the overlap problem of the upper and lower margins of components and the bug caused by IE's hasLaout, all modules use margin-top to set the upper and lower margins, except for special needs.

    Javascript

  • Using anonymous functions to wrap scripts can effectively control global variables and avoid potential conflicts.
  • To prevent JS from causing conflicts, you need to avoid the proliferation of global variables, make reasonable use of namespaces, and add necessary attention to the code.
  • DOMReady is more suitable to call the initialization function than window.onload.
  • Call the init function at the end of the page, that is, before the
  • 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
    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.

    HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

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

    HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

    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.

    From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

    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.

    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

    MantisBT

    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

    Dreamweaver Mac version

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools