244 lines
4.8 KiB
CSS
244 lines
4.8 KiB
CSS
/*
|
|
* 轻量级顶部通知样式
|
|
* 在页面顶部显示简洁的通知横条
|
|
*/
|
|
|
|
/* 通知容器 */
|
|
.toast-container {
|
|
position: fixed;
|
|
top: 20px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
z-index: 9999;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
width: 100%;
|
|
max-width: 800px; /* 增加最大宽度,但保持在移动设备上的响应式 */
|
|
padding: 0 20px;
|
|
box-sizing: border-box;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* 通知条样式 */
|
|
.toast {
|
|
background-color: #fff;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
padding: 12px 16px;
|
|
display: flex;
|
|
align-items: flex-start; /* 改为flex-start让图标和文本从顶部对齐,更好地支持多行文本 */
|
|
justify-content: space-between;
|
|
width: fit-content; /* 更好地适应内容宽度 */
|
|
min-width: 300px; /* 最小宽度 */
|
|
max-width: 100%; /* 相对于容器的最大宽度 */
|
|
animation: slideInDown 0.3s ease forwards;
|
|
overflow: hidden;
|
|
pointer-events: auto;
|
|
border-left: 4px solid #1890ff;
|
|
margin: 0 auto; /* 水平居中 */
|
|
transition: width 0.2s ease-out; /* 添加平滑的宽度过渡效果 */
|
|
}
|
|
|
|
/* 多行文本的Toast样式调整 */
|
|
.toast.toast-multiline {
|
|
padding-top: 14px;
|
|
padding-bottom: 14px;
|
|
}
|
|
|
|
.toast.closing {
|
|
animation: slideOutUp 0.3s ease forwards;
|
|
}
|
|
|
|
.toast-content {
|
|
display: flex;
|
|
/* align-items: flex-start; 改为flex-start让图标和文本从顶部对齐 */
|
|
align-items: center;
|
|
flex: 1;
|
|
min-width: 0; /* 确保flex子项不会溢出父容器 */
|
|
margin-right: 8px; /* 给关闭按钮留出空间 */
|
|
}
|
|
|
|
/* 图标容器 */
|
|
.toast-icon-wrapper {
|
|
margin-right: 12px;
|
|
flex-shrink: 0;
|
|
margin-top: 2px; /* 微调图标位置,与文本第一行更好地对齐 */
|
|
}
|
|
|
|
/* 通知图标 */
|
|
.toast-icon {
|
|
font-size: 20px;
|
|
height: 24px;
|
|
width: 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
/* 图标类型样式 */
|
|
.toast-icon.success {
|
|
color: #52c41a;
|
|
}
|
|
|
|
.toast-icon.error {
|
|
color: #f5222d;
|
|
}
|
|
|
|
.toast-icon.warning {
|
|
color: #faad14;
|
|
}
|
|
|
|
.toast-icon.info {
|
|
color: #1890ff;
|
|
}
|
|
|
|
/* 通知类型样式 */
|
|
.toast-success {
|
|
border-left-color: #52c41a;
|
|
}
|
|
|
|
.toast-error {
|
|
border-left-color: #f5222d;
|
|
}
|
|
|
|
.toast-warning {
|
|
border-left-color: #faad14;
|
|
}
|
|
|
|
.toast-info {
|
|
border-left-color: #1890ff;
|
|
}
|
|
|
|
/* 消息样式 */
|
|
.toast-message {
|
|
font-size: 14px;
|
|
line-height: 1.5;
|
|
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); /* 确保有足够空间给图标和关闭按钮 */
|
|
}
|
|
|
|
/* 关闭按钮 */
|
|
.toast-close {
|
|
width: 20px;
|
|
height: 20px;
|
|
border-radius: 50%;
|
|
border: none;
|
|
background-color: transparent;
|
|
color: #999;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
margin-left: 8px;
|
|
flex-shrink: 0;
|
|
padding: 0;
|
|
align-self: flex-start; /* 按钮始终位于顶部 */
|
|
margin-top: 2px; /* 微调按钮位置 */
|
|
}
|
|
|
|
.toast-close:hover {
|
|
background-color: rgba(0, 0, 0, 0.05);
|
|
color: #333;
|
|
}
|
|
|
|
.toast-close i {
|
|
font-size: 16px;
|
|
}
|
|
|
|
/* Toast焦点状态样式 */
|
|
.toast:focus {
|
|
outline: none;
|
|
box-shadow: 0 0 0 3px rgba(24, 144, 255, 0.2);
|
|
}
|
|
|
|
.toast-success:focus {
|
|
box-shadow: 0 0 0 3px rgba(82, 196, 26, 0.2);
|
|
}
|
|
|
|
.toast-error:focus {
|
|
box-shadow: 0 0 0 3px rgba(245, 34, 45, 0.2);
|
|
}
|
|
|
|
.toast-warning:focus {
|
|
box-shadow: 0 0 0 3px rgba(250, 173, 20, 0.2);
|
|
}
|
|
|
|
/* 动画关键帧 */
|
|
@keyframes slideInDown {
|
|
from {
|
|
transform: translateY(-20px);
|
|
opacity: 0;
|
|
}
|
|
to {
|
|
transform: translateY(0);
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
@keyframes slideOutUp {
|
|
from {
|
|
transform: translateY(0);
|
|
opacity: 1;
|
|
}
|
|
to {
|
|
transform: translateY(-20px);
|
|
opacity: 0;
|
|
}
|
|
}
|
|
|
|
/* 响应式样式 */
|
|
@media (max-width: 768px) {
|
|
.toast-container {
|
|
padding: 0 15px;
|
|
max-width: 90%;
|
|
}
|
|
|
|
.toast {
|
|
min-width: 250px;
|
|
width: auto; /* 在平板上自动调整宽度 */
|
|
}
|
|
}
|
|
|
|
@media (max-width: 480px) {
|
|
.toast-container {
|
|
top: 10px;
|
|
padding: 0 10px;
|
|
width: 100%;
|
|
max-width: 100%;
|
|
}
|
|
|
|
.toast {
|
|
padding: 10px 12px;
|
|
min-width: 0; /* 移动设备上取消最小宽度限制 */
|
|
width: 100%; /* 在移动设备上占满容器宽度 */
|
|
}
|
|
|
|
.toast-icon {
|
|
font-size: 16px;
|
|
height: 20px;
|
|
width: 20px;
|
|
}
|
|
|
|
.toast-message {
|
|
font-size: 13px;
|
|
max-width: calc(100% - 50px); /* 移动设备上调整最大宽度 */
|
|
}
|
|
|
|
.toast-close {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
|
|
.toast-close i {
|
|
font-size: 14px;
|
|
}
|
|
} |