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

html-css08

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 属性设置间隙

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