如何修复不可见的边距参数?

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

How to fix invisible margin parameter?

问题

以下是您要翻译的内容:

首先,我真的不懂CSS!我遇到了一些奇怪的问题...但首先让我向您展示我的应用程序。
这是屏幕:(左侧边栏展开)
[![在此输入图像描述][1]][1]

(左侧边栏隐藏)
[![在此输入图像描述][2]][2]

请注意周围带有网格的画布上的滚动条。这个滚动条看起来是这样的,因为它有margin-top和margin-left = 20。看看这个:
[![在此输入图像描述][3]][3]

如果我在那个地方删除这个margin,看看它会变成什么样:
[![在此输入图像描述][4]][4]

  [1]: https://i.stack.imgur.com/PVThO.png
  [2]: https://i.stack.imgur.com/k3mOI.png
  [3]: https://i.stack.imgur.com/ghozO.png
  [4]: https://i.stack.imgur.com/JEyma.png

正如您所看到的,一切看起来都很好。我需要在左边用调试器向您展示这个,因为如果我关闭它,这个margin就会立刻回来。我需要在右边用调试器向您展示这个,因为如果我关闭它,这个margin就会立刻回来。这是我“网格”部分的代码:

    <div id="justdraw" style="position: static; width: 1600px; height: 600px;">
        <!-- Diagram组件绑定到下面的canvas元素 -->
        <div id="ruler" style="position: static; width: 100%; height: 100%;">
            <div id="canvas" style="position: absolute; width: 1600px; height: 600px; margin-top: 0; margin-left: 0; overflow: scroll;">
                <canvas id="diagram" width="2100" height="2100">
                    此页面需要支持HTML 5 Canvas元素的浏览器。
                </canvas>
            </div>
        </div>
    </div>

我正在使用Thymeleaf片段,该代码是片段,并且在这里使用:

    <!-- 页面内容 -->
    <div id="content" style="position: relative;">
        <th:block th:include="diagramER :: diagram"/>
    </div>

有人可以告诉我这是什么原因吗?为什么浏览器中的样式显示与我在代码中看到的不同?
    
浏览器中的样式:

    element.style {
    position: absolute;
    width: 1600px;
    height: 600px;
    overflow: scroll;
    margin-top: 20px;
    margin-left: 20px;
    }

我的代码中的样式:

    <div id="canvas" style="position: absolute; width: 1600px; height: 600px; margin-top: 0; margin-left: 0; overflow: scroll">
英文:

for first i am really bad with css! I have strange problems... but firstly let me show you my app
Here is screen: (left sidebar expanded)
如何修复不可见的边距参数?

(left sidebar hidden)
如何修复不可见的边距参数?

Please take a look on scrollbar around that canvas covered with grid. This scrollbar look like that because it have margin-top and margin-left = 20. Look at this:
如何修复不可见的边距参数?

If i will delete this margin in that place, look how it will be look like:
如何修复不可见的边距参数?

As you can see everything look good. I needed to show you that with debbuger on my left side because if i close him then immediatly this margin come back. I needed to show that with debugger on my right side because if i close him then immediately this margin come back. Here is my code of that "grid" part:

&lt;div id=&quot;justdraw&quot; style=&quot;position: static; width: 1600px; height: 600px;&quot;&gt;
    &lt;!-- The Diagram component is bound to the canvas element below --&gt;
    &lt;div id=&quot;ruler&quot; style=&quot;position: static; width: 100%; height: 100%;&quot;&gt;
        &lt;div id=&quot;canvas&quot; style=&quot;position: absolute; width: 1600px; height: 600px; margin-top: 0; margin-left: 0; overflow: scroll&quot;&gt;
            &lt;canvas id=&quot;diagram&quot; width=&quot;2100&quot; height=&quot;2100&quot;&gt;
                This page requires a browser that supports HTML 5 Canvas element.
            &lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

I am using fragments Thymeleaf, that code is fragment and it is used here:

&lt;!-- Page Content  --&gt;
&lt;div id=&quot;content&quot; style=&quot;position: relative;&quot;&gt;
    &lt;th:block th:include=&quot;diagramER :: diagram&quot;/&gt;
&lt;/div&gt;

Can anyone tell me what could be the reason for this? How is it possible that the styles in the browser show something different than what I have in the code?

Styles from browser:

element.style {
position: absolute;
width: 1600px;
height: 600px;
overflow: scroll;
margin-top: 20px;
margin-left: 20px;
}

Styles from my code:

&lt;div id=&quot;canvas&quot; style=&quot;position: absolute; width: 1600px; height: 600px; margin-top: 0; margin-left: 0; overflow: scroll&quot;&gt;

答案1

得分: 1

这是不同于其他操作系统的地方,所以你应该自定义你的滚动条。

制作了一个快速示例:

::-webkit-scrollbar-track {
  display: none;
}

https://jsfiddle.net/p4mc70go/1/

英文:

It's different on other OS'.. so you should style your scrollbar

Made a quick sample:

::-webkit-scrollbar-track {
  display: none;
}

https://jsfiddle.net/p4mc70go/1/

huangapple
  • 本文由 发表于 2020年1月6日 21:32:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613037.html
匿名

发表评论

匿名网友

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

确定