# Can you apply css to specific sections rather than the entire page

**URL:** <https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582>\
**Category:** Devs: Theme Design & Custom CSS\
**Tags:** custom-css\
**Created:** [January 24, 2024, 5:42am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582 "2024-01-24T05:42:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![the1gofer](https://forum.obsidian.md/user_avatar/forum.obsidian.md/the1gofer/32/36997_2.png) [@the1gofer](https://forum.obsidian.md/u/the1gofer)\
**Post date:** [January 24, 2024, 5:42am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/1 "2024-01-24T05:42:04Z")

</div>

I’m using the minimal theme, but I think this question should apply more broadly.

I know almost nothing about css, so maybe the answer is obvious, but can I apply the css helper classes that the theme applies to a specific section? or Dataview query?

---

<div class="post-metadata">

**Author:** ![ariehen](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ariehen/32/46932_2.png) [@ariehen](https://forum.obsidian.md/u/ariehen)\
**Post date:** [January 24, 2024, 7:40am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/2 "2024-01-24T07:40:51Z")

</div>

Which helper class(es)?

Images, for sure. You can use alt/attribute text, e.g. `![[snow.jpg|float-right-wide]]` to have certain images display differently depending on the alt text.

For tables you can, for example, have all Dataview tables in a note wide but Markdown tables stay _Readable Line Length_. I’m not sure if it’s possible to have one certain paragraph wide and the others not. Minimal is unique in its structure with how the helper classes and block widths work.

For arbitrary styling of things around the page [custom callouts](https://help.obsidian.md/Editing+and+formatting/Callouts#Customize+callouts) are a playground. They are fairly easy to make and use. Two popular snippets for layout around the page:

> **[Multi Column Callout](https://efemkay.github.io/obsidian-modular-css-layout/multi-column/02-multi-column-callout/)**
>
> Modular CSS Layout for Obsidian

> **[Callout Adjustments - SlRvb's Documentation - Obsidian Publish](https://publish.obsidian.md/slrvb-docs/ITS+Theme/Callout+Adjustments)**
>
> Callout Adjustments provides more flexibility and functionality to position, re-size, and apply styles to callouts in notes.

* * *

`@CawlinTeffid` asked a while ago on Discord:

> Could someone share a snippet for an “invisible” callout to use as a div for arbitrary styling?

And SailKite was kind enough to share a “starter” div callout:

```css
/* basic div-like callout as a platform for other styling */
.callout[data-callout="div"] {
    margin: unset;
    border: unset;
    border-radius: unset;
    padding: unset;
    background: unset;
    mix-blend-mode: normal;

    & > .callout-title { display: none; }
}

```

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [January 24, 2024, 9:12am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/3 "2024-01-24T09:12:01Z")

</div>

> [@ariehen](#):
>
> For arbitrary styling of things around the page …  
> …  
> `@CawlinTeffid` asked a while ago on Discord:
> 
> > Could someone share a snippet for an “invisible” callout to use as a div for arbitrary styling?
> 
> And SailKite was kind enough to share a “starter” div callout: …

Whilst playing around with some table formatting in [another post](http://forum.obsidian.md/t//74636) I found another nifty trick to target a smaller area which also can be used in this context. Mark the section by some random tag, i.e. #flag, and use CSS as shown below to hide the tag, and to format that section to your hearts content.

```css
a[href="#flag"] {
  display: none;
}

div:has(a[href="#flag"]) {
  ... whatever styling you like ...
}

```

This way the extra markup is minimal, and the visual impact is hidden in the rendered views, but it still allows you to do whatever you want with the marked section. In the linked thread above, I also show examples of how you can use this to first anchor the CSS to the table, and then continue to style smaller parts of the table afterwards. This trick also works for both _live preview_ and _reading mode_.

---

<div class="post-metadata">

**Author:** ![CawlinTeffid](https://forum.obsidian.md/user_avatar/forum.obsidian.md/cawlinteffid/32/82899_2.png) [@CawlinTeffid](https://forum.obsidian.md/u/CawlinTeffid)\
**Post date:** [January 24, 2024, 4:23pm UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/4 "2024-01-24T16:23:50Z")

</div>

Whoa, that deserves a Share & Showcase post!

---

<div class="post-metadata">

**Author:** ![the1gofer](https://forum.obsidian.md/user_avatar/forum.obsidian.md/the1gofer/32/36997_2.png) [@the1gofer](https://forum.obsidian.md/u/the1gofer)\
**Post date:** [January 26, 2024, 6:11am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/5 "2024-01-26T06:11:14Z")

</div>

Well I’m trying to do a couple of different things.

1. the minimal theme allows you to make cards out of dataview table queiries, which I like in a single colum for most things, but it might be nice to have the option to do different layouts besed on the query.

2. I’m also making various charts using dataveiwjs and chartsjs, but each chart takes up the entire width of the screen, and I would like to have a couple of them next to each other.

---

<div class="post-metadata">

**Author:** ![the1gofer](https://forum.obsidian.md/user_avatar/forum.obsidian.md/the1gofer/32/36997_2.png) [@the1gofer](https://forum.obsidian.md/u/the1gofer)\
**Post date:** [January 26, 2024, 4:50pm UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/6 "2024-01-26T16:50:55Z")

</div>

I can’t seem to get a dataviewjs query in a call out to work … so I’m not sure if this is going to be possible.

---

<div class="post-metadata">

**Author:** ![josephtribulat](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@josephtribulat](https://forum.obsidian.md/u/josephtribulat)\
**Post date:** [January 26, 2024, 9:36pm UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/7 "2024-01-26T21:36:59Z")

</div>

Wow, thank you! This is going to save me so much time.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [January 26, 2024, 9:44pm UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/8 "2024-01-26T21:44:27Z")

</div>

I’ve been thinking about it, but I did some tests yesterday, and something had changed it v seems, so it might not be as good as I thought it was… Need to investigate some more in this topic…

---

<div class="post-metadata">

**Author:** ![ariehen](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ariehen/32/46932_2.png) [@ariehen](https://forum.obsidian.md/u/ariehen)\
**Post date:** [January 27, 2024, 2:08am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/9 "2024-01-27T02:08:03Z")

</div>

> [@the1gofer](#):
>
> I can’t seem to get a dataviewjs query in a call out to work

I’m not a big dataviewjs user, but I fire this up every few months to check for dupe notes, and it works fine in a callout:

> <https://github.com/claremacrae/obsidian-experiments-plugin/issues/1>
>
> The wiki-style links depend on file-names being unique.
> 
> \- Perhaps when creati…ng new files, add a check and prevent duplicates.
> \- Or add a way to show duplicate file names (similar to Dangling Links plugin)

 ![Screenshot 2024-01-27 at 11.02.26](https://forum.obsidian.md/uploads/default/original/3X/6/f/6f788e6bdff2c8c3872717669434d9cb74186af4.png)

 ![Screenshot 2024-01-27 at 11.03.25](https://forum.obsidian.md/uploads/default/original/3X/5/9/59b9cee32ddfb72e10ca1831d187f838204dc170.png)

* * *

You could try selecting your entire dataviewjs code block and running the _Insert callout_ command (or even better, assign a hotkey). That should keep the formatting intact.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [January 27, 2024, 5:58pm UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/10 "2024-01-27T17:58:43Z")

</div>

In the post before when I suggested using #flag to mark an arbitrarily section I had done some testing using tables. It turns out that _live preview_ is slightly inconsistent, because inside of a table the #flag is rendered the same as in general in _reading mode_ and that is that it’s rendered as `<a href=“#flag” … >`. Outside of a table in plain text, it doesn’t keep this link format, but instead you need to target a `cm-tag-flag` class to get a similar selector.

I’m not sure if there are other cases to cover, but the example I gave need to be extended to at least:

```css
.cm-tag-flag, 
a[href="#flag"] {
  display: none;
}

div:has(.cm-tag-flag), 
div:has(a[href="#flag"]) {
  ... whatever styling you like ...
}

```

I’ve been thinking about doing a #Share & showcase post about this, but haven’t found the time and energy to do so, just yet. 😃

---

<div class="post-metadata">

**Author:** ![the1gofer](https://forum.obsidian.md/user_avatar/forum.obsidian.md/the1gofer/32/36997_2.png) [@the1gofer](https://forum.obsidian.md/u/the1gofer)\
**Post date:** [January 28, 2024, 3:34am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/11 "2024-01-28T03:34:06Z")

</div>

oh, that’s a good idea!

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [February 4, 2024, 3:34am UTC](https://forum.obsidian.md/t/can-you-apply-css-to-specific-sections-rather-than-the-entire-page/75582/12 "2024-02-04T03:34:58Z")

</div>

Closed on February 4, 2024, 3:34am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
