旋转的HTML为什么会使div垂直滚动?

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

Why rotated html makes the div vertically scrollable?

问题

这是我想出来的代码,但找不到问题出在哪里。正如问题所暗示的,当旋转时,div 变得可以垂直滚动,这在我的情况下是不可取的。

另外,我希望在浏览器不是全屏时,内容会根据文本内容至少垂直调整大小。我想这应该是默认的,但甚至没有将包装器设置为 height: inherit;

<!DOCTYPE html>
<html>
<head>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html {
      transform: rotate(-90deg);
    }
    
    .wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      width: 100%;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <div>
      <p>你好,你好吗</p>
      <p>你好,无论如何</p>
      <p>你好,测试一下</p>
    </div>
  </div>
</body>
</html>

编辑: @Brett Donald 的答案适用于像我最初发布的小型 div,但对于较大的 div 不适用。

英文:

This the code I came up with but cannot find where the problem lies. As the question implies, when rotated, the div becomes vertically scrollable and it is not desirable in my case.

Additionally, I would like that when the browser is not on full screen the content shrinks to adjust only to the text content at least vertically. I would imagine it would happen by default but does not even set the wrapper to height: inherit;

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;html&gt;

&lt;head&gt;
  &lt;style&gt;
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html {
      transform: rotate(-90deg);
    }
    
    .wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      width: 100%;
    }
  &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div&gt;
      &lt;p&gt;hello how are you&lt;/p&gt;
      &lt;p&gt;hello whatever here&lt;/p&gt;
      &lt;p&gt;hello testing this&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

Edit: @Brett Donald answer works with a small div like the one I initially posted but not with larger ones.

答案1

得分: 1

我看到你正在尝试旋转整个文档(HTML元素)。我不太惊讶这样做会引起问题。

如果可能的话,尽量旋转特定的元素,而不是整个文档。例如,如果你想让文本显示在视口的中心,然后逆时针旋转90度,你只需要旋转包裹的div。

<html>
  <head>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        min-height: 100vh;
        border: 2px solid red;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .wrapper {
        border: 2px solid black;
        transform: rotate(-90deg);
      }
    </style>
  </head>
  <body>
    <div class="wrapper">
      <div>
        <p>你好,你好吗</p>
        <p>你好,不管怎样</p>
        <p>你好,测试一下</p>
      </div>
    </div>
  </body>
</html>
英文:

Not sure exactly what you’re after. I see that you’re trying to rotate the entire document (the HTML element). I am not at all surprised that doing so is causing problems.

If at all possible, try rotating specific elements rather than the entire document. For example, if you want the text to display in the centre of the viewport, then be rotated 90° counter-clockwise, you only need to rotate the wrapper div.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;html&gt;

&lt;head&gt;
  &lt;style&gt;
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      min-height: 100svh;
      border: 2px solid red;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .wrapper {
      border: 2px solid black;
      transform: rotate(-90deg);
    }
  &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div&gt;
      &lt;p&gt;hello how are you&lt;/p&gt;
      &lt;p&gt;hello whatever here&lt;/p&gt;
      &lt;p&gt;hello testing this&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月6日 11:19:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625273.html
匿名

发表评论

匿名网友

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

确定