2017-06-22 11 views
1

htmlは、固定div(ヘッダー)とロングテーブルの2つの部分で作成しました。テーブルには多くの列があるので、ヘッダーを常に上に保つことが不可欠であるため、ヘッダーを固定しました。ページがスクロールされると、固定された行を含むExcelスプレッドシートのように動作します。ヘッダーは常に上にとどまり、表はヘッダーの下にスクロールします。私はウィンドウをサイズ変更するまですべてうまく動作します。表はヘッダーに対して水平方向にスクロールしますが、ヘッダーはヘッダーとは一致しません。したがって、表のヘッダーと列の列名は一致しません。私の質問は、垂直にではなく水平にスクロールする固定divを作成することが可能かどうかです。水平にスクロールするが垂直にはスクロールしない固定divを作成する

以下

私のHTMLです:

<!DOCTYPE html> 
<head> 
    <title>Text</title> 
    <link rel="stylesheet" type="text/css" href="CSS.css"> 
</head> 

<body> 

<div id="nav_menu"> 
      <img id="SctnImage" src="ub.png"> 
      <p id="TileFistLine">Text</p> 
      <p id="TileSecLine">Text</p> 

      <table id="TblHead"> 
      <col width="90"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="45"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="40"> 
      <col width="45"> 
      <col width="45"> 
      <col width="42"> 
      <col width="42"> 
      <col width="40"> 

       <tr> 
        <td rowspan="2" id="C1">Designation <br> Click to download CAD</td> 
        <td rowspan="2" id="C2">Mass<br> kg/m</td> 
        <td rowspan="2" id="C3">Depth<br> h, mm</td> 
        <td rowspan="2" id="C4">Width<br> b, mm</td> 
        <td rowspan="2" id="C5">Web<br> s, mm</td> 
        <td rowspan="2" id="C6">Flange<br> t, mm</td> 
        <td rowspan="2" id="C7">Root Radius<br> r, mm</td> 
        <td rowspan="2" id="C8">Between fillets<br> d, mm</td> 
        <td colspan="2" id="C9">Local Buckling Ratios</td> 
        <td colspan="2" id="C10">Second Moment of Area</td> 
        <td colspan="2" id="C11">Radius of Gyration</td> 
        <td colspan="2" id="C12">Elastic Modulus</td> 
        <td colspan="2" id="C13">Plastic Modulus</td> 
        <td rowspan="2" id="C14">Buckling Param.<br> u</td> 
        <td rowspan="2" id="C15">Torsional Index<br>x</td> 
        <td rowspan="2" id="C15">Warping Const.<br> H, dm<sup>6</sup></td> 
        <td rowspan="2" id="C16">Torsional Const.<br> J, cm<sup>4</sup></td> 
        <td rowspan="2"id="C17">Area<br> A, cm<sup>2</sup></tp> 
       </tr> 

       <tr> 
        <td id="C11">b/2t</td> 
        <td id="C21">d/s</td> 
        <td id="C31">I<sub>x</sub>, cm<sup>4</sup></td> 
        <td id="C41">I<sub>y</sub>, cm<sup>4</sup></td> 
        <td id="C51">r<sub>x</sub>, cm</td> 
        <td id="C61">r<sub>y</sub>, cm</td> 
        <td id="C71">Z<sub>x</sub>, cm<sup>3</sup></td> 
        <td id="C81">Z<sub>y</sub>, cm<sup>3</sup></td> 
        <td id="C91">S<sub>x</sub>, cm<sup>3</sup></td> 
        <td id="C101"S<sub>y</sub>, cm<sup>3</sup></td> 
       </tr> 
      </table> 
</div> 

<div id="DataDiv"> 
     <table id="DataTable"> 
     <col width="90"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="45"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="40"> 
     <col width="45"> 
     <col width="45"> 
     <col width="42"> 
     <col width="42"> 
     <col width="40"> 

<?php 
     $dbconnection=mysqli_connect("localhost:3306", "root", "root", "sections"); 
     $myquery="SELECT * FROM sections.ub"; 
     $queryresults=mysqli_query($dbconnection, $myquery); 
     $tableraws=mysqli_num_rows($queryresults); // gets raws number from table 

     for ($i=1; $i<=$tableraws; $i++) { 
      $myrow=mysqli_fetch_row($queryresults); 
       echo "<tr class='DataRows'>"; 
       echo "<td class='DesignCell'><button type='button' class='DownButt'>".$myrow[1]."</button></td>"; 
       for ($k=2; $k<=23; $k++){ 
        echo '<td>'.$myrow[$k].'</td>'; 
       } 
       echo "</tr>"; 
     } 
?> 

</table> 

<div id="tail"></div>   

<?php   readfile("bottom_navi.html"); ?> 

</div> 

</body> 

そしてCSS.css:

*{ 
    font-family:arial; 
    font-size:10px; 
} 

#DataDiv { 
    position: relative; 
    top:172px; 
    margin-left: -8px; 
    margin-right: -8px; 
} 

#SctnImage { 
    display:inline; 
} 

#TileFistLine { 
    display: inline; 
    font-size: 50px; 
    position:absolute; 
    top: -20px; 
} 

#TileSecLine { 
    font-size: 12px; 
    position: absolute; 
    top: 80px; 
    left: 100px; 
} 

#TblHead { 
    top:120px; 
    width:1100px; 
    text-align:center; 
    font-size: 10px; 
    vertical-align: middle; 
    border-style: solid; 
    border-width: 1px; 
    border-collapse: collapse; 
    table-layout: fixed; 
    background-color:white; 
    position: fixed; 
    z-index: 1; 
} 

#DataTable { 
    border-collapse: collapse; 
    table-layout: fixed; 
    margin: auto; 
    width: 1100px; 
    text-align:center; 
    vertical-align:middle; 
    z-index: -1; 
} 

#nav_menu{ 
    width: 1100px; 
    height: 175px; 
    position:fixed; 
    right: 0; 
    left: 0; 
    margin-right: auto; 
    margin-left: auto; 
    top:0; 
    background-color:white; 
    z-index: 1; 
    display: inline; 
    } 

#tail{ 
    position:relative; 
    width:1100px; 
    height:40px; 
    margin:auto; 
    bottom: 0px; 
} 

tr, td { 
    border-style: solid; 
    border-width: 1px; 
    border-color: #99FFFF; 
} 

.DataRows:hover { 
      background-color: #E5F1FB; 
     } 

.DownButt { 
    width:90px; 
    height:23px; 
    padding: 0 0 0 0; 
    margin: 0 0 0 0; 
} 

.DesignCell{ 
    padding: 0 0 0 0; 
} 

#Navigation{ 
    width:1098px; 
    height:35px; 
    border: 1px solid; 
    border-color:#99FFFF; 
    position:fixed; 
    margin-left:auto; 
    margin-right:auto; 
    right: 0; 
    left: 0; 
    bottom:0px; 
    background-color:white; 
    z-index: 1; 
} 

#home_butt{ 
    position: relative; 
    top:3px; 
    left:4px; 
    height:30px; 
    width:90px; 
    padding: 0px; 
    margin: 0px; 
} 

#CountrySelector { 
    width: 150px; 
    position: relative; 
    left: 6px; 
    bottom: 7px; 
    height: 18px; 
} 

#SectSelector { 
    width: 150px; 
    position: relative; 
    left: 6px; 
    bottom: 7px; 
    height: 18px; 
} 
+1

あなたのhtmlコードを共有することができますか? – Archana

+0

@Archana、私は要求通りにコードを引用しました。 – Rat2good

答えて

1

あなたはこのような何かを探していますか?あなたは、私が示すことoverflow-xoverflow-yを使用していることがわかり、上記の例(scroll)で

.h-scroll { 
 
    position: fixed; 
 
    width: 200px; 
 
    height: 200px; 
 
    border: solid 1px black; 
 
    overflow-x: scroll; 
 
    overflow-y: hidden; 
 
}
<div class="h-scroll">Horizontal scroll</div>

または非表示(hidden

はそれが役に立てば幸いスクロールバー。

2
<!DOCTYPE html> 
<html> 
<head> 
<style> 

#header { 
height:20px; 
position:absolute; 
top:0; 
left:0; 
width:100%; 
background-color:#f5690f; 
color:white; 
} 
#body { 
height:90%; 
position:absolute; 
top:20px; 
left:0; 
width:100%; 
overflow:hidden; 
overflow-y:scroll; 
background-color:#672846; 
color:white; 
} 
</style> 
</head> 
<body> 

<div id=header>Header</div> 
<div id=body>Body1213213123213123213213212313123123213123213</br> 
</br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br> 
End 
</div> 

</body> 
</html> 
+0

あなたの例は素晴らしいです!しかし、これを私のコードに上記の方法で適用すると、余分なスクロールが両方向で起こります。あなたの例ではネイティブのブラウザウィンドウのスクロールだけが考えられます。 – Rat2good

+0

あなたのコードを試してみる私は、ブラウザウィンドウのサイズが変更されたときにヘッダーが水平にスクロールしないことに気付きました。これは達成したいものです。ヘッダーは常に上に置いて、必要に応じて左右にスクロールしたい。 – Rat2good

0

それはコードに従うことによって達成することができ、

overflow-x: scroll; 
overflow-y: hidden; 
関連する問題