本文主要讨论左右边栏固定宽度,中间栏填满其余空间的布局。至于其他类型,基本上也就是半斤和八两。每一种布局都会有个Demo,个人依然认为文章里帖代码并没有Demo来的直接。所以正文负责解释,源码参见Demo。其中讨论了这么多种(6种)布局,有以下理由:1是每种布局也都有他的毛病,没有十全十美的,每种布局也都有人在用。2是虽然有相对优秀的方案,但是不优秀的方案也有有用的东西在里边,可能会启发其他的思路补充遗漏的知识点。
- 利用绝对定位特点:左右两栏采用绝对定位抽离文档流,分别固定于页面的左右两侧,中间栏用左右margin值撑开可以容纳左右边栏的距离。这个很简单不多解释。Demo:http://www.dabao.love/demo/layoutDemo/absoluteLayout.html
- 利用两侧浮动都不占据文档流:左栏左浮动,右栏右浮动,中间栏左右margin值等于左右栏宽度。html中,中间栏要放在左右边栏的后边。道理上和绝对定位差不多,就是不占文档流了其他元素就填充上了,只要把两边留出空间不导致重合即可。Demo:http://www.dabao.love/demo/layoutDemo/twoSidesFloatLayoutDemo.html
- 利用浮动和margin负值的特点:标签顺序为
middle 宽度 100%,sub 左右 margin 为左右栏留出空间,其中 sub 元素不要浮动,否则会包裹里面的内容而不会撑满空间,其他元素全部左浮动。left 的 margin-left 为-100%,right 的margin-left为sub的负的margin-right 。浮动的特点就是紧跟着前一个元素,放不下了就换行,本来middle元素占满了第一行,sub元素的margin留出的空间并不会给其他的浮动元素,左栏被迫换行,处于第二行最左侧,相当于紧跟着第一行后边,100%的负margin-left会让他从紧跟着第一行变成第一行最左边,这时左栏和sub元素的margin-left留出的空间重合,达到目的,此时右栏在原来左栏的位置,再用类似的处理方式,达到最终效果。其中sub的margin可以换为padding,相同的原理和效果。此处如果不需要撑满空间(有内容撑满sub)可以不要父元素(即middle)。Demo:http://www.dabao.love/demo/layoutDemo/floatLayoutDemo.html
- 利用inline-block特点:父元素包含左中右栏:(子元素顺序中,左,右)父元素设置padding为左右栏留出空间,然后中栏宽度100%占据除padding外的空间,左右栏利用margin-left等于自身宽的负值使其与中栏右边界重合,再调节left,左栏left为-100%右栏left为右栏宽度。左中右栏全部为子元素,所以margin-left无法占据padding空间,需要左右边栏相对定位后调解left值达到目标状态。其中注意父元素设置font-size: 0; letter-spacing: -4px; 子元素再重置这两个属性。Demo:http://www.dabao.love/demo/layoutDemo/inlineBlockLayoutDemo.html
- 利用calc属性和inline-block特点:(同样是父元素包含左中右栏)
父元素设置: text-align:center; font-size: 0; letter-spacing: -4px;
左中右栏再重置: font-size: 16px; letter-spacing: normal;
左右栏固定宽度, html中元素顺序为:左,中,右 ,假设左右栏宽度和300px;
中间拦: width:calc(100% - 300px);
百分比与固定宽度混合布局使用,支持ie9+,注意+-*/号两边留空格
Demo:http://www.dabao.love/demo/layoutDemo/useCalcLayoutDemo.html
- 利用flex布局:flex布局我认为是最先进而方便的布局,非常灵活不过内容也不少,只可惜兼容ie10+。不在这多废话,推荐阮一峰老师的教程:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool 父元素display:flex; ,左右两栏设置flex-basis 预置宽度,中间栏flex-grow: 1;自动伸展。完活。Demo:http://www.dabao.love/demo/layoutDemo/flexLayoutDemo.html
如有纰漏欢迎批评指正,没有纰漏也欢迎拍砖。

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.

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.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

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.

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment