Difference between revisions of "Help:TestImageWidth"
Jump to navigation
Jump to search
(Created page with "== Responsive 100% width using Template:ResponsiveImage == {{ResponsiveImage| File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png }} == Try using inline div == <div s...") |
|||
| Line 1: | Line 1: | ||
| − | = | + | From https://www.mediawiki.org/wiki/Topic:Tuubagqalz9vk2m9 I learned about making a css class to style responsive images |
| − | + | ||
| + | [https://www.mediawiki.org/wiki/User:AhmadF.Cheema AhmadF.Cheema] commented that using an inline div doesn't work: | ||
| + | |||
| + | <pre> | ||
| + | <div style="max-width:100%; height:auto;"> | ||
[[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | [[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | ||
| − | + | </div> | |
| + | </pre> | ||
| + | gives this: | ||
| − | |||
<div style="max-width:100%; height:auto;"> | <div style="max-width:100%; height:auto;"> | ||
[[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | [[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | ||
</div> | </div> | ||
| + | |||
| + | They talk about modifying your Wiki's MediaWiki:Common.css page but I learned that that isn't a good idea and I should use TemplateStyle instead, so I created <code>Template:ResponsiveImage</code> thus: | ||
| + | <pre> | ||
| + | <templatestyles src="ResponsiveImage/style.css" /> | ||
| + | <div class="responsive-image"> | ||
| + | {{{1}}} | ||
| + | </div> | ||
| + | </pre> | ||
| + | and <code>Template:ResponsiveImage/style.css</code> thus: | ||
| + | <pre> | ||
| + | /* To make images responsive */ | ||
| + | .responsive-image img { | ||
| + | max-width:100%; | ||
| + | height:auto; | ||
| + | } | ||
| + | </pre> | ||
| + | |||
| + | With that I can do this: | ||
| + | <pre> | ||
| + | {{ResponsiveImage| | ||
| + | [[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | ||
| + | }} | ||
| + | </pre> | ||
| + | and it gives me this: | ||
| + | {{ResponsiveImage| | ||
| + | [[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] | ||
| + | }} | ||
Revision as of 09:05, 7 April 2021
From https://www.mediawiki.org/wiki/Topic:Tuubagqalz9vk2m9 I learned about making a css class to style responsive images
AhmadF.Cheema commented that using an inline div doesn't work:
<div style="max-width:100%; height:auto;"> [[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]] </div>
gives this:
They talk about modifying your Wiki's MediaWiki:Common.css page but I learned that that isn't a good idea and I should use TemplateStyle instead, so I created Template:ResponsiveImage thus:
<templatestyles src="ResponsiveImage/style.css" />
<div class="responsive-image">
{{{1}}}
</div>
and Template:ResponsiveImage/style.css thus:
/* To make images responsive */
.responsive-image img {
max-width:100%;
height:auto;
}
With that I can do this:
{{ResponsiveImage|
[[File:Warming stripes GLOBAL 1850-2019 nolabels 600h.png]]
}}
and it gives me this:
