How can I make columns in two tables have the same width?
I tried applying the width property on the td element for each column and the property style = "table-layout: fixed; but as you can see, the boundaries of the columns do not match.
JSFiddle: https://jsfiddle.net/v2bxdygj/
Here is my sample which works to some extent:
table {
border: 1px solid grey;
border-collapse:collapse;
width: 100%;
table-layout:fixed;
}
td {
border: 1px solid grey;
padding-left: 5px;
padding-right: 5px;
white-space: nowrap;
}
td span {
white-space: nowrap;
}
.code {
width: 40px;
}
.name {
width: 548px;
}
.colspan {
width: 588px;
}
.col3, .col4, .col5 {
width: 10%;
}
<table>
<tr>
<td class="code"><button>Код</button></td>
<td class="name"><button>Название</button></td>
<td class="col3"> </td>
<td class="col4"> </td>
<td class="col5"> </td>
</tr>
<tr>
<td class="colspan" colspan="2"><input type="text"> <span>Фильтр по коду и названию...</span></td>
<td class="col3">Разрешено</td>
<td class="col4">Запрещено</td>
<td class="col5">Неопределено</td>
</tr>
</table>
<table>
<tr>
<td class="code">1</td>
<td class="name">Вход в систему</td>
<td class="col3"> </td>
<td class="col4"> </td>
<td class="col5"> </td>
</tr>
<tr>
<td>2</td>
<td>Редактирование, администрирование групп и пользователей</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>3</td>
<td>Создание или редактирование определения адресного элемента</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>4</td>
<td>Создание или редактирование записи адресного элемента</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Related
I have a matrix which, because of the subjects names, is stretching off screen
I wish to create a training matrix with the abilities on the left, colored cells for the acquired skill, with the subjects name vertically across the columns.
I have tries using bootstrap and css rules to rotate text, but I cant get the text to float above the grid
apologies, this is what I have tried :
<style>
.rotate {
transform: rotate(90deg);
width: 8rem;
}
</style>
</head>
<body>
<div class="row">
<div class="col">
<table class="table">
<tr> <td> </td>
<tr> <td> <p class="text-nowrap bd-highlight rotate ">Bruce Wayne. </p> </td>
<tr> <td> <p class="text-nowrap bd-highlight rotate ">Clark Kent.</p> </td>
<tr> <td> <p class="text-nowrap bd-highlight rotate ">Barry Allen.</p> </td>
</tr>
<tr> <td> Detective</td> <td class="table-success"> </td> <td class="table-success"></td> <td class="table-success"></td> </tr>
<tr> <td> can fly</td> <td class="table-success"> </td> <td class="table-success"></td> <td class="table-success"></td> </tr>
<tr> <td> runs fast</td> <td class="table-success"> </td> <td class="table-success"></td> <td class="table-success"></td> </tr>
<tr> <td> plays well</td> <td class="table-success"> </td> <td class="table-success"></td> </tr>
</table>
all the vertical text stacks to the left of the screen.
Is this what you wanted?
.table {
background: grey;
border-spacing: 5px;
border: none;
width: 500px;
}
.rotate {
transform: rotate(90deg);
width: 8rem;
}
td {
width: 25%;
border: 2px solid black;
padding: 10px;
position: relative;
}
.vertical {
transform: rotate(90deg);
position: absolute;
top: 200%;
left: 0;
right: 0;
color: #fff;
font-weight: bold;
font-size: 18px;
text-transform: uppercase;
white-space: nowrap;
}
.
<body>
<div class="row">
<div class="col">
<table class="table">
<tr>
<td> Detective</td>
<td class="table-success"><span class="vertical"> Bruce Wayne</span> </td>
<td class="table-success"><span class="vertical"> clark Kent</span></td>
<td class="table-success"><span class="vertical"> barry allen</span></td>
</tr>
<tr>
<td> can fly</td>
<td class="table-success"> </td>
<td class="table-success"></td>
<td class="table-success"></td>
</tr>
<tr>
<td> runs fast</td>
<td class="table-success"> </td>
<td class="table-success"></td>
<td class="table-success"></td>
</tr>
<tr>
<td> plays well</td>
<td class="table-success"> </td>
<td class="table-success"></td>
<td class="table-success"></td>
</tr>
</table>
You haven't given your code how you did it but I give you a solution. Hope this is useful for you.
.rotate{
transform: rotate(-90deg);
}
<table>
<tr>
<td class="rotate">BRUCE</td>
<td class="rotate">CLARK</td>
<td class="rotate">BARRY</td>
</tr>
</table>
I'm making a table and I got a few problems that I can't solve without help,namely:
I need all <td> to be the same height as it's respective <tr>. height:100% doesn't work for all <td> for some reason, however fixed height works.
<tbody> is smaller than <table> itself which leads to the gap on the right side.
I want all borders to be 1px, but some of them are more bold. How do I make them all uniform?
https://codepen.io/NoOneKnowsWhoIam/pen/rzweRV
* {
box-sizing: border-box;
}
.caption {
background: yellow;
padding: 5px;
}
table {
border-collapse: collapse;
border: 1px solid black;
width: 400px;
display: block;
margin: 0 auto;
background: grey;
}
.quarter-width {
width: 25%;
}
.half-width {
width: 50%;
}
.third-width {
width: 33.33333333333333%;
}
td {
padding: 5px;
width: 100%;
height: 100%;
border: 1px solid black;
display: inline-block;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
<table>
<tbody>
<caption class="caption"><b>ST CLARE ZNNR5</b></caption>
<tr>
<td><b>11:39 01.07.2017</b></td>
</tr>
<tr>
<td class="half-width"><b>MMSI 235002514</b></td>
<td class="half-width text-right"><b>IMO 09236949</b></td>
</tr>
<tr>
<td>
<b>
Пассажирское судно, в пути<br>
86 м × 18 м × 2.5 м
</b>
</td>
</tr>
<tr>
<td class="half-width">
Координаты<br>
<b>50 47. 2000 N</b><br>
<b>001 06. 4000 W</b>
</td>
<td class="half-width text-right">
Время с момента получения отчета<br>
<b>9 с</b>
</td>
</tr>
<tr>
<td class="half-width">
Пункт назначения<br>
<b>Port Fish</b>
</td>
<td class=" fixim half-width text-right">
Расчетное время прибытия<br>
<b>
2017-07-01 17:15
<b>(UTC)</b>
</b>
</td>
</tr>
<tr class="text-center">
<td class="quarter-width">
COG<br>
<b>329°</b>
</td>
<td class="quarter-width">
COG<br>
<b>329°</b>
</td>
<td class="quarter-width">
HDG<br>
<b>323°</b>
</td>
<td class="quarter-width">
LOG<br>
<b>_</b>
</td>
</tr>
<tr>
<td><b>Спланированный маршрут</b></td>
</tr>
<tr>
<td class="third-width"><b>ПТ №1</b></td>
<td class="third-width">
Tдв<br>
<b>12:57:19</b>
</td>
<td class="third-width">
D<br>
<b>40.162 миль</b>
</td>
</tr>
<tr>
<td>Рассчитать маршрут</td>
</tr>
</tbody>
</table>
Delete display: inline-block; from the rule for td - this cancels their table-cell property, causing the problems you describe:
* {
box-sizing: border-box;
}
.caption {
background: yellow;
padding: 5px;
}
table {
border-collapse: collapse;
border: 1px solid black;
width: 400px;
display: block;
margin: 0 auto;
background: grey;
}
.quarter-width {
width: 25%;
}
.half-width {
width: 50%;
}
.third-width {
width: 33.33333333333333%;
}
td {
padding: 5px;
width: 100%;
height: 100%;
border: 1px solid black;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
<table>
<tbody>
<caption class="caption"><b>ST CLARE ZNNR5</b></caption>
<tr>
<td><b>11:39 01.07.2017</b></td>
</tr>
<tr>
<td class="half-width"><b>MMSI 235002514</b></td>
<td class="half-width text-right"><b>IMO 09236949</b></td>
</tr>
<tr>
<td>
<b>
Пассажирское судно, в пути<br>
86 м × 18 м × 2.5 м
</b>
</td>
</tr>
<tr>
<td class="half-width">
Координаты<br>
<b>50 47. 2000 N</b><br>
<b>001 06. 4000 W</b>
</td>
<td class="half-width text-right">
Время с момента получения отчета<br>
<b>9 с</b>
</td>
</tr>
<tr>
<td class="half-width">
Пункт назначения<br>
<b>Port Fish</b>
</td>
<td class=" fixim half-width text-right">
Расчетное время прибытия<br>
<b>
2017-07-01 17:15
<b>(UTC)</b>
</b>
</td>
</tr>
<tr class="text-center">
<td class="quarter-width">
COG<br>
<b>329°</b>
</td>
<td class="quarter-width">
COG<br>
<b>329°</b>
</td>
<td class="quarter-width">
HDG<br>
<b>323°</b>
</td>
<td class="quarter-width">
LOG<br>
<b>_</b>
</td>
</tr>
<tr>
<td><b>Спланированный маршрут</b></td>
</tr>
<tr>
<td class="third-width"><b>ПТ №1</b></td>
<td class="third-width">
Tдв<br>
<b>12:57:19</b>
</td>
<td class="third-width">
D<br>
<b>40.162 миль</b>
</td>
</tr>
<tr>
<td>Рассчитать маршрут</td>
</tr>
</tbody>
</table>
I'm trying to make some kind of "menu", but my menu items have too large heights in IE. Tested it on chrome, firefox and safari and it's working fine. What's wrong with my code? Please help. I just want them to be "fixed" 2em in height, is it possible in ie? And I wonder, is it an error in my page or just an IE bug?
window.onload=init;
window.onpageshow=init;
function init()
{
var main=document.getElementById("mainview");
var str=String.fromCharCode(Math.round( Math.random()*(90-65))+65);
var chr;
for(var i=0;i<20000;i++)
{
chr=String.fromCharCode(Math.round(Math.random()*(122-97))+97);
if(chr!="<") str=str+chr;
if(Math.random()<0.02)
{ chr=". "+String.fromCharCode(Math.round(Math.random()*(90-65))+65);
}
if(Math.random()<0.2)
{ str+=" ";
}
str+=chr;
}
main.innerHTML=str;
}
table
{ width: 100%;
border-collapse: collapse;
border-spacing: 0px;
padding: 0;
background-color: #fff;
table-layout: fixed;
}
tr.first
{
background-color: #000;
height: 2em;
}
tr.space
{
height: 1em;
}
td.lmargin
{
width: 3em;
}
td.label
{
width: 10em;
height: 4em;
background-color: #c30425;
}
td.menu
{
padding-left: 2em;
vertical-align: middle;
height: 2em;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
}
td.dummy
{
height: auto;
}
td#mainview
{
padding-left: 2em;
}
<table>
<tr class="first">
<td class="lmargin">
</td>
<td rowspan="2" class="label">
</td>
<td>
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td>
</td>
</tr>
<tr class="space">
<td class="lmargin">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="menu">
Menu item 1
</td>
<td rowspan="6" id="mainview">
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="menu">
Menu item 2
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="menu">
Menu item 3
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="menu">
Menu item 4
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="menu">
Menu item 5
</td>
</tr>
<tr>
<td class="lmargin">
</td>
<td class="dummy">
</td>
</tr>
</table>
Update: found the reason
https://support.microsoft.com/en-us/kb/2312750
The ROWSPAN property is disabled in Internet Explorer 8 if a webpage contains a tag in a table cell
It seems IE does not allow right cell to be larger than the left cell. Open developer console on IE (press F12) change
<td id="mainview" rowspan="6">
to
<td id="mainview" rowspan="1">
and see the differences.
I would like to create rowspan on my sticky header but can't get it work.
JsFiddle: http://jsfiddle.net/x62v5ea8/1/
What i need is to connect first and second td in 'Header 1'
Can someone help me with this problem ?
HTML
<div class="my-wrapper">
<div class="my-scroller">
<table class="myTable">
<thead>
<tr>
<th class="my-sticky-col">Header 1</th>
<th class="my-sticky-col2">Header 2</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
<th>10</th>
<th>11</th>
<th>12</th>
<th>13</th>
<th>14</th>
<th>15</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" class="my-sticky-col">A</td>
<td class="my-sticky-col2"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="my-sticky-col"> </td>
<td class="my-sticky-col2"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="my-sticky-col">C</td>
<td class="my-sticky-col2"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</div>
</div>
CSS
body {
font-size: 1em;
}
.myTable {
border: none;
border-right: solid 1px #DDEFEF;
border-collapse: collapse;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.myTable thead th {
background-color: #EEE;
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.myTable tbody td {
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.myTable tbody td, .myTable thead th {
border: 1px solid #ccc;
}
.my-wrapper {
position: relative;
}
.my-scroller {
margin-left: 283px;
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 5px;
width: 300px;
}
.myTable .my-sticky-col {
left: 0;
position: absolute;
top: auto;
width: 120px;
}
.myTable .my-sticky-col2 {
border-right: solid 1px #000;
left: 142px;
position: absolute;
width: 120px;
}
Your code is actually working correctly. You are not seeing the rowspan working because the absolute positioning that is used for the sticky header. I updated your JS Fiddle with a few tweeks so you can see what is going on. http://jsfiddle.net/x62v5ea8/2/
You can see in the HTML I commented out the cell that will used by the rowspan and added a .test class with a height and background color so you can see that the cell is now fully expanding. Alternatively you can remove the position: absolute and you see the same results but your header wont be sticky anymore.
How can the code below be modified such that the Table THead matches up with the TD's and also respect the size (width) of the table? What is happening now is that the table headers expand beyond the size of the div and the table horizontally accross the page.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<style type="text/css">
/*------------------------------------------------------------------
Table Style
------------------------------------------------------------------ */
table a:link {
color: #666;
font-weight: bold;
text-decoration:none;
}
table a:visited {
color: #999999;
font-weight:bold;
text-decoration:none;
}
table a:active,
table a:hover {
color: #bd5a35;
text-decoration:underline;
}
table {
font-family:Arial, Helvetica, sans-serif;
color:#666;
font-size:12px;
background:#eaebec;
border-radius:3px;
border-collapse:collapse; border-spacing: 0;
box-shadow: 0 1px 2px #d1d1d1;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
table-layout: fixed;
}
table th {
border-bottom:1px solid #ccc;
border-left: 1px solid #ccc;
background: #ededed;
}
table tr {
text-align: center;
}
table td {
border-bottom:1px solid #ccc;
border-left: 1px solid #ccc;
background: #fafafa;
text-align: left;
}
table tr:hover td {
background: #f2f2f2;
}
table th, table td {
height: 20px;
width: 200px;
}
#container {
width : 98.7%;
height: 300px;
overflow-x: scroll;
overflow-y: scroll;
}
table tr td:first-child, table tr th:first-child {
border-left: 0;
}
table thead {
_position: fixed;
_position: relative;
_position: absolute;
}
TABLE THEAD TR TH {
top:expression(this.offsetParent.scrollTop);
border-top:1px solid #ccc;
_position:relative;
_position: absolute;
_position: fixed;
}
table tr:first-child td {
border-top: 0;
}
</style>
</head>
<body>
<div id="container">
<table id="data">
<!-- Table Header -->
<thead>
<tr>
<th>File Number</th>
<th> </th>
<th> </th>
<th>Firstname</th>
<th>Lastname</th>
<th>Progress</th>
<th>Vital Task</th>
</tr>
</thead>
<!-- Table Header -->
<!-- Table Body -->
<tbody>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr><!-- Table Row -->
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr><!-- Darker Table Row -->
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>20%</td>
<td>No</td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>80%</td>
<td>No</td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>23%</td>
<td>yes</td>
</tr>
<tr>
<td>ABC-123-123456</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>80%</td>
<td>No</td>
</tr>
<tr>
<td>Hyperlink Example</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>80%</td>
<td>Another</td>
</tr>
</tbody>
<!-- Table Body -->
</table>
<script>
$(function() {
$( "#data tr th" ).resizable({
handles: 'e'
});
});
</script>
</div>
</body>
</html>
ETA http://jsfiddle.net/KrB79/
Fix the container's CSS Coding to:
#container {
width : 98.7%;
height: 300px;
overflow-x: scroll;
overflow-y: scroll;
position: fixed;
}
Problem solved with IE7.