【问题标题】:Small error in html/CSS formatting to freeze first column in PHP generated SQL tableshtml/CSS 格式中的小错误冻结 PHP 生成的 SQL 表中的第一列
【发布时间】:2018-08-09 04:49:35
【问题描述】:

我有一个似乎没有人能够修复的琐碎错误,但我确信它非常简单并且可能与 CSS 相关。

我希望冻结/修复第一列(即用户名),以便用户滚动浏览其他列(测试,其中有很多)。

这现在有效,但用户名的位置与表的其余部分不同步。

看起来像这样:

它应该看起来像:

PHP 和 HTML 代码:

<?php  }elseif(isset($_POST['quiz']) && $_POST['quiz'] == "non" && $err == ""){ ?>

                <div class="col-sm-12">
            <div class="table-responsive">
                    <table class="table table-bordered table-striped table-condensed" id="table">

                    <thead>
                        <tr>
                            <td width="3%"></td>
                        <?php
                            $all_quizes = mysqli_query($con,"SELECT * FROM quizes ORDER BY FIELD(quiz_level, 'Beginner','Intermediate','Advanced'),quiz_name ASC");
                            $quizes = array();
                            while($my_rows = mysqli_fetch_array($all_quizes)){
                                array_push($quizes,$my_rows);
                            }
                            foreach($all_quizes as $record){
                        ?>

                        <th width="30%"><?php echo $record['quiz_name']; ?></th>
                        <?php } ?>
                        </tr>
                    </thead>

                    <tbody>
                    <?php foreach(@$result as $record){?>
                    <tr>

                        <td class="headcol"><?php echo $record["username"];?></td>
                            <?php
                            $counter=0;
                            echo "&nbsp;&nbsp;&nbsp;";
                            while(mysqli_num_rows($all_quizes) > $counter){
                                $current_td = mysqli_query($con,"SELECT * FROM quiz_takers WHERE username='".$record["username"]."' AND quiz_id=".$quizes[$counter][0]." ORDER BY marks DESC");
                                $td = mysqli_fetch_array($current_td);

                                if($td['percentage'] == null){

                                    echo "<td> ?</td>";
                                }else{
                                    if(intval($td["percentage"]) >= 0 && intval($td["percentage"]) <= 30){
                                        $color = 'red';
                                    }elseif(intval($td["percentage"]) > 30 && intval($td["percentage"]) <= 70){
                                        $color = '#ffbf00';
                                    }elseif(intval($td["percentage"]) <= 30){

                                    }else{
                                        $color = 'green';
                                    }
                                    echo "<td style='color:".$color."'>".round($td["percentage"],2)."%</td>";

                                }

                                $counter++;
                            }
                            /*foreach($current_td as $td){
                                echo $counter." ".$td['username'] . " - ".$quizes[$counter]['3']."<br>";
                                if($quizes[$counter]['0'] == $td['quiz_id']){
                            ?>
                            <td><?php echo $td["percentage"];?></td>
                            <?php  } $counter++;}*/ ?>
                    </tr>
                        <?php  } ?>


                    </tbody>


                    </table>
                </div>
            </div>

当前的css是:

<style>



.headcol {

  position:absolute;
  height:100px;

  width: 5em;
  left: -10;


  overflow-x: scroll;
  margin-left: 5em;

  padding: 0;

  top: 2;
  border-top-width: -2px;
  /*only relevant for first row*/
  margin-top: -90px;
  /*compensate for top border*/
}



</style>

有人可以提出解决方案或修复方法吗?

【问题讨论】:

  • 我很想使用两张表——一张用于用户名,另一张用于其他数据
  • 谢谢,您能使用我现有的代码发布一个两表解决方案吗?

标签: php html css html-table freeze


【解决方案1】:

我认为问题来自第一标题行的第一列,您将其定义为 3% 的宽度。这个宽度应该等于.headcol的宽度

类似的东西

<thead>
  <tr>
    <td width="5em"></td> //equal to the width of .headcol

此外,您可能需要调整 .headcol 的 CSS 以便更好地对齐,也许可以输入 left: 0;

【讨论】:

  • 嗨 - 刚试过这个,你建议的两件事,但根本没有改变。还有其他想法吗?!请注意,问题不在于 head-col 的宽度,而在于定位。它浮动在中间,而不是固定在左侧,与表格中的其他列和行对齐
  • 我的意思是把left: 0;,对不起上面的回答!
  • 我刚做了这个codepen.io/huuvan20/pen/gvqjBZ。基本上,我将position: absolute; 更改为position: fixed;,这样更好。请根据自己的作品玩转。
  • 左:0;甚至 left:-10 只会稍微向左移动它。仍然没有区别:(
  • Huu Van Tran- 谢谢,是的,我也做过类似的事情,请参阅:teachingcomputing.com/testandtrack_tc/testingpage.php ,,,它实现了您所做的,但我需要将它与我现有的代码集成(即生成行等的php)。
猜你喜欢
  • 2021-01-12
  • 1970-01-01
  • 2015-11-14
  • 2017-12-17
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 2013-09-09
相关资源
最近更新 更多