html - Google Chrome 中的不同行为

标签 html css

这是我的 html 文件。

<BODY>
    <button id="b1" onclick="load()">Play</button>
    <canvas id="c1" onclick="f_clicked(this.id,1)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <canvas id="c2" onclick="f_clicked(this.id,2)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <canvas id="c3" onclick="f_clicked(this.id,3)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <br>
    <canvas id="c4" onclick="f_clicked(this.id,4)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <canvas id="c5" onclick="f_clicked(this.id,5)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>
    <canvas id="c6" onclick="f_clicked(this.id,6)">
        Your browser does not support the HTML5 canvas tag.
    </canvas>

</body>

这是我的 css 文件

body{
    background - color: gray;
}
button {
    height: 40px;
    width: 40px;
}
canvas {
    width: 100px;
    height: 100px;
    border: 1px solid #000000; display:none; }

预期结果: 第一行中的前 3 个 Canvas 元素。 第二行接下来的 3 个 Canvas 元素。每个 Canvas 元素之间的间距为 20px。

在 Chrome 中: 我得到了第一行的预期结果。但是第二行元素之间存在折叠。 Firefox:我得到了两行的预期结果。

有谁知道为什么 chrome 的行为不同??

最佳答案

删除

</br>

相反,将您的 2 组 Canvas 包裹在 div 中,因为它们是 display: block;另一组将被强制关闭,模拟你的 br 将要做什么,只是它没有
的空间量。

<body>
<div id="set-one">
<button id="b1" onclick="load()">Play</button>
<canvas id="c1" onclick="f_clicked(this.id,1)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
<canvas id="c2" onclick="f_clicked(this.id,2)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
<canvas id="c3" onclick="f_clicked(this.id,3)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
</div>
<div id="set-two">
<canvas id="c4" onclick="f_clicked(this.id,4)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
<canvas id="c5" onclick="f_clicked(this.id,5)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
<canvas id="c6" onclick="f_clicked(this.id,6)">
    Your browser does not support the HTML5 canvas tag.
</canvas>
</div>

这样,您将拥有您想要/需要的 2 套 Canvas ,很可能没有空间。

关于html - Google Chrome 中的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20756780/

相关文章:

javascript - 悬停在文本上方时禁用鼠标指针文本选择器

javascript - 仅对类中的一个单击元素执行操作

html - 不要从缓存中加载 HTML 页面

javascript - 使用 jQuery 将事件附加到动态创建的选定选择

css - Laravel - barryvdh pdf - 如何将外部 css 文件包含到 html View 中

javascript - 使页面居中不适用于正文选择器,但适用于 div 页面换行

html - Flex 如何显示保持垂直对齐的元素表

css - 如何使我的 <legend> 标记在 Internet Explorer 中的显示与在其他浏览器中的显示相同?

css - Bootstrap网格图像问题高度元素

html - 如何更改 Bootstrap 导航菜单颜色?