css 中text-align:justify 到底有什么作用?

html-css011

css 中text-align:justify 到底有什么作用?,第1张

这个是属性是单词两端对齐的意思。

值 justify 可以使文本的两端都对齐。在两端对齐文本中,文本行的左右两端都放在父元素的内边界上。然后,调整单词和字母间的间隔,使各行的长度恰好相等。

你对比一下下面的代码就明白了

css代码:

.box1{ width:500pxline-height:20pxmargin:10px autobackground-color:#cddtext-align:justify}

.box2{ width:500pxline-height:20pxmargin:10px autobackground-color:#cddtext-align:left}

html代码:

<div class="box1">There is clearly a need for CSS to be taken seriously by graphic artists. The Zen Garden aims to excite, inspire, and encourage participation. To begin, view some of the existing designs in the list. Clicking on any one will load the style sheet into this very page. The code remains the same, the only thing that has changed is the external .css file. Yes, really</div>

<div class="box2">There is clearly a need for CSS to be taken seriously by graphic artists. The Zen Garden aims to excite, inspire, and encourage participation. To begin, view some of the existing designs in the list. Clicking on any one will load the style sheet into this very page. The code remains the same, the only thing that has changed is the external .css file. Yes, really</div>

在 html 语言中,<p>被定义为段落标记,文档中任何适用于段落的地方,都可以出现p标签,例如文档的主体、列表、表格等元素中。

p标签是一个块级元素,可CSS规定宽、高属性,代码﹤p style="width:宽度值height:高度值"﹥。

每当创建一个 p 元素,浏览器均会在段落前后添加空行。

若使用了p标签来包含段落,而没有为其设定CSS属性,那么浏览时仅仅是新起了一段,不会有其它的任何效果。

p标签属性: align 属性已不被 HTML5 所支持,以下属性均可使用CSS样式来代替,p标签支持 HTML5 中的全局属性可参考《DIV标签包含的所有属性(HTML5新增DIV属性)》这篇文章

p align="left" :设置段落中的内容左对齐。CSS写法:p {text-align:left}

p align="right":设置段落中的内容右对齐。CSS写法:p {text-align:right}

p align="center":设置段落中的内容居中。CSS写法: p {text-align:center}

p align="justify":设置段落中的文本两端对齐。CSS写法: p {text-align: justify}。

注:p align="justify"只有当元素中的文章是英文时才能见到效果,如果是中文则不会看到任何效果,若想要中文文章也看到这种效果,就需要在CSS样式中多添加一条 text-justify:inter-ideograph 属性,完整的CSS样式代码:p {text-align:justifytext-justify:inter-ideograph}

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:

div{

border: 1px solid blue

width: 300px

text-align: justify

}

div:after {

display: inline-block

width: 100%

content: ''

}

3、浏览器运行index.html页面,此时一行内的文字实现了两端对齐。