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

html-css043

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>

CSS2.1定义了 4 中布局方式

给任意元素设置 display:flex,弹性布局就会被创建,flex 的子项会发生变化.

flex-direction属性用来控制 flex 子项的整体布局方向,决定是从左往右排序.flex-dirction属性有以下语法

flex-wrap属性用来控制 flex 子项单行显示还是换行显示,以及在换行显示情况下,没一行内容是否在垂直方向的反向显示.

flex-flow属性是 flex-dirction属性和 flex-wrap属性的缩写.表示弹性布局的流动性特性

CSS 在 flex 中属性名称基本上是几个固定单词的组合,且这些单词在整个 CSS 世界中是通用的含义

justify-content 属性在弹性布局中常用的语法如下

align-item和 align-self属性的一个区别是 align-self属性是设置在具体的某个 flex 子项上,而 flex-items 属性是设置在 flex 容器上,器控制 flex 子项的垂直对齐方式,align-self默认值是 auto,其余的数据值个 align-items 属性值一致.属性如下

align-content属性和 align-items属性的区别在于 align-items属性设置的是每一个 flex 子项的垂直对齐方式,而 align-content 属性是将所有作为一个整体进行垂直对齐设置.align-content 属性如下所示

我们可以通过 order 属性来改变 flex 子项的顺序位置.order 属性越小优先级别越高

flex 属性是弹性布局的精髓,因此弹性布局就是 flex 属性的作用.flex 属性是 flex-grow flex-shinrk flex-basic这 3 个属性的缩写.我们先了解下flex 常用的几个声明

表示的是什么意思?

flex-basic 属性用来表示基础宽度

flex-grow 属性表示宽度还有剩余的时候

flex-shrink 属性表示宽度不足的时候

flex:0等同设置 flex:0 1 0%,flex:none等同设置了 flex:0 0 auto.

如果没一行的行数是固定的,则可以使用两种方式实现最后一行对齐

要实现最后一行对齐,理论上最好使用 gap 属性设置间隙

如果每一行的行数不固定,则上面的方法都失效,需要使用其他的方式实现最最后一行对齐.可以使用空白标签进行填充占位,具体的占位数量由最多列数的个数决定

在 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}