gpt4 book ai didi

css - 如何在使用 flexbox 时在句子中间添加

转载 作者:行者123 更新时间:2023-11-28 11:01:44 26 4
gpt4 key购买 nike

给定一个包含句子的 flex 容器,我想用 <span> 包裹其中一个单词一些额外的造型。示例:

div {
display: flex;
border: 1px solid black;
width: 190px;
flex-wrap: wrap;
}

span {
color: red;
}
<div>
This is <span>not</span> a very long sentence.
</div>

enter image description here

如您所见,句子在 <span> 之后中断.

期望的结果是:

enter image description here

div {
display: flex;
border: 1px solid black;
width: 190px;
flex-wrap: wrap;
white-space: pre;
}

.red {
color: red;
}
<div>
<span>This </span>
<span>is </span>
<span class="red">not </span>
<span>a </span>
<span>very </span>
<span>long </span>
<span>sentence.</span>
</div>

你会如何解决这个问题?

最佳答案

试试 display: inline-block;

div {
display: inline-block;
border: 1px solid black;
width: 190px;
flex-wrap: wrap;
}

span {
color: red;
}
<div>
This is <span>not</span> a very long sentence.
</div>

关于css - 如何在使用 flexbox 时在句子中间添加 <span>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49124148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com