I have a bunch of Markdown files that I have added by indexing. They were saved from web pages with very large images near the top of the article, and I would like to shrink them so I can see more than the headline and photo when I preview them.
I created a custom stylesheet that contains a few tweaks, one of which is:
img {
max-width: 40% !important;
height: auto !important;
display: block;
}
But the images are still full-width. I tried adding !important to the rules, which did not help.
When I converted one of the files to HTML within Devonthink, I saw the reason: there is a large chunk of CSS injected at the top:
@layer DEVONthink {
which contains
figure {max-width: 100% !important; height: auto !important; }
img {max-width: 100% !important; height: auto !important; }
Only after that is my stylesheet included:
<link type="text/css" rel="stylesheet" href="file:///Users/mef/Library/Application%20Support/DEVONthink/StyleSheets/custom-markdown.css"/>
Given the rules of CSS precedence, the later mention (custom stylesheet) should override the earlier declarations in a <style> element (which are on the same level), and that when two rules conflict, the last one wins. Does the @layer change this precedence? It would be great for my stylesheet to prevail here…
Everything inside a layer has lower precedence than everything outside. In other words: DT’s style sheet is built so that user styles take precedence over it. Though I disagree with the use of !important – that’s always a red flag.
More to the point: you should convert your MD to HTML in DT. Then open that HTML in your favorite browser and take a look at the styles applied to your images. My guess is that your img elements are enclosed in figure elements. Or something else. We’re basically flying blind here since you show neither the generated HTML nor your CSS.
Just did this - max-width directly on an img (inside body > p) is being ignored even though the inspector shows that mine is the final computed value. Somehow, it is being overriden by width, which I thought was not supposed to happen. If I specify width !important directly, that works. Odd and annoying but I am out of time to investigate - this is livable. Thanks for confirming that I wasn’t crazy as far as what should be takiing precedence.
Can you provide the original URL that you saved? I’d like to have a look myself. Or, even better, send me the MD and css as a PM?
The issue here is that DT’s own stylesheet uses
img { max-width: 100% !important;}
The important directive makes the DT layered stylesheet override conflicting rules outside a layer, ie in particular those in a user stylesheet.
For details, see MDN: !important CSS keyword - CSS | MDN
This behavior is, IMO, counter-intuitive and goes against the whole idea of a @layer: It should encapsulate the app styles and allow users to override them easily.
@cgrunenberg: Perhaps this can be fixed in one of the upcoming maintenance releases? Stylesheets should never use !important, imo. And there’s no need to use it nowadays anyway, with a sensibly crafted @layer.
1 Like