@@ -386,9 +386,6 @@ each can have the following fields:
386
386
switcher.
387
387
- ``name ``: an optional name to display in the switcher dropdown instead of the
388
388
version string (e.g., "latest", "stable", "dev", etc).
389
- - ``extra_classes ``: an optional list of classes to add to the switcher
390
- button for a given version (e.g., ``["dev", "rc"] ``). These classes are only
391
- added when the version is active.
392
389
- ``url ``: an optional URL. If provided, it links the version to ``url ``
393
390
instead of ``switcher['url_template'] ``.
394
391
@@ -403,7 +400,6 @@ Here is an example JSON file:
403
400
},
404
401
{
405
402
"version" : " 2.1rc1" ,
406
- "extra_classes" : [" dev" , " rc" ]
407
403
},
408
404
{
409
405
"version" : " 2.0"
@@ -542,6 +538,57 @@ to insert a version switcher at the top of the left sidebar, while still
542
538
keeping the default navigation below it. See :doc: `sections ` for more
543
539
information.
544
540
541
+ Style the switcher buttons
542
+ --------------------------
543
+
544
+ You may apply styles via CSS to any of the switcher buttons to control their look and feel.
545
+ Each button has two `HTML dataset entries <https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset >`_
546
+ that you can use to apply CSS rules to subsets of buttons. These entries are:
547
+
548
+ .. code-block ::
549
+
550
+ data-version
551
+ data-version-name
552
+
553
+ For example, the link for an entry with ``version="0.2" ``,
554
+ and ``name="My version" `` would have metadata like so:
555
+
556
+ .. code-block :: html
557
+
558
+ <a data-version-name =" My version" data-version =" 0.2" class =" <classes...>" >
559
+
560
+ You can create CSS rules that select this metadata like so:
561
+
562
+ .. code-block :: scss
563
+
564
+ // Style all links with a specific subset of versions
565
+ #version_switcher a[data-version="0.2"],
566
+ #version_switcher a[data-version="0.3"] {
567
+ background-color: red;
568
+ }
569
+ // Style all links with `stable` in the version name
570
+ #version_switcher a[data-version-name*="stable"] {
571
+ background-color: green;
572
+ }
573
+
574
+ In addition, the parent button of the dropdown list contains similar metadata
575
+ about the **current version **. This could be used to style the entire dropdown
576
+ a certain color based on the active version.
577
+
578
+ For example, if you wanted to style the dropdown button orange if it was a ``dev ``
579
+ version, you could use the following CSS selector:
580
+
581
+ .. code-block :: scss
582
+
583
+ // If the active version has the name "dev", style it orange
584
+ #version_switcher_button[data-active-version-name*="dev"] {
585
+ background-color: rgb(255 138 62);
586
+ }
587
+
588
+ .. seealso ::
589
+
590
+ See the `MDN documentation on dataset properties <https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset >`_
591
+ for more information on using and styling with these properties.
545
592
546
593
Add an Edit this Page button
547
594
============================
0 commit comments