如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

huangapple go评论89阅读模式
英文:

How to use grid-column CSS property with bslib::layout_column_wrap() inside quarto doc

问题

如果我设置了两个值框,就像这样:

  1. ```{r}
  2. bslib::layout_column_wrap(
  3. width = NULL,
  4. fill = FALSE,
  5. class = "d-grid",
  6. style = htmltools::css(grid_template_columns = "repeat(auto-fill, minmax(200px, 1fr))"),
  7. bslib::value_box("Value box", 1),
  8. bslib::value_box("Value box", 2)
  9. )
  10. ```

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

我如何使用 grid-column: span 2 让第一个值框跨足两列?

目标是为特定的网格元素设置此属性并保留内容换行。

我可以这样做:

  1. ```{r}
  2. #| classes: col_wrap
  3. bslib::layout_column_wrap(
  4. width = NULL,
  5. fill = FALSE,
  6. class = "d-grid",
  7. style = htmltools::css(grid_template_columns = "minmax(200px, 2fr) minmax(200px, 1fr)"),
  8. bslib::value_box("Value box", 1),
  9. bslib::value_box("Value box", 2)
  10. )
  11. ```

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

但是,如果浏览器窗口宽度太窄,就会出现水平滚动条。

我可以进入开发工具并在第一个 div.html-fill-container 中添加 style = "grid-column: span 2" 以获得我想要的效果:

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

我尝试添加以下 CSS 代码块,但它没有起作用:

  1. ```{css}
  2. #| include: false
  3. div.bslib-column-wrap div:html-fill-container {
  4. grid-column: span 2
  5. }
  6. ```
英文:

If I have two value boxes setup like this:

  1. ```{r}
  2. bslib::layout_column_wrap(
  3. width = NULL,
  4. fill = FALSE,
  5. class = "d-grid",
  6. style = htmltools::css(grid_template_columns = "repeat(auto-fill, minmax(200px, 1fr))"),
  7. bslib::value_box("Value box", 1),
  8. bslib::value_box("Value box", 2)
  9. )
  10. ```

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

How do I use grid-column: span 2 to make the first value box span 2 columns?

The goal is to set this property for specific grid elements and preserve content wrapping.

I can do this:

  1. ```{r}
  2. #| classes: col_wrap
  3. bslib::layout_column_wrap(
  4. width = NULL,
  5. fill = FALSE,
  6. class = "d-grid",
  7. style = htmltools::css(grid_template_columns = "minmax(200px, 2fr) minmax(200px, 1fr)"),
  8. bslib::value_box("Value box", 1),
  9. bslib::value_box("Value box", 2)
  10. )
  11. ```

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

but then you get horizontal scrollbars if the browser window width is too narrow.

I can go into dev tools and add style = "grid-column: span 2" to the first div.html-fill-container to get what I want:

如何在Quarto文档中使用`bslib::layout_column_wrap()`和grid-column CSS属性。

I tried adding the following CSS code chunk but it did not work:

  1. ```{css}
  2. #| include: false
  3. div.bslib-column-wrap div:html-fill-container {
  4. grid-column: span 2
  5. }
  6. ```

答案1

得分: 1

尝试使用以下 CSS 选择器(选择位于 div.bslib-column-wrap 内的第一个 .html-fill-container div)。

  1. div.bslib-column-wrap > div.html-fill-container:first-child {
  2. grid-column: span 2;
  3. }
英文:

Try with the following css selector (which selects the first .html-fill-container div within div.bslib-column-wrap.

  1. ```{css, echo=FALSE}
  2. div.bslib-column-wrap > div.html-fill-container:first-child {
  3. grid-column: span 2;
  4. }
  5. ```

huangapple
  • 本文由 发表于 2023年2月14日 00:29:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定