Add border to image

Hello all

Can I add a thin border to a JPG image without resorting to a theme component? I want to keep this simple and avoid, for instance, this component:

I have tried every variation of the img tag that I can think of. The only thing that worked was to embed the image in a kbd tag, but that is a bit odd. This is really what I want to write:

<img src="upload://jIMXtLgb7enbLUiahXVT1Jz14n4.jpeg"
  alt="photo showing derelict medium voltage power pole"
  width="75%" 
  style="border: 1px solid gray">

And here is a sample image via standard upload:

The AI image captioning does a pretty good job, I must say. TIA!

2 Likes

Here is the earlier HTML copy/pasted in .. no border evident .. and kinda small too:

.cooked img:not(.thumbnail,.ytp-thumbnail-image,.emoji), .d-editor-preview img:not(.thumbnail,.ytp-thumbnail-image,.emoji) {
    border: 4px solid red;
}

devtools hacked CSS … YMMV :rofl:

1 Like

custom CSS gets stripped out of posts because someone could do something like border: 1000px solid gray and make the whole topic unreadable

You need to add some CSS to a theme or a theme component to do this, no great way around it. You can make it optional on an image-by-image basis though.

So for example, you can add this CSS to a theme:

div[data-theme-image-border] img {
  border: 1px solid gray;
}

and then use it in a post like this:

<div data-theme-image-border>
  <img src="yoururlhere"/>
</div>

5 Likes

Many thanks. Some follow‑up.

@merefield: your example worked when added as follows:

☰ ▸ Admin ▸ Customize ▸ Themes = Default ▸ Edit CSS/HTML ▸ Desktop ▸ CSS

@awesomerobot: I could not get your code to work, despite trying some variations.

Note that first example is site‑wide and the second example is (or rather should be) per‑image.

Any further suggestion welcome. The site‑wide solution is acceptable but a per‑image application is probably preferable.

PS: the AI captioning is deteriorating with every iteration :smiley:

This Theme component maybe of interest

@Heliosurge Tx. I had noted that component in my OP. But I will give it a try today too.