html - 表中的列在应用程序中未对齐

标签 html css

我无法将表格中的列与其表格标题对齐,奇怪的是这里的 Jsfiddle 中对齐没有问题:http://jsfiddle.net/m4HB3/68/

但在我使用完全相同代码的应用程序中,它没有将列与其标题正确对齐:application

我的问题是我需要在应用程序中包含什么才能解决应用程序中的对齐问题?

代码如下:

HTML:

<table id="tableqanda" cellpadding="0" cellspacing="0">
    <thead>
    <tr>
        <th width="5%" class="questionno">Question No</th>
        <th width="23%" class="question">Question</th>
        <th width="7%" class="option">Option Type</th>
        <th width="6%" class="noofanswers">Number of Answers</th>
        <th width="7%" class="answer">Answer</th>
        <th width="6%" class="noofreplies">Number of Replies</th>
        <th width="6%" class="noofmarks">Number of Marks</th>
        <th width="11%" class="image">Image</th>
        <th width="11%" class="video">Video</th>
        <th width="11%" class="audio">Audio</th>
    </tr>
    </thead>
    </table>
    <div id="tableqanda_onthefly_container">
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
    <tbody>
        <tr class="tableqandarow">
        <td width="5%" class="questionno">Question No.</td>
        <td width="23%" class="question">Question</td>
        <td width="7%" class="option">Option</td>
        <td width="6%" class="noofanswers">Number of Answers</td>
        <td width="7%" class="answer">Answer</td>
        <td width="6%" class="noofreplies">Number of Replies</td>
        <td width="6%" class="noofmarks">Number of Marks</td>
            <td width="11%" class="image"><ul><li>Image</li></ul></td>
        <td width="11%" class="video"><ul><li>Video</li></ul></td>
        <td width="11%" class="audio"><ul><li>Audio</li></ul></td>
</tr>
    </tbody>
    </table>
    </div>

CSS:

#tableqanda_onthefly_container
{
    max-height: 25px;
    width: 100%;
    overflow-y: scroll;
}


#tableqanda_onthefly
{
    width:100%;
    clear:both;
    table-layout: fixed;
}

#tableqanda_onthefly td
{
    border:1px black solid;
    border-collapse:collapse;
}

#tableqanda, #tableqanda_onthefly{
    border:1px black solid;
    border-collapse:collapse;
    word-wrap:break-word;
}       

#tableqanda{
    width:97%;
    margin-left:0;
    table-layout: fixed;
    float:left;
}

#tableqanda td { 
    vertical-align: middle;
    border:1px black solid;
    border-collapse:collapse;
}

#tableqanda th{
    border:1px black solid;
    border-collapse:collapse;
    text-align:center;
}

.tableqandarow{
    border:1px black solid;
    border-collapse:collapse;
}


.imagetd{
    font-size:75%;  
}

.audiotd{
    font-size:75%;  
}

.videotd{
    font-size:75%;  
}

.qandaul{
    list-style-type:square;
}

ul, ul li { margin: 0; padding: 0; }
ul { margin-left: 1.3em; }

最佳答案

您的列宽加起来不等于 100%;如果将其留给浏览器来解决,则无法确定对齐方式是否与您的想法相匹配。

将宽度更改为总和为 100%,您应该没问题。

关于html - 表中的列在应用程序中未对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514432/

相关文章:

html - img::after 在 src 改变时消失

css - 为什么在使用 flex 时样式标签也得到 "style"?

css - 字体大小和设备像素比

html - 重叠的 html 表单

javascript - 单击按钮时如何使 ul 按钮文本淡入淡出?

css - Bootstrap 3 : switching navbar with 2 rows on desktop to navbar with one row on mobile

css - 左对齐内容和自动调整大小的 div

html - 如何在没有 CSS 的情况下从表情符号中删除颜色

javascript - 将 html 插入到 contenteditable 中,但在其后添加新文本

javascript - 滚动时将 div 粘在屏幕顶部