-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from xhuajin/ob-css-docs
Ob css docs
- Loading branch information
Showing
21 changed files
with
221 additions
and
16 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
10-Obsidian/Obsidian使用技巧/Huajin/如何给浅色模式和深色模式写不同的 css 样式.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
uid: 20240223201104 | ||
title: 如何给浅色模式和深色模式写不同的 css 样式 | ||
tags: [obsidian, css] | ||
description: | ||
author: Huajin | ||
type: other | ||
draft: false | ||
editable: false | ||
modified: | ||
--- | ||
|
||
# 如何给浅色模式和深色模式写不同的 css 样式 | ||
|
||
在 obsidian 中,我们可以写 css 文件为页面中的元素定制各种样式,那么如何分别给深色模式和浅色模式中设置不同的样式呢 | ||
|
||
<kbd>ctrl shift i</kbd> 打开开发者模式,在元素的最上方 body 中可以看到有一个类 `.theme-light` 或者 `.theme-dark`。当 obsidian 处于浅色模式下,body 存在前者,处于深色模式下时存在后者。我们可以借助这个区别来编写 css 分别给深色模式和浅色模式中设置不同的样式。 | ||
|
||
举个例子,写两个选择器分别选中深色和浅色模式,然后给他们添加同一个变量但是给不同的变量值。然后再选择器中使用这个变量,这样,当当前 body 处于浅色模式时,存在 `.theme-light` 类,变量值为 `#2222222`,深色模式同理。 | ||
|
||
```css | ||
body.theme-dark { | ||
a-color-variable: #FFFFFF; | ||
} | ||
|
||
body.theme-light { | ||
a-color-variable: #222222; | ||
} | ||
|
||
(选择器) { | ||
background-color: var(--a-color-variable); | ||
} | ||
``` | ||
|
||
当然,我们也可以直接写成: | ||
|
||
```css | ||
body.theme-dark ... { | ||
background-color: #FFFFFF; | ||
} | ||
|
||
body.theme-light ... { | ||
background-color: #222222; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
uid: 20240223182902 | ||
title: Obsidian 样式 - 固定标签页样式美化 | ||
tags: [obsidian, css, pin, 标签页] | ||
description: | ||
author: Huajin | ||
type: other | ||
draft: false | ||
editable: false | ||
modified: 20240223185802 | ||
--- | ||
|
||
# Obsidian 样式 - 固定标签页样式美化 | ||
|
||
右键标签栏的文件名,可以看到有个『Pin』的选项,选择后可以把页面定在标签栏中,通常我们会固定非常常用的页面,例如你的主页等。但是如果固定在那里,很长一条不那么美观,因此写了段 css 用于隐藏该标签页的文字和『Pin』的符号。 | ||
|
||
## 效果 | ||
|
||
使用前: | ||
|
||
 | ||
|
||
使用后 | ||
|
||
 | ||
|
||
## 源码 | ||
|
||
css 代码使用方法见 [[Obsidian的CSS代码片段]] | ||
|
||
**使用方法**: | ||
|
||
如果 pin 的是**特定页面**,可以用这段 css,然后把 ... 改为你 pin 的页面对应的 data-type 和 aria-label | ||
|
||
```css | ||
.workspace-tab-header-container-inner .workspace-tab-header[data-type='...'][aria-label="..."] .workspace-tab-header-inner-title, | ||
.workspace-tab-header-container-inner .workspace-tab-header[data-type='...'][aria-label="..."] .workspace-tab-header-status-container { | ||
display: none; | ||
} | ||
|
||
.workspace-tab-header-container-inner .workspace-tab-header[data-type='...'][aria-label="..."] { | ||
margin-left: 0 !important; | ||
width: 34px !important; | ||
padding: 0 0 2px; | ||
max-width: 34px; | ||
} | ||
``` | ||
|
||
这段 css 会同时把标题和 pin 的图标都隐藏了,适用于你 pin 的内容本身有 icon,例如 kanban 和 surfing 打开的页面会有个图标。 | ||
|
||
- 如果你 pin 的页面是无图标的页面,可以去掉第一行的 `.workspace-tab-header-container-inner .workspace-tab-header[data-type='...'][aria-label="..."] .workspace-tab-header-inner-title,` (包括逗号),这样就可以显示部分文本。 | ||
- 也可以去掉第一行逗号往后的 `, .workspace-tab-header-container-inner .workspace-tab-header[data-type='...'][aria-label="..."] .workspace-tab-header-status-container` 这样就可以显示 pin 的图标了。 | ||
|
||
那么如何查询 pin 的页面的 data-type 和 aria-label 呢? | ||
|
||
- 快捷键 <kbd>ctrl+shift+i</kbd> 打开开发者模式 | ||
- 点击弹出也页面左上角的有个箭头的按钮(鼠标悬浮在该按钮上时显示快捷键 <kbd>ctrl+shift+c</kbd> | ||
- 点击后鼠标移动到你 pin 的标签页上,单击一下 | ||
- 在显示的一大堆代码中,当前高亮的那一行或者他的父级中可以找到 | ||
|
||
 | ||
|
||
如果想要一次性修改所有你 pin 的 markdown 页面的样式,可以用这个 | ||
|
||
```css | ||
.workspace-tab-header-container-inner .workspace-tab-header:has(.mod-pinned) .workspace-tab-header-inner-title { | ||
display: none; | ||
} | ||
|
||
.workspace-tab-header-inner:has(.mod-pinned) { | ||
padding-left: 3px; | ||
} | ||
|
||
.workspace-tab-header-container-inner .workspace-tab-header:has(.mod-pinned) { | ||
margin-left: 0 !important; | ||
width: 34px !important; | ||
padding: 0 0 2px; | ||
max-width: 34px; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
uid: 20240223202321 | ||
title: Obsidian 样式 - 状态栏美化 | ||
tags: [obsidian, css, state-bar, 状态栏] | ||
description: | ||
author: Huajin | ||
type: other | ||
draft: false | ||
editable: false | ||
modified: 20240223203021 | ||
--- | ||
|
||
# Obsidian 样式 - 状态栏美化 | ||
|
||
- 给状态栏增加透明度,使得平常不显眼。 | ||
- 鼠标悬浮 (hover) 时透明度恢复 | ||
- 去除边框,hover 恢复 | ||
|
||
```css | ||
.status-bar { | ||
/* background-color: var(--background-primary); */ | ||
border-width: 0; | ||
opacity: .5; | ||
transition: all .2s linear; | ||
} | ||
|
||
.status-bar:hover { | ||
opacity: 1; | ||
border-width: var(--status-bar-border-width); | ||
} | ||
``` | ||
|
||
如果浅浅的背景色也不需要,可以把上面的注释的 `/* background-color: var(--background-primary); */` 给取消注释(去掉开头结尾的 `/* */` 即可) | ||
|
||
如何使用 css 请见 [[Obsidian的CSS代码片段]] |
42 changes: 42 additions & 0 deletions
42
10-Obsidian/Obsidian外观/CSS 片段/Obsidian样式-隐藏 markdown 标记(加粗、斜体、下划线).md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
uid: 20240223203608 | ||
title: Obsidian 样式 - 隐藏 markdown 标记(加粗、斜体、下划线) | ||
tags: [obsidian, css] | ||
description: 隐藏 markdown 标记(加粗、斜体、下划线),以防止编写时的文本跳动 | ||
author: Huajin | ||
type: other | ||
draft: false | ||
editable: false | ||
modified: 20240223204444 | ||
--- | ||
|
||
# Obsidian 样式 - 隐藏 markdown 标记(加粗、斜体、下划线) | ||
|
||
在码字时,给文本添加加粗或者斜体等 markdown 格式的时候,文本总会跳动一下。因此写了一段 css 用于隐藏 markdown 标记来去抖(隐藏标记)。 | ||
|
||
需要借助 style-setting 插件给该 css 添加快捷键,方便需要修改标记时关闭该 css。(因此需要安装 style setting 插件:[[obsidian-style-settings]],这个插件可以为你的主题增加很多样式修改功能) | ||
|
||
```css | ||
/* @settings | ||
name: 隐藏 markdown 标记(这里你可以自己取名) | ||
id: a-unique-id | ||
settings: | ||
- | ||
id: hide-markdown-marker | ||
title: Hide markdown marker | ||
title.zh: 隐藏 markdown 标记 | ||
description: Hide bold, italic, strikethrough, etc. markdown markers | ||
description.zh: 隐藏加粗、斜体、删除线等 markdown 标记 | ||
type: class-toggle | ||
default: false | ||
addCommand: true | ||
*/ | ||
.hide-markdown-marker .cm-line span:is(.cm-formatting, .cm-tag) { | ||
display: none; | ||
} | ||
``` | ||
|
||
添加好 css 后(如何添加 css 请见 [[Obsidian的CSS代码片段]]),在『设置 => 快捷键』中搜索 style-setting,找到 Style Settings: Toggle Hide markdown marker,设置一个快捷键即可。 | ||
|
||
这样,在你码字的时候就可以尽情使用快捷键(`ctrl b, ctrl i`)添加各种格式,同时文字不会抖动。需要修改格式时可以用你设置的快捷键关闭隐藏修改。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ modified: 20230101000000 | |
|
||
下面是 [[smart-title]] 插件的自述翻译 | ||
|
||
【机翻】 | ||
【机翻】 | ||
# 智能标题 | ||
|
||
这个插件可以自动从标题中提取标签和别名。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ Enable better task management via lists. | |
|
||
下面是 [[task-list]] 插件的自述翻译 | ||
|
||
|
||
|
||
# 任务列表 | ||
|
||
一个简单的黑曜石插件,通过列表实现更好的任务管理。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters