html - 让兄弟用完动态宽度元素的宽度

标签 html css google-chrome

这似乎只是 chrome 上的问题

我有两个元素应该共享固定宽度 div 的宽度。最右边将有一些动态生成的文本,并使用 css 设置样式以具有较大的填充,以便我在左侧有一些空间用于图标(示例中没有)。

我不希望最右边的元素换行或超出外部 div 最左边的 input 元素应该用完所有剩余空间。

HTML:

<div id = "outer" >
  <input type="text" class="theinput">
  <span class="thetext"> hello world </span>
</div>

CSS:

.theinput{
  width:auto;
}

.thetext{ 
  border-style: solid;
  border-width: 1px;
  border-color: blue;

  padding: 0px 0px 0px 25px
}

#outer{
  border-style: solid;
  border-width: 1px;
  border-color: black;

  display:inline-block;
  width:260px;
}

我实际看到的是,一旦我向第二个元素添加填充,它就会跨两行。

enter image description here

我想只使用 CSS 和 HTML 来做到这一点,而不为任何一个同级元素指定固定的(px 或 %)宽度

最佳答案

为什么不使用 display: flex 呢?这是你想要的吗?

.theinput {
  flex: 1;
  background-color: red;
}

.thediv {
  color: blue;
  border-style: solid;
  border-width: 1px;
  border-color: blue;
  padding: 0px 0px 0px 25px
}

#outer {
  border-style: solid;
  border-width: 1px;
  border-color: black;
  display: flex;
  width: 260px;
}
<div id="outer">
  <input type="text" class="theinput">
  <span class="thediv"> hello world fgfdgdfg</span>
</div>

关于html - 让兄弟用完动态宽度元素的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50879635/

相关文章:

html - Dreamweaver,画廊

html - 在 float 表之间插入空格/间隙

jquery - Bootstrap 三列顺序

javascript - jQuery 不能在 Chrome 中运行,但可以在 Firefox 中运行

google-chrome - 如何使用 Inno Setup 检查 Windows 计算机上是否安装了 Google Chrome

javascript - CSS 效果适用于静态表格数据,但当表格数据由 javascript 添加时效果不佳

html - 如何让我的 div 定位到我想要的位置,CSS

html - 我可以仅通过 CSS 将焦点转移到 div 吗?

html - H1 CSS 重置失败?

html - Chrome CSS 下拉菜单问题