【问题标题】:Scaling with css just leaves whitespace around使用 css 缩放只会留下空白
【发布时间】:2026-02-06 22:25:01
【问题描述】:

所以我想缩小一个 div,但是当我这样做时,它仍然占用相同数量的空间,但只有空白,然后它在中间很小。

但我希望它实际上占用更少的空间,并让上面和下面的元素更接近它。

这是问题的一个例子: HTML:

<h1>A title goes here</h1>
  <div>
    <span>Some text here</span><br>
    <span>Some text here</span><br>
    <span>Some text here</span><br>
    <span>Some text here</span><br>
    <span>Some text here</span><br>
    <span>Some text here</span><br>
  </div>
<p>And some more text here</p>

CSS:

div{
  width: fit-content;
  transform: scale(0.5);
}

代码笔:

https://codepen.io/Tobias-Hewel/pen/ExvdENN

【问题讨论】:

标签: css scale


【解决方案1】:

htmlbody 元素添加样式以重置所有空格。

html,
body {
  margin:0;
  padding:0;
  overflow-x:hidden;
}

【讨论】:

  • 这确实会删除屏幕边缘的任何空白,但这不是我要说的。这是与缩放有关的特定问题。