Home > Web Front-end > CSS Tutorial > How to divide text into columns in css

How to divide text into columns in css

青灯夜游
Release: 2023-01-07 11:42:17
Original
4796 people have browsed it

You can use the columns attribute or column-width and column-count attributes to divide text into columns in css. You only need to add "columns: column width and number of columns;" or "column-width: value" to the text element. ;column-count:value;" style is enough.

How to divide text into columns in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can use the columns attribute or the column-width and column-count attributes to divide text into columns.

Let’s use code examples to see how css implements text columns.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
div{
	margin:20px 10px;
}
.div1
{
	columns:100px 3;
	-webkit-columns:100px 3; /* Safari and Chrome */
	-moz-columns:100px 3; /* Firefox */
}
.div2
{
	column-count:4;
	column-width:100px;
	
	-moz-column-count:4; /* Firefox */
	-moz-column-width:100px; /* Firefox */
	
    -webkit-column-count:4; /* Safari and Chrome */
	-webkit-column-width:100px; /* Safari and Chrome */
}
</style>
</head>
<body>

<div class="div1">
当我年轻的时候,我梦想改变这个世界;当我成熟以后,我发现我不能够改变这个世界,我将目光缩短了些,决定只改变我的国家;当我进入暮年以后,我发现我不能够改变我们的国家,我的最后愿望仅仅是改变一下我的家庭,但是,这也不可能。当我现在躺在床上,行将就木时,我突然意识到:如果一开始我仅仅去改变我自己,然后,我可能改变我的家庭;在家人的帮助和鼓励下,我可能为国家做一些事情;然后,谁知道呢?我甚至可能改变这个世界。
</div>
<div class="div2">
当我年轻的时候,我梦想改变这个世界;当我成熟以后,我发现我不能够改变这个世界,我将目光缩短了些,决定只改变我的国家;当我进入暮年以后,我发现我不能够改变我们的国家,我的最后愿望仅仅是改变一下我的家庭,但是,这也不可能。当我现在躺在床上,行将就木时,我突然意识到:如果一开始我仅仅去改变我自己,然后,我可能改变我的家庭;在家人的帮助和鼓励下,我可能为国家做一些事情;然后,谁知道呢?我甚至可能改变这个世界。
</div>

</body>
</html>
Copy after login

Rendering:

How to divide text into columns in css

Description:

columns attribute is a shorthand Attribute, you can set both the column width (column-width) and the number of columns (column-count) in one declaration.

column-width attribute: set the width of the column

column-count attribute: set the number of columns

(Learning video sharing: css video tutorial)

The above is the detailed content of How to divide text into columns in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template