jquery - 在 Internet Explorer 中表格的滚动条未显示在正确的位置

标签 jquery html css

我这里有一个嵌入的 jsfiddle(请在 IE 和其他主要浏览器中打开):

http://jsfiddle.net/6rCyH/51/embedded/result/

http://jsfiddle.net/6rCyH/51/ (正常的 fiddle ,所以你可以看到代码)

要使用 fiddle,只需多次点击“添加问题”,它就会在下表中添加行:

我的问题是列在 Safari、Opera、Chrome 和 Firefox 的主要浏览器中对齐正确,但在 IE 中对齐不正确。

每列的每个表格单元格包含相同的宽度,但我可以看到的问题是 IE 中的滚动条比其他浏览器中的滚动条更深入表格。我的问题是,将滚动条放在表格旁边的最佳方法是什么,这样它就不会导致其他列的对齐出现问题?该表应该是一个带有固定标题的滚动表。

代码如下:

HTML:

<div id="details">
    <table id="qandatbl" align="center" cellpadding="0" cellspacing="0" border="0">
      <thead>
        <tr>
          <th width="9%" class="qid">Question No</th>
          <th width="29%" class="question">Question</th>
          <th width="62%" class="optandans">Option and Answer</th>
        </tr>
      </thead>
    </table>
    <div id="qandatbl_onthefly_container">
    <table id="qandatbl_onthefly" align="center" cellpadding="0" cellspacing="0" border="0" width="100%">
      <tbody>
      </tbody>
    </table>
    </div>
  </div>

更新的 CSS:

#qandatbl_onthefly_container
{
    width:100%;
    overflow:scroll;
    max-height:600px;
}


#qandatbl, #qandatbl_onthefly{
    border:1px black solid;
    border-collapse:collapse;
    table-layout:fixed;
}
#qandatbl
{
    width:100%;
    margin-left:0;
}
#qandatbl_onthefly
{
    width:100%;
}

.qid {
    /*width:15%;*/
    font-weight:bold;
    border:1px black solid;
    border-collapse:collapse;
}

/*.question {
    width:30%;
    border:1px black solid;
    border-collapse:collapse;
}*/

.question {
    /*min-width:14%;
    max-width:14%;*/
    max-width:0.1%;
    border:1px black solid;
    border-collapse:collapse;
      line-height: 0;
}

.noofanswers{
    min-width:15%;
    max-width:15%;
    /*padding-top:5%;
    padding-bottom:5%;*/
}

.optandans{
    /*min-width:30%;
    max-width:30%;*/
    border:1px black solid;
    border-collapse:collapse;
}

.option{
    min-width:100%;
    max-width:100%;
    /*padding-top:5%;
    padding-bottom:5%;*/
}

.answer {
    min-width:100%;
    max-width:100%;
    /*padding-top:5%;
    padding-bottom:5%;*/
}

Jquery:

function insertQuestion(form)
{
//updated variables

var $tbody = $('#qandatbl_onthefly > tbody');
    var $tr = $("<tr class='optionAndAnswer' align='center'>");
    var $td = $("<td class='extratd'  width='62%'>");
    var $qid = $("<td class='qid' width='9%'></td>").text(qnum);
    var $question = $("<td class='question' width='29%'></td>");

.................
 function code here
.................

setWidth();

}

function setWidth() {
    var questionCellWidth = $("#qandatbl_onthefly tbody .question").width();
    console.log(questionCellWidth);
    var questionCellHeight = $("#qandatbl_onthefly tbody .question").height();
    $(".textAreaQuestion").css({
        "width": (questionCellWidth - 6) + "px",
        "height": (questionCellHeight) + "px"
    });
}

$(document).ready(function(){
var flag = true;
    if(flag == true)
    {
        var tbl_qanda = $("#qandatbl").width();
        $("#qandatbl").css({"width": (tbl_qanda - 16)+ "px"});
    }
    var tbl_qanda_onthefly = $("#qandatbl_onthefly").width();
    if(tbl_qanda > tbl_qanda_onthefly)
    {
         $("#qandatbl").css({"width": (tbl_qanda_onthefly - 16)+ "px"});
         $("#qandatbl_onthefly_container").css({"width": (tbl_qanda_onthefly)+ "px"});
    }
});

最佳答案

你需要对css做一些改变

我。在 #qandatbl 中添加 float:left;

二。在 #qandatbl_onthefly_container 添加 clear:both

三。在 .question textarea#qandatbl_onthefly_container 添加 overflow:auto

第三个与您的问题无关,但如果没有在 textarea 上滚动,在 ie 上看起来不太好。

关于jquery - 在 Internet Explorer 中表格的滚动条未显示在正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13872918/

相关文章:

jquery - TYPO3 9.5 表单框架 AJAX

jquery - 如何删除自动完成中的重复项

html - 如何保持两个并排的 div 元素高度相同?

html - 行高属性不适用于 tumblr 主题?

java - 找不到在 Scene Builder 中添加的 CSS StyleSheet

javascript - 在js文件中调用JQuery函数

php - Symfony 2 原型(prototype)内的原型(prototype) - 双 $$name 字段

javascript - 使用jquery在ul中添加li元素

jquery - 如何使用固定容器滚动 div 文本?

html - 如何控制 yii2 detailView 中的行高和单元格填充?