Jump to content

Handbuch:CSS

From mediawiki.org
This page is a translated version of the page Manual:CSS and the translation is 18% complete.
Outdated translations are marked like this.
"CSS" wird hierher geleitet. Für die Erweiterung siehe $1

Cascading Style Sheet (CSS) Regeln setzen auf dem Look and Feel von MediaWiki auf: Schriftgrösse, Farbe, Abstände, das Logo, Hintergrundbild bzw. Seiteninhalte werden angezeigt oder versteckt.

Um das Look and Feel von MediaWiki's Bildschirmdarstellung (wie es im Browser aussieht) kann man CSS in MediaWiki:Common.css setzen. Diese Datei ist eine Seite in Deinem Wiki und keine Datei wie in index.php oder load.php, sodass man sie nicht in der Verzeichnisstruktur auf Deinem Server findet, weder ist sie initial zu Deiner Hauptsteite oder jeder anderen Seite verlinkt. Die Seite besteht initial nur aus einem Einzeilen-Kommentar. Um es zu finden, schreibe MediaWiki:Common.css in die Suchzeile auf der Hauptseite deines Wiki. Es erscheint als Datei mit der Adresse, ähnlich wie https://www.myserver.org/mywiki/index.php?title=MediaWiki:Common.css. (Benötigt die folgenden Änderungsrechte: "interface administrator")

If code added to MediaWiki:Common.css doesn't take effect immediately, you may have to do a hard refresh.

To change the way MediaWiki pages print, you put CSS into MediaWiki:Print.css on your wiki.

CSS can be used to change the style of the entire wiki, for example to make the background a different color, or you can use inline CSS to style specific pieces of text in your wiki. For example green text can be accomplished by doing <span style="color:green">green text</span>. If you want to make all text on the wiki larger you can add the code body { font-size: larger; } to MediaWiki:Common.css. For mobile version use MediaWiki:Mobile.css.

If $wgAllowUserCss is enabled on your wiki, individual users can create custom stylesheets just for themselves at Special:MyPage/<skin_name>.css (for example Special:MyPage/vector.css if they are using the vector skin). Special:MyPage/common.css allows the creation of personal stylesheets for all skins.

You can also create custom skins for MediaWiki.

Hilfe

CSS syntax, attributes and values, must be correct or stuff won't work right. World Wide Web Consortium (W3C) is an excellent reference for checking how to write CSS correctly directly from the standards:

Wikipedia gives a good overview of CSS.

If you prefer an easily consumable reference alongside demos of CSS features, MDN CSS Reference will provide you an "up-to-date" guide to syntax and basic usage of the various elements.

Caveats

Be sure to keep your HTML markup semantic. Relying on styling to indicate meaning is a bad practice (e.g. for machine readability such as by search engines, screen readers using text-to-speech, and text browsers).

If necessary, custom style sheets can temporarily be deactivated using the safemode=1 URL parameter.

Normalized CSS

Much CSS today relies on a "reset" or "normalize" CSS to make all browsers work the same. MediaWiki does not have a reset per se, though there are built-in stylesheets such as common/commonElements.css, common/commonContent.css, common/commonInterface.css, and MediaWiki:Common.css.

If you copy CSS, watch if it depends on additional CSS.

For example, jsFiddle has a checkbox for "Normalized CSS". This sets margins to 0 and resets the numbers on ordered lists. Since none of this normalization CSS is running on MediaWiki sites, you should not use it when testing MediaWiki-related code.

jsfiddle has a feature to import CSS. If you're testing against the Vector skin on English Wikipedia, the primary sheets should be (in this order):

You can adjust the domain in the URL for other WMF wikis. By importing these, you can get a better idea how your CSS interacts with the CSS on WMF wikis.

Styles not working on Special:UserLogin or Special:Preferences?

By default, site CSS customizations (e.g. MediaWiki:Common.css) do not take effect on the login and preferences pages. This is to preserve the security of the login process, and to allow users to remove any unwanted customizations without being interfered with. If you are not concerned about the security risks, you can use the $wgAllowSiteCSSOnRestrictedPages configuration setting to allow custom CSS to work on these pages.

Using the url() function

For privacy reasons, Wikimedia sites are configured to reject loading resources from external servers using the url() CSS function. This includes resources encoded in data URLs.

However, you can load resources that are hosted in the Wikimedia servers. For example, you can load an image from Wikimedia Commons and use it as a background image via CSS:

.my-class {
	background: url("https://upload.wikimedia.org/wikipedia/commons/1/1a/some_image.svg");
}

You can also use a custom font family provided by Wikimedia's Universal Language Selector extension (see the list of fonts available on Wikimedia wikis).

Example CSS to load the Gochi Hand font:

@font-face {
  font-family: 'GochiHand';
  src: local("Gochi Hand"),
       url(https://xyz.wikipedia.org/w/extensions/UniversalLanguageSelector/data/fontrepo/fonts/GochiHand/GochiHand-Regular.woff2);
}

If you wish to use custom fonts, they need to be installed locally on your system.

Siehe auch