英文:
Apply slide specific CSS in ioslides_presentation on specified div classes only
问题
以下是您要翻译的内容:
markdown:
---
title: "TITLE"
subtitle: "subtitle"
output:
ioslides_presentation:
css: www/cust.css
---
# Main 0
## sub
# Main 1 {.cust-1 .rcorners}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 2 {.cust-2}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 3 {#cust-3 .rcorners}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 4 {#cust-4}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ```
css:
.slides > slide:not(.nobackground):before {
left: initial;
bottom: initial;
right: 0;
top: 0;
width: 100px;
height: 100px;
background-size: 115px 115px;
}
.cust-1 {
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
.rcorners img{
border-radius: 45px;
padding: 20px;
}
.cust-2 h2{
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
#cust-3 h2{
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -10px;
bottom: 60px;
}
#cust-4 {
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -10px;
bottom: 60px;
}
.auto-fadein h2{
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
top: 0px;
}
.gdbar img {
width: 150px !important;
height: 150px !important;
margin: 8px 8px;
}
.gdbar {
width: 250px !important;
height: 170px !important;
}
aside.gdbar {
left: initial;
right: 0;
border-top-left-radius: 10px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 10px;
background-position: right;
}
<style>
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
希望这能帮助您进行所需的翻译。
英文:
How can I change the h2 header styles for specific slides only using the {} syntax?
I want to create a html presentation using rmarkdown
and ioslides
.
Some of the main slides should include images, and their titles should not overlap the image.
I am trying to influence their layout using some css ID (or class) specified in the www/cust.css
file.
markdown:
---
title: "TITLE"
subtitle: "subtitle"
output:
ioslides_presentation:
css: www/cust.css
---
# Main 0
## sub
# Main 1 {.cust-1 .rcorners}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 2 {.cust-2}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 3 {#cust-3 .rcorners}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
# Main 4 {#cust-4}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("www/SMPTE_Color_Bars.svg")
` ``
css
slides > slide:not(.nobackground):before {
left: initial;
bottom: initial;
right: 0;
top: 0;
width: 100px;
height: 100px;
background-size: 115px 115px;
}
.cust-1 {
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
.rcorners img{
border-radius: 45px;
padding: 20px;
}
.cust-2 h2{
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
#cust-3 h2{
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -10px;
bottom: 60px;
}
#cust-4 {
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -10px;
bottom: 60px;
}
.auto-fadein h2{
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
top: 0px;
}
.gdbar img {
width: 150px !important;
height: 150px !important;
margin: 8px 8px;
}
.gdbar {
width: 250px !important;
height: 170px !important;
}
aside.gdbar {
left: initial;
right: 0;breaker.s
border-top-left-radius: 10px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 10px;
background-position: right;
}
<style>
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
However the problem i am facing is that i can't influence the h2
header class via the {.cust-x}
or {#cust-x}
syntax.
It either influences the image and subtitle:
or, if i use h2
like this:
.cust-2 h2{
font-weight: 200;
font-size: 10px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
it has no influence whatsoever.
Usually these markdown first level header slides are using this css:
.auto-fadein h2{
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
top: 0px;
}
But i cant change this class because it will interfere with the title page, etc.
EDIT
The syntax: {} works fine if i try to target other html objects for examle using this css style:
.rcorners img{
border-radius: 45px;
padding: 20px;
}
gives me rounded image corners in example 1 and three where it is applied.
答案1
得分: 3
问题
正如你发现的,.cust-1 h2 {}
没有定位到你想要的标题。这是因为 HTML 结构与你想象的不同。
如何知道如何定位到你想要的元素?
步骤1:在 RStudio 中点击 Knit to HTML (ioslides)
步骤2:点击 Open in Browser
步骤3:使用开发者工具(即,在浏览器中按 F12 键)
你可以看到 HTML 结构如下:
<hgroup class="auto-fadein">
<h2>Main 1</h2>
</hgroup>
<article id="main-1" class="cust-1">
...
</article>
截图:
解决方案1
例如,要定位第四张幻灯片中的 <h2>
(即 Main 1),使用以下 CSS:
/* 设置 <h2> 包装器的位置 */
slide[data-slide-num='4'] .auto-fadein {
/* 你的 CSS */
}
/* 设置 <h2> */
slide[data-slide-num='4'] h2 {
/* 你的 CSS */
}
查看下面的 my-presentation.Rmd
和 styles.css
以获取完整解决方案。
my-presentation.Rmd
---
title: "Title"
subtitle: "Subtitle"
output:
ioslides_presentation:
css: styles.css
date: "2023-05-30"
---
# Main 0
## 子
# Main 1 {.cust-1}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 2 {.cust-2}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 3 {#cust-3}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 4 {#cust-4}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
styles.css
slides > slide:not(.nobackground):before {
left: initial;
bottom: initial;
right: 0;
top: 0;
width: 100px;
height: 100px;
background-size: 115px 115px;
}
/**************** Slide 4 ****************/
/* 设置 <h2> 包装器的位置 */
slide[data-slide-num='4'] .auto-fadein {
bottom: 60px;
}
/* 设置 <h2> */
slide[data-slide-num='4'] h2 {
color: blue;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 5 ****************/
/* 设置 <h2> 包装器的位置 */
slide[data-slide-num='5'] .auto-fadein {
bottom: 60px;
}
/* 设置 <h2> */
slide[data-slide-num='5'] h2 {
color: red;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 6 ****************/
/* 设置 <h2> 包装器的位置 */
slide[data-slide-num='6'] .auto-fadein {
bottom: 60px;
}
/* 设置 <h2> */
slide[data-slide-num='6'] h2 {
color: green;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 7 ****************/
/* 设置 <h2> 包装器的位置 */
slide[data-slide-num='7'] .auto-fadein {
bottom: 60px;
}
/* 设置 <h2> */
slide[data-slide-num='7'] h2 {
color: purple;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
.gdbar img {
width: 150px !important;
height: 150px !important;
margin: 8px 8px;
}
.gdbar {
width: 250px !important;
height: 170px !important;
}
aside.gdbar {
left: initial;
right: 0;
border-top-left-radius: 10px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 10px;
background-position: right;
}
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
编辑
你
英文:
Problem
As you figured out, .cust-1 h2 {}
wasn't targeting the heading you wanted. This is because the HTML structure is different than you thought.
How do you know how to target the element you want?
Step 1: Click Knit to HTML (ioslides) in RStudio
Step 2: Click Open in Browser
Step 3: Use Developer Tools (i.e., press the F12 key in your browser)
You can see that the HTML structure is the following:
<hgroup class="auto-fadein">
<h2>Main 1</h2>
</hgroup>
<article id="main-1" class="cust-1">
...
</article>
Screenshot:
Solution 1
For example, to target the <h2>
in the fourth slide (i.e., Main 1) use the following CSS:
/* Style the position of the <h2> wrapper */
slide[data-slide-num='4'] .auto-fadein {
/* Your CSS */
}
/* Style the <h2> */
slide[data-slide-num='4'] h2 {
/* Your CSS */
}
See my-presentation.Rmd
and styles.css
below for the full solution.
my-presentation.Rmd
---
title: "Title"
subtitle: "Subtitle"
output:
ioslides_presentation:
css: styles.css
date: "2023-05-30"
---
# Main 0
## sub
# Main 1 {.cust-1}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 2 {.cust-2}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 3 {#cust-3}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
# Main 4 {#cust-4}
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
styles.css
slides > slide:not(.nobackground):before {
left: initial;
bottom: initial;
right: 0;
top: 0;
width: 100px;
height: 100px;
background-size: 115px 115px;
}
/**************** Slide 4 ****************/
/* Style the position of the <h2> wrapper */
slide[data-slide-num='4'] .auto-fadein {
bottom: 60px;
}
/* Style the <h2> */
slide[data-slide-num='4'] h2 {
color: blue;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 5 ****************/
/* Style the position of the <h2> wrapper */
slide[data-slide-num='5'] .auto-fadein {
bottom: 60px;
}
/* Style the <h2> */
slide[data-slide-num='5'] h2 {
color: red;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 6 ****************/
/* Style the position of the <h2> wrapper */
slide[data-slide-num='6'] .auto-fadein {
bottom: 60px;
}
/* Style the <h2> */
slide[data-slide-num='6'] h2 {
color: green;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
/**************** Slide 7 ****************/
/* Style the position of the <h2> wrapper */
slide[data-slide-num='7'] .auto-fadein {
bottom: 60px;
}
/* Style the <h2> */
slide[data-slide-num='7'] h2 {
color: purple;
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
bottom: 60px;
}
.gdbar img {
width: 150px !important;
height: 150px !important;
margin: 8px 8px;
}
.gdbar {
width: 250px !important;
height: 170px !important;
}
aside.gdbar {
left: initial;
right: 0;
border-top-left-radius: 10px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 10px;
background-position: right;
}
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
EDIT
You didn't understand what I wrote above. I'll try to simplify.
If you write:
# Main 1 {.cust-1}
The HTML structure will be the following:
<hgroup class="auto-fadein">
<h2>Main 1</h2>
</hgroup>
<article id="main-1" class="cust-1">
...
</article>
Meaning, you can't style the <h2>
the way you want to (i.e., with the following CSS: .cust-1 h2 {}
) because it's not a child or descendant of the <article>
with the class="cust-1"
. See Solution 1.
But if you really want to style the <h2>
with a class, then see Solution 2.
Solution 2
You can add a class to the <h2>
like this:
<h2 class="main-1">Main 1</h2>
See my-presentation.Rmd
and styles.css
below for the full solution.
my-presentation.Rmd
---
title: "Title"
subtitle: "Subtitle"
output:
ioslides_presentation:
css: styles.css
date: "2023-05-30"
---
# Main 0
## sub
#
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
<h2 class="main-1">Main 1</h2>
#
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
<h2 class="main-2">Main 2</h2>
#
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
<h2 class="main-3">Main 3</h2>
#
```{r,echo=FALSE, fig.cap= "an img caption", out.width= '50%', fig.pos='top'}
knitr::include_graphics("./SMPTE_Color_Bars.png")
```
<h2 class="main-4">Main 4</h2>
styles.css
slides > slide:not(.nobackground):before {
left: initial;
bottom: initial;
right: 0;
top: 0;
width: 100px;
height: 100px;
background-size: 115px 115px;
}
h2.main-1,
h2.main-2,
h2.main-3,
h2.main-4 {
font-weight: 200;
font-size: 100px;
line-height: 1.1;
position: relative;
left: -6px;
}
/**************** Main 1 ****************/
h2.main-1 {
color: blue;
}
/**************** Main 2 ****************/
h2.main-2 {
color: red;
}
/**************** Main 3 ****************/
h2.main-3 {
color: green;
}
/**************** Main 4 ****************/
h2.main-4 {
color: purple;
}
.gdbar img {
width: 150px !important;
height: 150px !important;
margin: 8px 8px;
}
.gdbar {
width: 250px !important;
height: 170px !important;
}
aside.gdbar {
left: initial;
right: 0;
border-top-left-radius: 10px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 10px;
background-position: right;
}
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
Output
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论