<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.a {
display: flex;
width: 400px;
height: 200px;
background-color: skyblue;
}
.b {
flex: 1;
width: 0;
}
.txt {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
</style>
</head>
<body>
<div class="a">
<div class="b">
<div class="txt">111111111111111111111111111111111111111111111111</div>
</div>
</div>
</body>
</html>
这段HTML代码展示了如何利用Flex布局和CSS样式实现文本溢出时的截断效果。在一个宽度为400px、高度为200px的蓝色背景容器中,通过设置`.b`类的`flex: 1`和`.txt`类的`text-overflow: ellipsis`、`white-space: nowrap`及`overflow: hidden`属性,实现了当文本内容过长时,以省略号显示。
474

被折叠的 条评论
为什么被折叠?



