修复提示框文字换行问题

This commit is contained in:
2025-04-26 18:43:22 +08:00
parent 6c40c4d074
commit 9a22e9092f
5 changed files with 129 additions and 91 deletions
+53 -28
View File
@@ -27,17 +27,17 @@
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
padding: 12px 16px;
display: flex;
align-items: flex-start; /* 改为flex-start让图标和文本从顶部对齐,更好地支持多行文本 */
align-items: flex-start;
justify-content: space-between;
width: fit-content; /* 更好地适应内容宽度 */
min-width: 300px; /* 最小宽度 */
max-width: 100%; /* 相对于容器的最大宽度 */
width: max-content;
min-width: 300px;
max-width: 450px;
animation: slideInDown 0.3s ease forwards;
overflow: hidden;
overflow: visible;
pointer-events: auto;
border-left: 4px solid #1890ff;
margin: 0 auto; /* 水平居中 */
transition: width 0.2s ease-out; /* 添加平滑的宽度过渡效果 */
margin: 0 auto;
box-sizing: border-box;
}
/* 多行文本的Toast样式调整 */
@@ -52,25 +52,25 @@
.toast-content {
display: flex;
/* align-items: flex-start; 改为flex-start让图标和文本从顶部对齐 */
align-items: center;
align-items: flex-start;
flex: 1;
min-width: 0; /* 确保flex子项不会溢出父容器 */
margin-right: 8px; /* 给关闭按钮留出空间 */
min-width: 0;
margin-right: 8px;
}
/* 图标容器 */
.toast-icon-wrapper {
margin-right: 12px;
flex-shrink: 0;
margin-top: 2px; /* 微调图标位置,与文本第一行更好地对齐 */
margin-top: 2px;
width: 24px;
}
/* 通知图标 */
.toast-icon {
font-size: 20px;
height: 24px;
width: 24px;
height: 20px;
width: 20px;
display: flex;
align-items: center;
justify-content: center;
@@ -113,16 +113,39 @@
/* 消息样式 */
.toast-message {
font-size: 14px;
line-height: 1.5;
line-height: 1.6;
color: #333;
word-break: break-word; /* 允许在任何字符处换行 */
word-wrap: break-word; /* 长词自动换行 */
white-space: pre-wrap; /* 保留空格和换行,但允许文本换行 */
overflow-wrap: break-word; /* 确保长单词也能换行 */
flex: 1;
min-width: 0; /* 确保flex子项不会溢出父容器 */
max-height: none; /* 移除最大高度限制,让内容自然增长 */
max-width: calc(100% - 60px); /* 确保有足够空间给图标和关闭按钮 */
min-width: 0;
text-align: left;
padding: 1px 0;
/* 简化文本样式 */
white-space: normal;
}
/* 消息行样式 */
.toast-message-line {
display: block;
margin-bottom: 3px;
}
.toast-message-line:last-child {
margin-bottom: 0;
}
/* 对于中文文本特别处理 */
:lang(zh) .toast-message,
:lang(zh-CN) .toast-message,
:lang(zh-TW) .toast-message {
/* 中文特殊处理 */
text-indent: 0; /* 确保没有首行缩进 */
text-align-last: left; /* 确保最后一行也左对齐 */
}
/* 对于英文文本,特别处理 */
.toast-message:lang(en) {
word-break: normal;
}
/* 关闭按钮 */
@@ -141,8 +164,8 @@
margin-left: 8px;
flex-shrink: 0;
padding: 0;
align-self: flex-start; /* 按钮始终位于顶部 */
margin-top: 2px; /* 微调按钮位置 */
align-self: flex-start;
margin-top: 2px;
}
.toast-close:hover {
@@ -204,7 +227,8 @@
.toast {
min-width: 250px;
width: auto; /* 在平板上自动调整宽度 */
max-width: 400px;
width: auto;
}
}
@@ -218,8 +242,9 @@
.toast {
padding: 10px 12px;
min-width: 0; /* 移动设备上取消最小宽度限制 */
width: 100%; /* 在移动设备上占满容器宽度 */
min-width: 0;
max-width: 330px;
width: calc(100% - 20px);
}
.toast-icon {
@@ -230,7 +255,7 @@
.toast-message {
font-size: 13px;
max-width: calc(100% - 50px); /* 移动设备上调整最大宽度 */
max-width: calc(100% - 50px);
}
.toast-close {