TL;DR
- Here’s a CSS snippet to add a floating action button (FAB) to your mobile UI.
- Copy and save snippet in code block below. Refer to CSS snippets - Obsidian Help for how to do so.
- Adjust the parameters inside
body.is-mobile .view-action
accordingly. Save.
I first started using FAB when I discovered Obsidian You theme for Obsidian (the theme’s name already imply the app’s). As I have a setup that syncs my vault to my phone for reference, review and quick edit, FAB is a finger-stretching saver. Over time, I adopted it into my theme and significantly modified the CSS – using Obsidian’s pre-defined variables, added hover property and adjust z-index and so on.
Here’s a trimmed down version of the CSS that applies only for Editing/Reading button (my other modification introduce a second FAB that you would use together with Commander plugin). Anyway, if you want to have FAB for Editing/Reading button in your Obsidian setup, simply load the following snippet and adjust the variables declaration inside body.is-mobile .view-action
to suit your preferences.
This FAB applies to mobile only and since .is-mobile
covers both tablet (>600px width) and phone, the button is also there if you use tablet/iPad. If you want strictly on phone only, swap the .is-mobile
to .is-phone
.
P/s: I did quick test on community theme compatibility but only for select few (i.e. Minimal, AnuPpuccin, Border, ITS Theme, Prism, and Shimmering Focus)
/* === Floating Action Button FAB === */
/* FAB option allow to select which Page Header button to be used for FAB 2nd button */
/* declare variables to be used for easy customisation
other than these variables, other variables are obsidian's pre-defined */
body.is-mobile .view-action {
--lst-fab-view-y: 10vh; /* set to 0 for flushed bottom position */
--lst-fab-view-x: 2vw; /* set to 0 for flushed right position */
--lst-fab-button-size: 60px; /* set button box size */
--lst-fab-button-radius: calc(var(--lst-fab-button-size) / 3); /* divide 3 for square circle, divide 2 for circle */
--lst-fab-toolbar-y-adj: 80px;
}
/* make the button "floating" and define customisation */
body.is-mobile div.view-actions > .view-action[aria-label^="Current view"] {
position: absolute;
top: calc(88vh - var(--lst-fab-view-y));
right: calc(0vw + var(--lst-fab-view-x));
width: var(--lst-fab-button-size);
aspect-ratio: 1;
transform: translate(-40%, 5%);
border-radius: var(--lst-fab-button-radius);
background-color: var(--background-secondary);
box-shadow: 0px 0px var(--size-4-2) rgba(0,0,0,0.3);
}
body.is-mobile.mod-toolbar-open div.view-actions > .view-action[aria-label^="Current view"] {
top: calc(88vh - var(--lst-fab-view-y) - var(--lst-fab-toolbar-y-adj));
}
/* make sure FAB is higher than backlinks control */
body.is-mobile .view-header {
z-index: 30;
}
/* change background-color when hover */
body.is-mobile div.view-actions > .view-action.clickable-icon:hover {
background-color: var(--background-accent);
}
update 27June2023 – added variable (i.e.
--lst-fab-toolbar-y-adj
) to adjust vertical position when mobile toolbar appear on the screen. this is to avoid FAB become hidden behind it partially. adjust accordingly, the 80px is to compensate for two rows of mobile toolbar.