为什么一种形式的最后一个元素与第二种形式的第一个元素之间存在间隙?

2024-01-16

我有这个 html 文件:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ff5;
}

form {
  display: inline;
}

#nick_msg {
  background: #000;
  position: fixed;
  bottom: 0;
  width: 90%;
}

#nick {
  width: 20%;
}

#nick input {
  border: 0;
  padding: 10px;
  width: 10%;
  background: #00f;
}

#nick button {
  border: 0;
  padding: 10px;
  width: 10%;
  background: rgb(130, 224, 255);
}

#msg {
  width: 80%;
}

#msg input {
  border: 0;
  padding: 10px;
  width: 60%;
}

#msg button {
  border: 0;
  padding: 10px;
  width: 10%;
  background: rgb(130, 224, 255);
}

#messages {
  margin: 0;
  padding: 0;
  list-style-type: none;
  background: #fff;
}
<ul id="messages">
  <li>msg</li>
  <li>msg</li>
  <li>msg</li>
  <li>msg</li>
  <li>end</li>
</ul>
<div id='nick_msg'>
  <form id='nick' action="">
    <input id="n" /><button>Join</button>
  </form>
  <form id='msg' action="">
    <input id="m" autocomplete="off" /><button>Send</button>
  </form>
</div>

现在,我在“#nick button”和“#msg input”之间出现了间隙,如以下屏幕截图所示:

So, I made the content window exactly 1000px and took a look at the other elements. 900px for #nick_msg, 90px for #nick input and button and #msg button and 540px for #msg input, another 90px gap on the right (the black one and another 100px white gap on the outer right). The input and button tags get 10px padding on all sides, so their inner size should be 70px (and 520px for the big one). The form's size is shown as auto x auto, but selecting it only shows a selection box of size 180px or 630px as it should be. But still, there is a small gab between the two forms. I already tried to write both form tags on one line with no spaces in between, no change here. (not sure about this one anymore, because considering the accepted answer, this should have resolved the issue and in a later test I did, it actually DID.) So, what's causing the gap and what do I need to change to get rid of that gap?

浏览器:Opera 47.0.2631.55 Gentoo/Linux (x86_64)

注意:“#nick”的屏幕截图显示了一个更大的框,可以解释差距。一旦我把它放在第一位</button>首先</form>在同一条线上,之间没有空格,该框缩小,但间隙仍然存在。

更多截图:

  • https://i.stack.imgur.com/3bvGM.png https://i.stack.imgur.com/3bvGM.png(正文 - 上面内嵌的图像)
  • https://i.stack.imgur.com/W0ySx.png https://i.stack.imgur.com/W0ySx.png(#nick_msg)
  • https://i.stack.imgur.com/EaSBt.png https://i.stack.imgur.com/EaSBt.png (#nick)
  • https://i.stack.imgur.com/vErgd.png https://i.stack.imgur.com/vErgd.png(#nick 输入)
  • https://i.stack.imgur.com/z0O1u.png https://i.stack.imgur.com/z0O1u.png(#nick 按钮)
  • https://i.stack.imgur.com/jySAQ.png https://i.stack.imgur.com/jySAQ.png (#msg)
  • https://i.stack.imgur.com/EtMvq.png https://i.stack.imgur.com/EtMvq.png(#msg 输入)
  • https://i.stack.imgur.com/pUibf.png https://i.stack.imgur.com/pUibf.png(#msg 按钮)

Set font-size: 0给你的form看看魔法吧!

嗯,这是由于特征使用时元素之间的空间inline元素 - 请注意您已经给出display: inline给你的form.

浏览器样式为form元素将覆盖零字体大小,或者您可以自己使用font-size: initial.

请参阅下面的演示:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ff5;
}

form {
  display: inline;
  font-size: 0;
}

#nick_msg {
  background: #000;
  position: fixed;
  bottom: 0;
  width: 90%;
}

#nick {
  width: 20%;
}

#nick input {
  border: 0;
  padding: 10px;
  width: 10%;
  background: #00f;
}

#nick button {
  border: 0;
  padding: 10px;
  width: 10%;
  background: rgb(130, 224, 255);
}

#msg {
  width: 80%;
}

#msg input {
  border: 0;
  padding: 10px;
  width: 60%;
}

#msg button {
  border: 0;
  padding: 10px;
  width: 10%;
  background: rgb(130, 224, 255);
}

#messages {
  margin: 0;
  padding: 0;
  list-style-type: none;
  background: #fff;
}
<ul id="messages">
  <li>msg</li>
  <li>msg</li>
  <li>msg</li>
  <li>msg</li>
  <li>end</li>
</ul>
<div id='nick_msg'>
  <form id='nick' action="">
    <input id="n" /><button>Join</button>
  </form>
  <form id='msg' action="">
    <input id="m" autocomplete="off" /><button>Send</button>
  </form>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么一种形式的最后一个元素与第二种形式的第一个元素之间存在间隙? 的相关文章

随机推荐

  • 使用 torchtext 时出现 ImportError

    当我尝试运行这行代码时 出现以下错误 from torchtext data import Field TabularDataset BucketIterator Iterator ImportError cannot import nam
  • Gradle从哪个版本开始支持Java 17

    当尝试配置项目时 我收到错误 不支持 Java 您的构建当前配置为使用 Java 17 0 1 和 Gradle 7 0 不幸的是 没有信息官方文档 https docs gradle org current userguide compa
  • CAtlList::RemoveAt 是否会使现有的 POSITIONS 无效?

    我正在看这个 其中 m Rows 是 CAtlList void CData RemoveAll size t cItems m Rows GetCount POSITION Pos m Rows GetHeadPosition while
  • 如何按特定顺序自动启动程序?

    我的 i3 配置文件中有以下几行 Startup applications exec firefox exec gnome terminal exec nautilus 这些行按预期启动 firefox gnome terminal 和 n
  • Erlang 和带有西里尔字母的二进制

    我需要能够使用其中包含西里尔字符的二进制文件 我尝试只写 lt lt gt gt 但我收到了 badarg 错误 如何在 Erlang 中使用西里尔字母 或 unicode 字符串 如果你想输入上面的表达式erlang shell 请阅读u
  • 使用基于单选按钮值的 javascript(Node JS) 将数据插入 mysql(Sequelize)

    我有下面的 json 对象 phoneno field1 Mohamed field2 123456789 field3 Sameer field1 Ganesh field2 987654321 field3 Pandiyan sende
  • “现代”正则表达式的识别能力

    真正的现代正则表达式实际上可以识别哪一类语言 每当存在带有反向引用的无限长度捕获组时 例如 1 正则表达式现在匹配非常规语言 但这本身并不足以匹配类似的东西S S 匹配括号对的上下文无关语言 递归正则表达式 这对我来说是新的 但我确信 Pe
  • 如何为 NDK 工具链的 gcc 包含

    首先 我上次尝试将c程序编译到linux arm架构时遇到了一个问题 以便稍后在android应用程序中使用它 我成功地做到了这一点 稍后我将写一篇关于如何使用 NDK 独立工具链的文章 现在我终于开始工作了 我正在尝试编译一个 c 文件
  • 画半条无限直线?

    我使用 pyqtgraph 进行数据采集 并且必须在图形视图上表示一些阈值 例如表示高电压限制等 我使用了该类InfiniteLine来自 pyqtgraph 但现在 我必须考虑在采集过程中阈值可能发生的一些变化 它看起来像是两条无限线之间
  • 为什么 Dapper dot net 不自行打开和关闭连接?

    Dapper 隐式地期望连接在使用时打开 为什么它不自己打开和关闭 这不是简单的连接管理吗 我问这个问题是因为我和一位同事一直在反复探讨连接池幕后发生的事情的本质 以及在多个命令中保持连接打开或打开和关闭连接是否有任何好处对于每个命令 Da
  • python中zip档案的流式解压

    有没有办法对单文件 zip 档案进行流式解压缩 我目前在 s3 中有任意大的压缩存档 每个存档一个文件 我希望能够通过迭代来处理文件 而不必实际将文件下载到磁盘或内存中 一个简单的例子 import boto def count newli
  • 在android程序中下载gmail附件

    我尝试了很多搜索 最后在这里问 我需要写一段代码下载附件形成我的GMail 我怎样才能做到这一点 到目前为止 我可以阅读 发送电子邮件 但仍在弄清楚如何下载附件 任何帮助将不胜感激 附件不单独下载 它们是 MIME 多部分文档的一部分 您可
  • 使用 HTTParty 捕获特定请求

    我想在不使用代理的情况下捕获给定操作的完整请求 raw request 通过网络传输的内容 我知道类上的 debug output 方法 这可能是解决方案的一部分 但不清楚如何根据每个请求进行设置 考虑以下 response HTTPart
  • 黑莓中的正则表达式?

    如何在 Blackberry 中使用正则表达式验证电子邮件 Blackberry API 中没有 Pattern 类 有没有其他方法可以验证 谢谢 当前的 Blackberry API 中没有正则表达式 尝试这个 http code goo
  • 具有可变参数的回调函数 tkinter 按钮[重复]

    这个问题在这里已经有答案了 from tkinter import F Tk i 1 while i lt 10 newButton Button F text Show Number command lambda showNumber i
  • Python:Ramer-Douglas-Peucker(RDP)算法,用点数代替 epsilon

    我想修改以下 python 脚本RDP算法 https en wikipedia org wiki Ramer E2 80 93Douglas E2 80 93Peucker algorithm目的是不使用 epsilon 而是选择我想在决
  • 方案没有文件系统:cos

    我正在尝试从 IBM Data Science Experience 连接到 IBM Cloud Object Storage access key XXX secret key XXX bucket mybucket host lon i
  • 如何在 Azure 逻辑应用程序中使用 OAuth 2.0 身份验证?

    我正在尝试创建一个带有 FTP 触发器的简单逻辑应用程序 然后将任何上传的文件内容通过管道传输到我在 Azure 中托管并使用 OAuth 2 0 客户端凭据授予流进行保护的 Web API 如何在逻辑应用中配置 OAuth 2 0 身份验
  • 在 NestJS 微服务中公开正常的 http 端点

    我用 NestJs 编写了这个微服务 async function bootstrap const port parseInt process env PORT 5000 10 const app await NestFactory cre
  • 为什么一种形式的最后一个元素与第二种形式的第一个元素之间存在间隙?

    我有这个 html 文件 margin 0 padding 0 box sizing border box body margin 0 background ff5 form display inline nick msg backgrou