In Bootstrap 5 Documentation they added a note:-
在Bootstrap 5文档中,他们添加了一条注释:
Note that we don’t provide utility classes for justified text. While
aesthetically, the justified text might look more appealing, it does make
word-spacing was more random and therefore harder to read.
I don't find any built-in class for this, further, you can check from here https://getbootstrap.com/docs/5.0/utilities/text/
我没有找到任何内置的类,而且,您可以从这里查看https://getbootstrap.com/docs/5.0/utilities/text/
Hence, you can use custom class with .custom-class { text-align: justify }
.
因此,您可以使用自定义类与.custom-class { text-align:justify }。
Thanks.
谢谢。
In Bootstrap 5, text-alignment
classes are part of Bootstrap utilities, which can be extended using Utilities API.
在Bootstrap 5中,文本对齐类是Bootstrap实用程序的一部分,可以使用实用程序API进行扩展。
By default, Bootstrap 5 generates the following classes: text-start
, text-center
, text-end
(their responsive classes are also available).
默认情况下,Bootstrap 5生成以下类:Text-Start、Text-Center、Text-End(也可以使用它们的响应类)。
We can generate the text-justify
class by adding an additional value to the text-align
utilities:
我们可以通过向文本对齐实用程序添加一个附加值来生成文本对齐类:
$utilities: map-merge(
$utilities,
(
"text-align": map-merge(
map-get($utilities, "text-align"),
(
values: map-merge(
map-get(map-get($utilities, "text-align"), "values"),
(justify: justify),
),
),
),
)
);
CSS Output:
Css输出:
.text-justify {
text-align: justify !important;
}
@media (min-width: 576px) {
.text-sm-justify {
text-align: justify !important;
}
}
// .text-md-justify ...
// .text-lg-justify ...
@media (min-width: 1200px) {
.text-xl-justify {
text-align: justify !important;
}
}
Full SCSS code:
完整的SCSS代码:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/variables-dark";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/root";
@import "bootstrap/scss/utilities";
// extend `text-align` utility
$utilities: map-merge(
$utilities,
(
"text-align": map-merge(
map-get($utilities, "text-align"),
(
values: map-merge(
map-get(map-get($utilities, "text-align"), "values"),
(justify: justify),
),
),
),
)
);
// include utilities API last to generate classes based on the Sass map in `_utilities.scss`
@import "bootstrap/scss/utilities/api";
DEMO:
https://stackblitz.com/edit/bootstrap-5-qjdfsx?file=src%2Fstyles.scss
演示:https://stackblitz.com/edit/bootstrap-5-qjdfsx?file=src%2Fstyles.scss
Further resources:
更多资源:
https://getbootstrap.com/docs/5.0/utilities/api/#using-the-api
https://getbootstrap.com/docs/5.0/utilities/api/#modify-utilities
Https://getbootstrap.com/docs/5.0/utilities/api/#using-the-api https://getbootstrap.com/docs/5.0/utilities/api/#modify-utilities
更多回答
我是一名优秀的程序员,十分优秀!