custom CSS
Hi ReDoc team, Is there any way to apply custom css in ReDoc? I tried applying in index.html of ReDoc but that is getting overridden by ReDoc styles.
Regards.
This is similar to #144
You can override certain styles you would just have to use the !important operator a lot or make your CSS have a higher specificity value
.menu-content {
background-color: #ffff00 !important;
}
@jsmartfo thanks for answering! CSS is now getting overridden by ReDoc as it uses attributes selectors.
Instead of having important try to prefix all your css rules with e.g. redoc[spec-url]. It should increase specifity of css selectors and do the trick.
During the next month I am going to refactor all the css and this issue should not happen in the future
Thanks Roman and Jsmartfo,
One clarification, do i need to specify the css file like following in index.html? < redoc spec-url="customstyle.css" > or need to modify the css file itself and modify the style (could you please provide an example for this? how to prefix the css rule?)
Regards,
@ranjapri spec-url is for providing swagger spec not css file.
You should add your css into head of the html page. Taking quick example from readme:
<!DOCTYPE html>
<html>
<head>
<title>ReDoc</title>
<!-- needed for adaptive design -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="YOUR CSS LINK HERE">
</head>
<body>
<redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>
<script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"> </script>
</body>
</html>
As for prefixing, here is example of how to change headings 1 color:
redoc[spec-url] h1 {
color: red;
}
redoc[spec-url] .tag-info h1 {
color: red !important;
}
Sometimes prefixing is not enough so just use !important for now
Thank you so much Roman, It works but writing important for all styles or even prefixing is troublesome. Will the CSS work seamlessly after the code refactoring?
Regards.
@ranjapri yes, it will
Is custom CSS like this supported in redoc-cli?
@debri174, no, redoc-cli is using [email protected] which is a complete rewrite so this css doesn't work
To customize it you can use the theme. Check out README for details
Could someone please confirm;
- If i'm wanting to use custom styling (for any / every thing), I would need to stick to v1.x.x for now? (https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js) rather than the newer v2 (https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js)?
Seems that, using the v1.x.x reference I can get the styling to work (external link and in-place styling), however, if I change to v2, nothing renders? @RomanGotsiy
Note: I'm using the CDN repo.
My CSS was working up until recently. I was using redoc to serve some api docs, but I customized the CSS for ease of readability and to adapt the doc color schemes to our company colors. The issue seems that there must have been an update of some sort that overrode the old html class tags, so all my css references no longer work. For example, before the CSS for one of the elements in the menu item that previously worked would have looked like:
.arcYq {
border-left: rgba(255, 200, 0, 0.7) solid 4px;
background: #5058ab;
box-shadow: 2px 2px;
border-radius: 0px 3px 3px 0px;
margin: 10px 10px 0px 0px;
padding: 5px 5px 0px 0px;
}
[type="section"]{
border-left: rgba(255, 200, 0, 0.7) solid 4px;
}
However, now, I have to manually fix all of the css, and I'm not certain which css tags would replace the existing css tags. There must be a better way to update the css without having to identify the new css class names and which ones match the old CSS class names. How should I go about updating the css without having to redo the work again when the tags are updated again?