search
HomeWeb Front-endHTML TutorialSummary of CSS layout basics_html/css_WEB-ITnose

  • Common layout types
  • One column layout
  • Two column layout
  • Three column layout
  • Positioning mechanism in CSS
  • Principles of structure and performance of simple web page layout
  • Hide CSS elements
  • The best way to clear floats in CSS
  • DIVCSS specification naming collection
  • DIVCSS naming reference table
  • Import styles and scripts
  • Traditional way
  • New specification
  • Common layout types

    One-column layout

  • Top-down, generally the header has a fixed width and the height is set to automatic
  • Two-column layout

  • Adaptive two-column layout: width is float as a percentage;
  • Fixed-width two-column layout: width: specific value/width of parent element is determined, width is percentage; float;
    If float is not added, side-by-side two-column layout cannot be achieved.
  • Three-column layout

  • The traditional three-column layout relies on float
  • Special three-column layout: fixed left and right, adaptive in the middle, left and right are implemented using absolute positioning , the middle is implemented with margin.
    Three-column layout: left and right fixed, middle adaptive:
  • Positioning mechanism in CSS
    1. Standard document flow
    2. Floating
    3. Absolute positioning
    Principles of structure and performance of simple layout of web pages
  • Simplify the structure of html to the greatest extent, and then use css to set it up to reduce the fit between html and css
  • You should not add meaningless tags for the sake of style
  • Structure and presentation are separated, the structure is simple, and the structure is built without considering the layout style
  • CSS elements are hidden
    { display: none; /* 不占据空间,无法点击 */ }{ visibility: hidden; /* 占据空间,无法点击 */ }{ position: absolute; clip:rect(1px 1px 1px 1px); /* 不占据空间,无法点击 */ }{ position: absolute; top: -999em; /* 不占据空间,无法点击 */ }{ position: relative; top: -999em; /* 占据空间,无法点击 */ }{ position: absolute; visibility: hidden; /* 不占据空间,无法点击 */ }{ height: 0; overflow: hidden; /* 不占据空间,无法点击 */ }{ opacity: 0; filter:Alpha(opacity=0); /* 占据空间,可以点击 */ }{ position: absolute; opacity: 0; filter:Alpha(opacity=0); /* 不占据空间,可以点击 */ }
    The best way to clear floats in CSS

    Add overflow: hidden
    at the parent level. Advantages: There are no structural and semantic problems, and the amount of code is very small.

    The parent element is also set to float (add a float: left/right)

    Advantages: There are no structural and semantic problems, and the amount of code is very small
    Disadvantages: It makes elements adjacent to the parent element The layout will be affected and it is impossible to float all the way to the body. It is not recommended to use

    parent element to set display:table

    Advantages: The structure semantics is completely correct and the amount of code is very small
    Disadvantages: Box model The attributes have been changed, and the resulting series of problems are not worth the loss. It is not recommended to use

    Use the :after pseudo-element

    Advantages: It should be noted that: after is a pseudo-element, not a pseudo-class (some CSS It is called "pseudo-object" in the manual), and many articles such as Clear Float are called pseudo-classes. However, CSS should be more rigorous. This is an attitude.
    Since IE6-7 does not support :after, use zoom:1 to trigger hasLayout.
    Disadvantages: Compatibility is not very good.

    Add empty tags after floating elements

    Clear floats

    Advantages: Simple and clear
    Disadvantages: Meaningless empty tags, not conducive to semantics

    DIV CSS specification named collection

    DIV CSS naming reference table CSS style naming instructions CSS file naming instructions
    wrapper Page peripheral control overall layout width master.css, style.css main
    container or #content container, used for the outermost module.css Module
    layout Layout base.css Basic common
    head,#header Header part layout .css Layout, layout
    foot, #footer Footer part themes. css theme
    nav main navigation columns.css Column
    subnav Secondary navigation font.css Text, font
    menu menu forms.css form
    submenu Submenu mend.css Patch
    sideBar Sidebar print.css Print
    sidebar_a,#sidebar_b Leftbar or Right column
    main Page body
    tag tag
    msg#message Prompt message
    tips Tips
    vote Vote
    friendlink Friendlink
    title title
    summary Summary
    loginbar Log in Bar
    searchInput Search input box
    hot Hot Hotspot
    search Search
    search_output Search output is similar to search results
    searchBar Search bar
    search_results Search results
    copyright Copyright information
    branding Trademark
    logo Website LOGO
    siteinfo Website information
    siteinfoLegal Legal Notice
    siteinfoCredits Reputation
    joinus Join us
    partner Partner
    service Service
    regsiter Register
    arr/arrow arrow
    guild Guidelines
    sitemap Sitemap
    list list
    homepage Homepage
    subpage Secondary page sub-page
    tool,#toolbar Toolbar
    drop Drop-down
    dorpmenu 下拉菜单
    status 状态
    scroll 滚动
    .tab 标签页
    .left.right.center 居左、中、右
    .news 新闻
    .download 下载
    .banner 广告条(顶部广告条)
    导入样式及脚本

    传统方式

  • 引用线上CDN
  • 引用本地文件
  • 新规范

    根据 HTML5 规范,在引入 CSS 和 JavaScript 文件时一般不需要指定 type 属性,因为 text/css 和 text/javascript 分别是它们的默认值。

    <!-- External CSS --><link rel="stylesheet" href="code-guide.css"><!-- In-document CSS --><style> /* ... */ </style><!-- JavaScript --><script src="code-guide.js"></script>
    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
    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.

    Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

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

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.