gpt4 book ai didi

css - 空白 : nowrap; and flexbox did not work in chrome

转载 作者:技术小花猫 更新时间:2023-10-29 10:21:36 25 4
gpt4 key购买 nike

Chrome 的最新更新打破了 white-space: nowrapoverflow: hidden 元素上使用 text-overflow: ellipsis;。如何在不在 name 类上添加硬编码宽度的情况下解决这个问题..

<h1>problem</h1>
<div class="container">
<div class="name">
<div class="firstname">
test
</div>
<div class="lastname">
as kjldashdk ja asdjhk ashdjk ashdjk asdjasdkajsdh akjsd asd asd asd asd asd asd as das da asdas dasd asda sdasd as dasd asd asd as dasd a
</div>
</div>
<div class="side">
options
</div>
</div>

结构不应该改变,因为我在我的应用程序的其他地方重用了 .name 部分。

.container {
width: 800px;
height: 80px;
display: flex;
border: solid 1px black;
margin: 10px;
}
.name {
display: flex;
}
.firstname {
width: 100px;
background-color: grey;
}
.lastname {
flex-grow: 1;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.side {
flex-grow: 0;
}
.side, .firstname, .lastname {
align-self: center;
padding: 0 20px;
}

http://codepen.io/anon/pen/xZpMYg

最佳答案

引用 - https://drafts.csswg.org/css-flexbox-1/#min-size-auto

The initial setting on flex items is min-width: auto. So, in order for each item to stay within the container, we need to give min-width: 0.

添加 min-width: 0;。这是针对您的情况的简单解决方法。

也就是

name {
display: flex;
min-width: 0;
}

片段

.container {
width: 800px;
height: 80px;
display: flex;
border: solid 1px black;
margin: 10px;
}
.name {
display: flex;
min-width: 0;
}
.firstname {
width: 100px;
background-color: grey;
}
.lastname {
flex-grow: 1;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
display: flex;
}
.side {
flex-grow: 0;
}
.side, .firstname, .lastname {
align-self: center;
padding: 0 20px;
}
<h1>problem</h1>
<div class="container">
<div class="name">
<div class="firstname">
test
</div>
<div class="lastname">
as kjldashdk ja asdjhk ashdjk ashdjk asdjasdkajsdh akjsd asd asd asd asd asd asd as das da asdas dasd asda sdasd as dasd asd asd as dasd a
</div>
</div>
<div class="side">
options
</div>
</div>

<h1>expected result</h1>

<div class="container">
<div class="name">
<div class="firstname">
test
</div>
<div class="lastname">
as kjldashdk ja asdjhk ashdjk ashdjk asdjasdkajsdh akjsd asd asd asd asd sa dad...
</div>
</div>
<div class="side">
options
</div>
</div>

关于css - 空白 : nowrap; and flexbox did not work in chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34934586/

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