链接样式区分与美化
Obsidian 默认的链接样式不够直观,内部链接、外部链接和未创建链接难以区分。通过 CSS 可以让不同类型的链接呈现不同样式。
链接类型区分
css
/* 内部链接 - 紫色 */
.internal-link,
.cm-link {
color: #7c3aed !important;
text-decoration: none;
border-bottom: 1px dashed transparent;
transition: all 0.2s;
}
.internal-link:hover {
border-bottom-color: #7c3aed;
background: rgba(124, 58, 237, 0.05);
}
/* 外部链接 - 蓝色 + 外部图标 */
.external-link {
color: #2563eb !important;
text-decoration: none;
}
.external-link::after {
content: ' ↗';
font-size: 0.8em;
opacity: 0.6;
}
.external-link:hover {
color: #1d4ed8 !important;
text-decoration: underline;
}
/* 未创建链接 - 灰色虚线 */
.is-unresolved,
.cm-hmd-internal-link .is-unresolved {
color: #9ca3af !important;
text-decoration: underline wavy;
text-decoration-color: #9ca3af55;
opacity: 0.7;
}悬停动画
下划线动画
css
/* 链接下划线滑入动画 */
a.internal-link {
position: relative;
text-decoration: none;
}
a.internal-link::after {
content: '';
position: absolute;
bottom: -2px;
left: 0;
width: 0;
height: 2px;
background: var(--interactive-accent);
transition: width 0.3s ease;
}
a.internal-link:hover::after {
width: 100%;
}背景高亮
css
/* 悬停背景高亮 */
.internal-link {
border-radius: 3px;
padding: 0 2px;
transition: all 0.2s ease;
}
.internal-link:hover {
background: rgba(124, 58, 237, 0.1);
border-radius: 3px;
}链接卡片化
css
/* 外部链接卡片样式 */
a.external-link {
display: inline-flex;
align-items: center;
background: linear-gradient(135deg, #667eea, #764ba2);
color: white !important;
padding: 2px 10px;
border-radius: 6px;
text-decoration: none;
font-size: 0.9em;
transition: transform 0.2s, box-shadow 0.2s;
}
a.external-link:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}链接预览样式
css
/* 链接预览弹窗美化 */
.popover.hover-popover {
border-radius: 8px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
border: 1px solid var(--background-modifier-border);
max-width: 400px;
max-height: 300px;
}
/* 预览内容 */
.popover.hover-popover .markdown-preview-view {
padding: 12px 16px;
font-size: 0.9em;
}相关内容
- Callout 美化 — Callout 标注框样式
- CSS 片段速查表 — 选择器速查