html - 跨度重叠问题

标签 html css

大家好,我在让我的跨度按我想要的方式工作时遇到了一些问题。我在表格标题中有一个警报和一个搜索输入框,我希望搜索框向右浮动,警报填充搜索框左侧的其余空间。在附加的 plunker 中,我已经开始通过设置搜索框的宽度然后在警报上放置一个匹配的右边距来工作,但这似乎是一种非常肮脏的方式。

<span style="float:right;"><input class="form-control" style="margin-bottom: 0px;width:200px;" placeholder="global search ..." type="text" /></span>
<span class="alert alert-success" style="display:block;margin-right:210px;" role="alert">I don't want this to overlap the search</span>

有谁知道更好的方法来完成这个?这是我的 plunkr 的链接

最佳答案

如果你不喜欢边距,你可以计算宽度:

<th colspan="6">
  <span style="float:right;"><input class="form-control" style="margin-bottom: 0px;width:200px;" placeholder="global search ..." type="text" /></span>
  <span class="alert alert-success" style="display:block;width:calc(100% - 210px);" role="alert">I don't want this to overlap the search</span>
</th>

https://plnkr.co/edit/Aq45ZTXzR6i1vDEWEhSj?p=preview

在我看来,最简洁的选择是 flex 盒布局,因为这正是它的用途。

<th colspan="6">
  <div style="display:flex;align-items: stretch;justify-content: space-between;">
    <span class="alert alert-success" style="display:block;flex:1;margin-right:10px;" role="alert">I don't want this to overlap the search</span>
    <input class="form-control" style="margin-bottom: 0px;width:200px" placeholder="global search ..." type="text" />
  </div>
</th>

https://plnkr.co/edit/Aq45ZTXzR6i1vDEWEhSj?p=preview

关于html - 跨度重叠问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36067905/

相关文章:

javascript - 有没有办法防止在html中重复代码我正在使用bootstrap 4在一页中折叠20次

html - 如何将相对大小的子元素保持在父元素的边界内?

javascript - 如何使用 Bootstrap 添加多个模态图像

html - [class$ =""] 和 [id* =""] 有什么特殊性?

javascript - 发出AJAX请求时如何显示进度?

javascript - 文本溢出 :ellipsis doesn't work on in Table cell hyper links

html - 根据右侧 div 的位置垂直对齐左侧 div 的文本

html - ul li 内图像的垂直对齐

javascript - 无法检测 Android Barcode Scanner 输入、JavaScript 的关键事件

html - 2个跨度之间的边距