In bookdown how can I set the default color on code output

I would like to have the text output from my bookdown book appear in a white box with a black boarder. The R Markdown Cookbook shows how to set the style for a specific block but I don't see how to set the default. If anybody knows how can you please respond on stack overflow: https://stackoverflow.com/questions/65495605/in-r-bookdown-how-do-i-set-the-default-code-output-background-color (or here).

I answered there too

The previous answer is correct for the CSS rule but the selector must be more specific for a gitbook() format. This a matter of CSS specificity.

Using a browser inspector, you can get a sense of the selector you need to use to override default CSS style set by gitbook.

This simple css will replace background and add a border

.book .book-body .page-wrapper .page-inner section.normal pre {
    background: #fff;
    border: 1px solid #ddd;
    border-color: #000;
}

You put in as you do in style.css and use the css argument of bookdown::gitbook in index.Rmd or in _output.ymldepending of which you are using.

This will pick up the CSS.

I think you could also use !important to have the most specify on pre with

pre {
    background: #fff !important;
    border: 1px solid #ddd !important;
    border-color: #000 !important;
}

I sincerely appreciate the help! I posted a follow-up question on SO...

Your code styles both the code and output the same. Is there a way to limit it to only applying this to the output? I inspected the html and the code is tagged with and the output is tagged with

. Is there a way to NOT apply your change to the "sourceCode r" chunks? In other words, I want to keep the default style for the code and use your code for only the output.

For reference this topic has been answered on Stackoverflow.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.