CSS Customization in a Bookdown Document

CSS Customization in a Bookdown Document

Your problem is most likely the CSS specificity:
https://www.w3.org/TR/CSS2/cascade.html#specificity
This means that gitbooks style override those of leaflet because they are more specific.

To fix this you could add a lot of classes to the leaflet CSS file but that would be kinda dirty (an even more dirty fix would be to use !important).
I searched a bit and found the following document, the problem is solved by linking the map in an iFrame, would that be a solution for you too?
https://bookdown.org/yihui/bookdown/web-pages-and-shiny-apps.html

In the future it will probably be possible to use encapsulation with shadow dom: https://glazkov.com/2011/01/14/what-the-heck-is-shadow-dom/

From your link:

Let’s assume the file is named mathjax-number.html, and it is in the
root directory of your book (the directory that contains all your Rmd
files). You can insert this file into the HTML head via the in_header
option, e.g.,

So you can create a custom CSS file and save it in the root of your book. The way I take it it needs to be a .html file.
Because the content seems to be written in the HTML head you need to include style tags: http://www.w3schools.com/tags/tag_style.asp

In the file you can change stuff like .leaflet-bar a to .book .book-body .page-wrapper .page-inner section.normal .leaflet-bar a which will grant a higher specificity.
Please bear in mind to update the specificity of the following CSS as well:

.leaflet-bar a, .leaflet-bar a:hover {
background-color: #fff;
}

This is because apparently background: 0 0; overwrites not only the background position but also the background color.

CSS and R markdown (bookdown). How can I use a CSS to build css boxes without changing the overall template?

If someone faces the same question, this is the solution.

In the CSS file, start the commands with a specific string (below) and then, on Markdown, use the div notation. Such as:

<div class="question">
1. My first question
1. My second question
</div>

/* -----------Question counter ---------*/

body {
counter-reset: li;
}
h1 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
}

h2 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
margin-top: 24px;
}
.question ol {
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */
}

.question ol>li {
position:relative; /* Create a positioning context */
margin:0 0 10px 2em; /* Give each list item a left margin to make room for the numbers */
padding:10px 80px; /* Add some spacing around the content */
list-style:none; /* Disable the normal item numbering */
border-top:2px solid #317EAC;
background:rgba(49, 126, 172, 0.1);
}

.question ol>li:before,
.question ol>p>li:before {
content:"Questão " counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
width:7em;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:8px;
padding:4px;
border-top:2px solid #317EAC;
color:#fff;
background:#317EAC;
font-weight:bold;
font-family:"Helvetica Neue", Arial, sans-serif;
text-align:center;
}

.question ol ol {
counter-reset: subitem;
}

.question li ol,
.question li ul {margin-top:6px;}
.question ol ol li:last-child {margin-bottom:0;}

Custom CSS to Change Bookdown Page Width

Try this:

.book .book-body .page-wrapper .page-inner {
max-width: 1200px !important;
}

creating custom blocks in RStudio's bookdown

Thanks to @Frank's tip (see his solution for using local images), I was able to come up with the following.

I added this to the style.css file in the root of my book's directory based on this SO answer and this specific example:

.rmdcomment {
padding: 1em 1em 1em 4em;
margin-bottom: 10px;
background: #f5f5f5;
position:relative;
}

.rmdcomment:before {
content: "\f075";
font-family: FontAwesome;
left:10px;
position:absolute;
top:0px;
font-size: 45px;
}

I got the value f075 for the comment icon from this FontAwesome cheatsheet.

Then I downloaded the CSS toolkit from FontAwesome and copied the font-awesome.min.css file into the root of my book directory. I added the following to my output.yml file (in the template I started with, style.css, toc.css was already present):

bookdown::html_book:
css: [style.css, toc.css, font-awesome.min.css]

Finally, I inserted a code chunk into my Rmd file using the type option:

```{block, type='rmdcomment'}
Some text for this block. Some text for this block. Some text for this block. Some text for this block. Some text for this block. Some text for this block.
```

Sample Image

Customising Colour / Boldness in Markdown with RMarkdown / Bookdown

Per your request, you can change the styles in HTML outputted R Markdown scripts by adding styles. There are a few different ways you can add them. Typically, I just place this content in between chunks.

<style>
blockquote {
font-color: black;
opacity: 1;}
</style>

You can attach an external style document or use a CSS chunk. I just find this easier for most projects.

You can read more about this here.

style links in a custom block in bookdown

I believe this is the section you talking about.

Sample Image

Add !important, so basically you overwrite the previous styles.

.rmdcomment a:link {text-decoration: underline !important; font-weight:bold !important; color:white !important;}



Related Topics



Leave a reply



Submit