[英]How to fix the position of the div tag at center of the page. using javascript
[英]how to fix the position of div tag in a table
这是你想要的?
html
<div class="fixed-header-table">
<header>
<table>
<tr>
<th>headline1</th>
<th>headline2</th>
<th>headline3</th>
<th>headline4</th>
<th>headline5</th>
</tr>
</table>
</header>
<div class="content">
<table>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
<tr>
<td>val1</td>
<td>val2</td>
<td>val3</td>
<td>val4</td>
<td>val5</td>
</tr>
</table>
</div>
</div>
CSS
.fixed-header-table {
/*
500px (5 columns a 100px) + 20px extra for the scroll-bar.
This is kind of a random value because the scroll bar
has a different width depending on the operating system
and browser. It is probably better to calculate this using js.
*/
width: 520px;
}
th,
td {
/*
If you need this to be different for each column you have
to set the value accordingdly for each column separately.
If you need the width to be dynamic use js to calculate it.
*/
width: 100px;
}
th {
text-align: left; /*default is center*/
}
header {
/*
same value as the scroll bar width - this makes sure
the header is not wider than the content, since it has
no scroll-bar
*/
padding-right: 20px;
}
.content {
overflow-y: auto;
height: 90px; /*this is set to demonstrate scrolling behavior*/
}
.content table {
/*
without setting an explicit width the tables will use
the whole width available and thus the header and content
columns will not be aligned properly
*/
width: 500px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.