Is it possible to generate vertical tabs in Rmarkdown by utilizing {.tabset} alongside a CSS stylesheet?

My Rmarkdown report consists of multiple tabs, and I'm exploring how to create vertical tabs on the left side of the screen while filling the rest of the space with tabbed content (similar to this simple example: https://www.w3schools.com/howto/howto_js_vertical_tabs.asp).

To align the tabs vertically, I utilized the following code in my CSS stylesheet:

.tab {
    float: left;
    width: 15%;
    height: 100%;
}

And within my Rmd document, I added:

## {.tabset .tabset-pills .tab}

### Section 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

### Section 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

However, this formatting applies the styles to both headings and body text, rather than just the headings.



To format the body as desired, I referred to a Github issue for assistance: https://github.com/rstudio/rmarkdown/issues/896, incorporating this CSS code:

.tabcontent .tab-content {
    float: left;
    padding: 0px 12px;
    height: 100%;
    width: 85%;
}

And updated my Rmarkdown code accordingly:

## {.tabset .tabset-pills .tabcontent}

### Section 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

### Section 2
Ut porttitor leo a diam. Auctor neque vitae tempus quam pellentesque nec nam.

I am now seeking guidance on editing the actual tabs themselves, similar to how I edited the tab content with .tab-content. Is there a similar selector for modifying the tabs directly?

Answer №1

Although this question is from some time ago, I wanted to share with you the code that positions pills on the side of the window. Interestingly, the code doesn't seem to work properly in the Rstudio viewer; you'll need to view it in a browser to see the desired effect.

`

---
title: "Custom Styling"
author: "Anonymous"
date: "May 14, 2021"
output: html_document
---

{css, echo=FALSE}
.container-fluid.main-container{
max-width: 85%
}
.tabset{
    display: flex;

}

.nav.nav-pills {
    flex: 15%;
    width: 100%;
}
.nav.nav-pills li{
    width: 100%;
}
.tab-content{
    flex: 85%;
    width: 100%
}




## {.tabset .tabset-pills .tabcontent}


### New Section

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.


### Another Section

Ut porttitor leo a diam. Auctor neque vitae tempus quam pellentesque nec nam.

`

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JSX/CSS: the text on the button is positioned outside of the button in Chrome browser

As I work on styling a React component using CSS, I noticed that I'm getting different results in Chrome and Firefox: Firefox (which is the desired behavior for both): https://i.sstatic.net/Q0LSD.png Chrome: https://i.sstatic.net/s2MWJ.png While I& ...

Using Three.js to display a CSS3D-rendered DIV in full-screen mode

After extensively experimenting with the three.js library, I was able to establish two distinct scenes – one canvas-rendered and the other css3d-rendered – both displayed using the same perspective camera. Note: Despite my efforts, I am constrained to ...

What is the reason for elements such as "if" and "else" not being visually

I am currently developing a browser-based code editor with a unique feature. Task: The objective is to highlight specific keywords like if, else, for... when they are entered into the editor. textarea.addEventListener("input", function() { ...

What is the best way to prevent card-group from wrapping on smaller screens?

What is the best way to ensure that cards in a card-group stay adjacent to each other on smaller screens? Currently, they are grouped together on larger screens but appear separated on smaller screens. I am currently hiding the additional cards on smaller ...

Achieving vertical alignment of form controls with labels that wrap in a row using Bootstrap 4

I am facing an issue where input elements in a row with labels above them are causing alignment problems when the screen width is reduced. The longer labels wrap to the next line and push the input element down, increasing the overall height of the row: h ...

Harnessing JavaScript templates within PHPHow to integrate JavaScript templates

I am currently working on a PHP document where I incorporate 'chapters' (jQuery tabs) in two different ways: Whenever a new chapter is generated, it gets added to the list as well as to the database using JavaScript and Ajax. I have already i ...

Filtering data without displaying every item as the default setting

I am looking to create a customized data filter that only displays items when a specific category is chosen. Most filters online display all items by default, but I want one that remains hidden until I choose to reveal them. If anyone has a tutorial or c ...

The text is not meticulously arranged within the designated span

My text-align (center) property doesn't seem to be working correctly with the following code snippet: <span class="info">&nbsp;i&nbsp;<span id="uitleg_itje">Bla bla. </span></span> The CSS for the info class is as fo ...

What are the best ways to customize a fullscreen menu with the default Bootstrap toggler?

I am new to Bootstrap Studio and I'm working on my first website. I would like to create a menu design similar to this one: Here's what the menu toggle looks like when clicked: https://i.sstatic.net/WPu07.jpg You can check out my website here: ...

Press the button obscured by an image

Recently on my HTML website, I encountered an issue where I tried adding a transparent image over a button but found that I was unable to click on the button afterwards. The problem seems to be related to the following code snippet: #container { heigh ...

What is the best way to incorporate verbatimTextOutput alongside regular text in a Shiny application?

Whenever I run this simple app, I encounter an issue where the alignment of the - between the verbatimTextOutput for scores and the output text boxes is off. It seems like the verbatimTextOutput contains the text within an HTML pre tag and upon inspecting ...

What is the best way to stop a Primefaces knob label from appearing outside of the knob circle while scrolling horizontally?

Currently employing Primefaces 13, I've encountered an issue with a dataTable that contains a column displaying a number using the p:knob component. When horizontally scrolling the dataTable, the label of the knob component is rendered outside the kno ...

"Optimize Magellan Sidebar for Mobile Devices by Relocating it to the Bottom of the Page

After spending a week working with Foundation 5 framework, I'm curious if there is a straightforward way to make my magellan sidebar shift to the bottom of the page when viewed on mobile or tablets. <div data-magellan-expedition="fixed"> <di ...

Is there a method to generate an endless carousel effect?

Hello, I am trying to create an infinite carousel effect for my images. Currently, I have a method that involves restarting the image carousel when it reaches the end by using the code snippet progress = (progress <= 0) ? 100 : 0;. However, I don't ...

Two separate pieces of text converge within a single span

I am facing a challenge with alignment in a bootstrap <span> element. Specifically, I want to align the word "amount" to the left, and the "$" to the right, within the same label. I attempted to nest a <span> inside another <span> and app ...

Unable to reach the dropdown menu in CSS

Having trouble with creating a dropdown navigation bar? I've encountered an issue where the dropdown menu disappears as soon as I move my cursor off the buttons that reveal it. The menu itself displays properly, but accessing the drop down menu is pro ...

Extract the specific value from a dataframe in R by specifying the column index and providing a conditional row index

As a data scientist, I face the challenge of handling a complex mapping table like this: fli.1 = c(0, 700, 1500, 2000, 3500, 5600, 11000, 20000, 50000) fli.2 = c(0, 200, 1000, 2900, 3000, 5500, 10000, 20000, 50000) fli.3 = c(0, 600, 1200, 2500, 3900, 5000, ...

My code got unexpectedly wrapped in an unnecessary div by Internet Explorer

Oh no, my layout on my aspx page looks totally messed up in IE9! It's perfect in Chrome though: But in IE9, it's all out of whack and looks like this: I finally found out the reason behind this strange display. Apparently IE9 wrapped my "save N ...

"Is it possible for an anchor tag to be clickable only if it is

I am puzzled by the HTML code below: @import url(https://fonts.googleapis.com/css?family=Roboto:400,300,400italic,500,700,900); /* global css */ body { font-size: 16px; font-family: 'Roboto', sans-serif; color: #fff; padding: 0; ma ...

How can you modify the Bootstrap class of a grid item only when the grid collapses in Bootstrap 4?

Is there a way to dynamically adjust the bootstrap class of a grid element from col-md-9 to col-md-12 only when the grid breaks due to resizing the browser window? For example, consider the following code snippet: https://jsfiddle.net/kp41m0xq/ <body ...