CSS3提供了个新属性columns用于多列布局。在这之前,有些大家习以为常的排版,要用CSS动态实现其实是比较困难的。如竖版报纸
在我不知columns这属性之前,第一反应是:这有何难,多弄几个并列的div不就行了?但仔细想想确实很难实现,因为内容是动态的。搞几个div容易,但每个div内放多少文字呢?一篇文章该在哪行哪段剪切进不同的div内呢?你肯定不愿意为每一段文字,都在特定的地方插入div标签,那代码重用性太低了。而column属性完美的解决了这个问题,让浏览器来决定在文字该在哪里换列。你所做的只需指定每列的宽度和列数即可。
先来看看columns和它的子属性:
- column-width
- column-count
- column-gap
- column-rule
- column-span
- column-fill
column-width给列定义个最小的宽度。默认值为auto表示将根据column-count列的数量自动调整列宽。
column-count最大列数,不赘述。
通常上面两个参数都合并在columns中一起指定。例如columns: auto 4;就是上图的效果,会将div分成4列,并根据div的宽度640px,均分列宽为160px(其实不到160px,因为还有列间距)。代码如下:
.wrapper { -moz-columns: auto 4; -webkit-columns: auto 4; columns: auto 4;}<div class="wrapper">...大段文字…</div>
上述实现简单到有的过分,现在看看更灵活的用法。上例中外层div是定宽640px,因此通过计算后得到的列宽也是固定的。无论你如何缩放浏览器窗口大小,都固定4列。这样显得不够灵活。
如果想要根据窗口尺寸自适应,随着窗口拉窄,从4列逐渐变为1列,随着窗口拉宽,再从1列逐渐变为4列。首先你需要将外层div从定宽width: 640px;改成动态宽度width: 50%;。其次columns-width不能同时为auto,否则会根据div动态宽度得到列宽,仍旧固定为4列。所以columns-width需要为定值。效果可以点这里,并且拉伸浏览器窗口试试。
column-gap是列间距,默认值normal,相当于1em。需要注意的是,如果column-gap与column-width加起来大于总宽度的话,就无法显示column-count指定的列数,会被浏览器自动调整列数和列宽
column-rule用于设置列的边框,类似于border,区别是不占用任何空间,因此设了column-rule不会导致列宽的变化。另外如果边框宽度大于column-gap列间距,将不会显示边框。语法和border类似,例如column-rule: 1px solid #000;。效果见例子页面。
column-span用于跨列,默认值none表示不跨列,all表示跨越所有列。例如文章标题可以设成all来跨列。效果见例子页面
column-fill用于统一列高。默认值auto各列的高度随内容自动调整,balance所有列高都设为最高的列高
总结
columns属性最大的问题还是浏览器兼容性问题,参见Can I Use。而且竖版排列暂时用的地方不多,这个属性是否能流行闪光尚存疑问。如果内网有这方面的需求,用用还是极好的。

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

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

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.

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

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.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software