Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scale an image's width to a percentage of the window with MediaWiki?

With html I can scale an image's width to a percentage of the available window like this:

<img src=whatever.png width=50% />

With mediawiki this seems to be impossible (if you do not allow html injections). Is it really? Don't tell me I have to write a mediawiki extension ;)

Note the CSS answer from Is there a way automatically to resize MediaWiki images depending on screen size? is not a solution. I want to have different images in one page with different percentages.

like image 859
Thorsten Staerk Avatar asked Sep 29 '22 00:09

Thorsten Staerk


1 Answers

It should be possible to apply the CSS solution to specific images by tagging them with a custom class name. That is, you'd add something like the following to your MediaWiki:Common.css page:

img.halfwidth {
    width: 50%;
    height: auto;
}

and then use wiki markup like this:

[[File:Myimage.jpg|class=halfwidth]]

(Note that specifying a class name on an image like this requires MediaWiki 1.20+. If, for some reason, you need to do this on an older MediaWiki version, you can instead change the CSS selector to e.g. .halfwidth img, and the wiki syntax to <div class="halfwidth">[[File:Myimage.png]]</div>.)

like image 151
Ilmari Karonen Avatar answered Oct 13 '22 01:10

Ilmari Karonen