jquery - 表格和带标签的 div 之间的空白

标签 jquery html css

我有这个带有 RowFilter 函数的表,我显示一条消息表示没有找到结果,这条消息是隐藏 div 内的标签,问题是出现了 thead 元素,下一行应该是带有标签的 div但不是,出现一个空格,然后是标签。我试图解决这个问题,将 padding 0% 添加到我的标签,然后添加到 div,但没有任何效果。

这是我的代码:

$(document).ready(function () {
  RowFilter();
});

function RowFilter() {
    var busqueda = document.getElementById('buscar');
    var noResults = document.getElementById('no-results');
    var table = document.getElementById("Tabla2").tBodies[0];

    buscaTabla = function () {
        texto = busqueda.value.toLowerCase();
        var match = false;
        var r = 0;
        while (row = table.rows[r++]) {
            if (row.innerText.toLowerCase().indexOf(texto) !== -1) {
                row.style.display = null;
                match = true;
            }
            else {
                row.style.display = 'none';
            }
        }
        if (!match) {
            noResults.style.display = 'block';
        }
        else {
            noResults.style.display = 'none';
        }
    }
    busqueda.addEventListener('keyup', buscaTabla);
}
 #no-results {
            display: none;
            text-align: center;
            font-weight: bold;
        }
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
  <input class="form-control" placeholder="Search..." id="buscar" type="text"/>
</div>

<hr />
<table id="Tabla2" class="table table-striped">
  <thead>
    <tr class="info">
      <td>ID</td>
      <td>Name</td>
     <td>Description</td>
    </tr>
  </thead>
  <tbody>
    <tr>  
      <td>1</td>
      <td>Mike</td>
      <td>N/A</td>
    </tr>
    <tr>  
      <td>2</td>
      <td>Steven</td>
      <td>N/A</td>
    </tr>
    <tr>  
      <td>3</td>
      <td>Tyler</td>
      <td>Active</td>
    </tr>
  </tbody>
</table>
<div id="no-results" >
  <label style="width:100%; margin-top:0%;" class="control-label label-warning">No results found... </label>
</div>

Pen with code

最佳答案

Bootstrap 的表是一个 margin-bottom: 20px .您可以超过此值(设置为 0)或将标签的顶部边距设置为 -20px .

选项#1:

<table id="Tabla2" class="table table-striped" style="margin-bottom: 0">

选项#2:

<div id="no-results" style="margin-top: -20px;">

在我看来,由于 bootstrap 的布局会影响您的所有布局,在这种情况下最好更改 margin-topno-result分区
这是一个工作代码笔:http://codepen.io/anon/pen/pbrvQm

关于jquery - 表格和带标签的 div 之间的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39171088/

相关文章:

html - 图像按钮在表格单元格内不可见

javascript - Jquery 效果在鼠标悬停时显示 <li><a> 菜单元素的溢出文本

javascript - jQuery、JavaScript : several forms same submit button text - how to determine value of closest hidden value box

javascript - JQuery 工具提示自定义悬停元素以显示在图像 map 上方

javascript - AJAX、JS 和 Select2 的问题

html - 在 Angular 项目中格式化 HTML。强制 vscode 中的 wrapAttributes 仅适用于 Angular 组件标签

javascript - 叠加的最佳方式

javascript - 使用 jQuery 在增量 ID 输入之间进行迭代

html - 使用 CSS 将段落与图标对齐

html - Wordpress - 使后端更加用户友好。自定义字段?