【问题标题】:Table inside the div tag is overflowing to outside of the divdiv 标签内的表格溢出到 div 之外
【发布时间】:2017-08-14 11:36:18
【问题描述】:

我想将表格保留在 div 标记内,但最后一部分的一半丢失了。 这是我用过的html结构,

 .dataTable{
    	table-layout: fixed;    	   	
    }
    .dataTable td{    	
    	white-space: nowrap;
    	overflow: hidden;
    	text-overflow: ellipsis;
    }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
     <div class="col-md-12">
      <table class="dataTable">
        <tr>
          <th>Company</th>
          <th>Contact</th>
          <th>Country</th>
        </tr>
        <tr>
          <td>Alfreds Futterkiste</td>
          <td>Maria Anders</td>
          <td>Germany</td>
        </tr>
        <tr>
          <td>Centro comercial Moctezuma</td>
          <td>Francisco Chang</td>
          <td>Mexico</td>
        </tr>
      </table>
     </div>
    </div>
    
</body>
</html>

问题我所面临的

谁能帮我解决这个问题?

【问题讨论】:

  • 尝试删除overflow: hidden;
  • 尝试移除溢出:隐藏;以为它会在底部添加一个滚动条,如果您不希望这样,请减小其中一列的宽度
  • 尝试为此提供jsfiddle链接。
  • 当我删除overflow: hidden;' it goes over other td`s
  • 您在问题中拥有的数据与图像中使用的数据量不同。 3 cols 而不是 5 cols。你能解决这个问题吗?这就是我得到的jsfiddle.net/gkktq81t/1

标签: html css twitter-bootstrap datatable


【解决方案1】:

试试这个:

.dataTable{
    table-layout: fixed;
    width: 100%;            
}

希望对你有帮助...

【讨论】:

    【解决方案2】:

    试试这个:

     $(document).ready(function () {
            $('#YourTable').DataTable({
                "scrollX": true,
                     });
            });
    

    【讨论】:

      猜你喜欢
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      相关资源
      最近更新 更多