Home › Forums › DITA and XMetaL Discussion › Customize Tag on View by using CSS › Reply To: Customize Tag on View by using CSS
Reply to: Customize Tag on View by using CSS
May 10, 2017 at 6:58 pmYou can extend the CSS files used for DITA authoring, and specifically the topic.dtd, by adding selectors to this file:
C:Program FilesXMetaL 12.0AuthorDITAXACs
The
Keep in mind that standard W3C CSS cascading rules apply. So, if you are overriding a previously defined CSS selector (which is very likely) any selector you add needs to be at least as “specific”. Any property set on the other selector will also still be in effect unless you provide a new value for it. Also, all the selectors for DITA use the DITA @class for the element (not the element name). This allows them to automatically be applied to any elements in any specialized DITA DTD that specializes that element (ie: if you specialize to add a
then they will look the same). In order to be as specific (according to the CSS cascade rules) you need to follow the same format (which basically means using the class attribute).
To check which other values are previously set have a look at this file (and the files it imports):
C:Program Files (x86)XMetaL 12.0AuthorDITAXACs
or
C:Program FilesXMetaL 12.0AuthorDITAXACs
That file just imports other CSS files, like so:
@import url(....sharedditabase-base.css);
@import url(..ditabaseditabase-base-override.css);
@import url(....sharedditabase-derived.css);
@import url(..ditabaseditabase-derived-override.css);
@import url(topic_ditabase-specialized.css);
…which is why you would normally add any of your own overrides or additional selectors to topic_ditabase-specialized.css
Of course you could also make modifications directly to any of these CSS files, it is just a bit cleaner to do it this way because then all of your changes are in one place. Adding them to topic_ditabase-specialized.css also means they are guaranteed to load last.
I would recommend commenting any changes you make with the date and reason. XMetaL Support often has clients contacting them for help with changes made to the software several years after they were done (not usually CSS, but macros and other functionality) when the creator is either now gone or doesn't know what they did or why. Makes it impossible to guess what the intended purpose for any particular change might have been.
Example that turns topic/p elements red for the topic.dtd for DITA version 1.3:
The CSS selector for this element is defined here (and imported by the other DITA CSS files):
C:Program FilesXMetaL 12.0AuthorDITAXACssharedditabase-base.css
/* p */
[class~="topic/p"] {
display: block;
margin-top: 2px;
margin-right: 2px;
margin-bottom: 8px;
}
Modify this file:
C:Program FilesXMetaL 12.0AuthorDITAXACs1.3topictopic_ditabase.css
Add something similar to this:
/* Derek Read
2017-05-10
changed p element to make it red
because I needed it to stick out and be really obvious
*/
[class~="topic/p"] {
color: red
}