Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

white-space:pre-wrap vs. overflow:auto for pre #81

Open
thierryk opened this issue Feb 2, 2021 · 2 comments
Open

white-space:pre-wrap vs. overflow:auto for pre #81

thierryk opened this issue Feb 2, 2021 · 2 comments

Comments

@thierryk
Copy link
Contributor

thierryk commented Feb 2, 2021

The rule for pre is as follow:

/* @docs
label: Pre Wrapping
note: |
  Overflow by default is bad...
category: typography
*/
pre { white-space: pre-wrap; }

I agree that "overflow by default is bad", but I'd argue that a better "fix" would be to prevent overflowing from happening rather than going against what this element is about:

The HTML <pre> element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered using a non-proportional ("monospace") font. Whitespace inside this element is displayed as written.

As far as I can tell, pres we find in the wild are styled with overflow:auto as it prevents content from overflowing while preserving the formatting of that content. The example below shows that this is true for GitHub too:

---------------- A ---------------- B ---------------- C ---------------- D ---------------- E ---------------- F ---------------- G
                 ^                  ^                  ^                  ^                  ^                  ^                  ^ 

So I'd suggest replacing white-space:pre-wrap with overflow:auto as it is more in line with how pre is styled IRL.

@jhthorsen
Copy link

How about overflow-x: auto;?

@thierryk
Copy link
Contributor Author

thierryk commented Feb 3, 2021

@jhthorsen what would be the advantage of using overflow-x:auto instead of overflow:auto?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants