Skip to content

Different rendering of <pre> blocks #2969

@dieghernan

Description

@dieghernan

Hi,

I noticed that pkgdown renders the <pre> blocks differently, causing the copy button to overlap with the <pre> border:

Image

Steps to reproduce: https://pkgdown.r-lib.org/articles/customise.html#getting-started > Inspect > Simulate hover in the <pre> blocks before and after the heading > Reduce width viewport (e.g. simulating Samsung Galaxy S8).

This is not a bug in pkgdown but the consequence of two rules in Boostrap 5.3.1:

/* Copy button */

@media (max-width: 575.98px) {
    .btn-copy-ex {
        right: calc(var(--bs-gutter-x) * -.5 + 5px);
    }
}

/* ...more code */

/* Remove margins in pre */
@media (max-width: 575.98px) {
    div>div>pre {
        margin-left: calc(var(--bs-gutter-x) * -.5);
        margin-right: calc(var(--bs-gutter-x) * -.5);
        border-radius: 0;
        padding-left: 1rem;
        padding-right: 1rem;
    }
} 

The issue is that the two pre are different, since the first one is preceded by only one div hence not affected by the second rule:


<!-- First pre precedence (starting in <main> -->
main > **div**.sourceCode.hasCopyButton > **pre**.downlit.sourceCode.r

<!-- Second pre precedence (starting in <main> -->
main > **div**.section.level2 > **div**.sourceCode.hasCopyButton > **pre**.sourceCode.yaml

I think a CSS rule like this would fix it (not tested yet):

@media (max-width: 575.98px) {
    div>pre {
        margin-left: calc(var(--bs-gutter-x) * -.5);
        margin-right: calc(var(--bs-gutter-x) * -.5);
        border-radius: 0;
        padding-left: 1rem;
        padding-right: 1rem;
    }
} 

Hopefully it is clear...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions