Template:Mxt/User CSS for a monospaced coding font: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>SMcCandlish
(ce)
m (31 revisions imported)
 
(29 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>{{Wikipedia how-to}}</noinclude>
<noinclude>{{Wikipedia how-to}}</noinclude><includeonly><div style="float:right; padding:0 1em;">{{navbar|Mxt/User CSS for a monospaced coding font|plain=y}}</div></includeonly>
You can consistently use a monospaced font with well-designed characters for coding, e.g. to distinguish clearly between <code>l</code>, <code>1</code>, and <code>I</code>).
You can consistently use a monospaced font with well-designed characters for coding (e.g., to distinguish clearly between <code>l</code>, <code>1</code>, and <code>I</code>, and between <code>O</code> and <code>0</code>).


Add something like one of the code snippets below into your <samp>[[Special:MyPage/common.css]]</samp> page, replacing <kbd>"Roboto Mono"</kbd> with whatever your preferred coding font is (Roboto Mono was picked as a freely-available coding font [https://fonts.google.com/specimen/Roboto+Mono] for this example).
Add something like one of the code snippets below into your {{samp|[[Special:MyPage/common.css]]}} page, replacing {{kbd|"Roboto Mono"}} with whatever your preferred coding font is ([https://fonts.google.com/specimen/Roboto+Mono Roboto Mono] was picked as a freely-available coding font for this example).
 
If you don't want to manually add this code to your CSS page but would rather <code>@import</code> (transclude) it, see [[meta:User:SMcCandlish/codefont.css]] for quick instructions.


This code will do the following:
This code will do the following:
* Apply a consistent monospace font of your choice (and the fallback system-default <samp>monospace</samp>, should that font go missing or not have characters you need) to all the classes used by {{tlx|mxt}} and other monospaced templates in the {{tlx|xt}} family, plus all the normally monospaced HTML elements like {{tag|code|o}}, {{tag|pre|o}}, etc.
* Apply a consistent monospace font of your choice (and the fallback system-default {{samp|monospace}}, should that font go missing or not have characters you need) to all the normally monospaced HTML elements like {{tag|code|o}}, {{tag|pre|o}}, etc.
* Make the two most frequently encountered editing fields also use this font stack: the main editing window and the edit summary line.
* Do the same for the classes used by {{tlx|mxt}} and other monospaced templates in the {{tlx|xt}} family
* Do the same for additional site-wide classes (as identified so far, e.g. <code>.monospaced</code>) that output as monospace.
* Make the three most frequently encountered editing fields also use this font stack: the main editing window, the edit summary line, and the search entry box.


If you know of an additional class to add here, please update this page or mention it on the talk page.
If you know of an additional class to add here, please update this page or mention it on [[Template talk:Mxt/User CSS for a monospaced coding font|the talk page]].


<!--DO NOT ADD var TO THIS LIST! It must be able to inherit the font of surrounding text, because it is used outside code, as in "If <var>A</var> then <var>B</var>", and in math equations.-->
'''Horizontal style'''
'''Horizontal style'''
{{syntaxhighlight|lang=css|1=
{{syntaxhighlight|lang=css|1=
/* Use my font for code, when available, to save my eyes */
/* Use my font, when available, for code */
code, pre, samp, kbd, tt, .example-mono, .bad-example-mono, .neutral-example-mono, .deprecated-example-mono { font-family: "Roboto Mono", monospace !important; }
code, pre, samp, kbd, tt, .example-mono, .userlinks-username, .monospaced, .keyboard-key, .button, .plaincode { font-family: "Roboto Mono", monospace !important; }
/*  Make some of the editable stuff monospaced */
/*  Make some of the editable stuff monospaced */
#wpTextbox1, #wpSummary { font-family: "Roboto Mono", monospace !important; }
#wpTextbox1, #wpSummary, #searchInput, #searchText { font-family: "Roboto Mono", monospace !important; }
}}
}}


'''Vertical style'''
'''Vertical style'''
{{syntaxhighlight|lang=css|1=
{{syntaxhighlight|lang=css|1=
/* Use my font for code, when available, to save my eyes */
/* Use my font, when available, for code */
code,
code,
pre,
pre,
Line 27: Line 32:
tt,
tt,
.example-mono,
.example-mono,
.bad-example-mono,
.userlinks-username,
.neutral-example-mono,
.monospaced,
.deprecated-example-mono {
.keyboard-key,
.button
.plaincode {
   font-family: "Roboto Mono", monospace !important;
   font-family: "Roboto Mono", monospace !important;
}
}
/*  Make some of the editable stuff monospaced */
/*  Make some of the editable stuff monospaced */
#wpTextbox1,
#wpTextbox1,
#wpSummary {
#wpSummary,
#searchInput,
#searchText {
   font-family: "Roboto Mono", monospace !important;
   font-family: "Roboto Mono", monospace !important;
}
}
}}
}}


If you'd like to help clean up instances of the {{tag|tt}} element – which has not been valid HTML since the 1990s, and should usually be replaced with {{tag|code}}, though this may vary by context) – you can add something like the following to your <samp>common.css</samp> to make {{tag|tt|o}} stick out like a sore thumb:
{{anchor|Cleanup efforts}}'''Cleanup efforts'''
 
If you'd like to help clean up instances of the {{tag|{{!mxt|tt}}}} element – which has not been valid HTML since the 1990s, and should usually be replaced with {{tag|{{mxt|code}}}} (this may vary by context) – you can add something like the following to your {{samp|common.css}} to make {{tag|{{!mxt|tt}}|o}} stick out like a sore thumb:


{{syntaxhighlight|lang=css|1=
{{syntaxhighlight|lang=css|1=
Line 45: Line 56:
tt { color: DarkRed; background: Pink; }
tt { color: DarkRed; background: Pink; }
}}
}}
<noinclude>
 
{{Documentation|content=This is a documentation snippet page transcluded (without the banner or this doc section) into other template documentation for consistency. It takes no parameters.   
You can also do this with {{tag|font|o}}, {{tag|center|o}}, {{tag|strike|o}}, and other [[Wikipedia:HTML 5#Obsolete elements and attributes|deprecated elements]].  For CSS you can just import for this, see [[meta:User:SMcCandlish/lint.css]].<noinclude><!--
 
-->{{Documentation|content=This is a documentation snippet page transcluded (without the banner or this doc section) into other template documentation for consistency. It takes no parameters.   


Typical usage:
Typical usage:
Line 56: Line 69:
</nowiki></pre>
</nowiki></pre>


It can also used as a stand-alone how-to page; a redirect to it, [[Help:User CSS for a monospaced coding font]], is categorized as such.
It can also be used as a stand-alone how-to page; a redirect to it, [[Help:User CSS for a monospaced coding font]], is categorized as such. It is also transcluded as a section, at [[Help:User style#User CSS for a monospaced coding font]].
 
[[Category:Template documentation]]
[[Category:Template documentation]]
<!--End documentation.-->}}</noinclude>
<!--End documentation.-->}}</noinclude>

Latest revision as of 14:13, 3 September 2020

You can consistently use a monospaced font with well-designed characters for coding (e.g., to distinguish clearly between l, 1, and I, and between O and 0).

Add something like one of the code snippets below into your Special:MyPage/common.css page, replacing "Roboto Mono" with whatever your preferred coding font is (Roboto Mono was picked as a freely-available coding font for this example).

If you don't want to manually add this code to your CSS page but would rather @import (transclude) it, see meta:User:SMcCandlish/codefont.css for quick instructions.

This code will do the following:

  • Apply a consistent monospace font of your choice (and the fallback system-default monospace, should that font go missing or not have characters you need) to all the normally monospaced HTML elements like <code>, <pre>, etc.
  • Do the same for the classes used by {{mxt}} and other monospaced templates in the {{xt}} family
  • Do the same for additional site-wide classes (as identified so far, e.g. .monospaced) that output as monospace.
  • Make the three most frequently encountered editing fields also use this font stack: the main editing window, the edit summary line, and the search entry box.

If you know of an additional class to add here, please update this page or mention it on the talk page.

Horizontal style <syntaxhighlight lang="css">/* Use my font, when available, for code */ code, pre, samp, kbd, tt, .example-mono, .userlinks-username, .monospaced, .keyboard-key, .button, .plaincode { font-family: "Roboto Mono", monospace !important; } /* Make some of the editable stuff monospaced */

  1. wpTextbox1, #wpSummary, #searchInput, #searchText { font-family: "Roboto Mono", monospace !important; }</syntaxhighlight>

Vertical style <syntaxhighlight lang="css">/* Use my font, when available, for code */ code, pre, samp, kbd, tt, .example-mono, .userlinks-username, .monospaced, .keyboard-key, .button .plaincode {

 font-family: "Roboto Mono", monospace !important;

} /* Make some of the editable stuff monospaced */

  1. wpTextbox1,
  2. wpSummary,
  3. searchInput,
  4. searchText {
 font-family: "Roboto Mono", monospace !important;

}</syntaxhighlight>

Cleanup efforts

If you'd like to help clean up instances of the <tt>...</tt> element – which has not been valid HTML since the 1990s, and should usually be replaced with <code>...</code> (this may vary by context) – you can add something like the following to your common.css to make <tt> stick out like a sore thumb:

<syntaxhighlight lang="css">/* Flag bad code for cleanup */ tt { color: DarkRed; background: Pink; }</syntaxhighlight>

You can also do this with <font>, <center>, <strike>, and other deprecated elements. For CSS you can just import for this, see meta:User:SMcCandlish/lint.css.