I am trying to get both the table tow of the table one and table three to match in width- at present, the last cell does not. The reason for the two tables is fixed headers on table one and scrollable overflow content for table 2. This approach has worked in the past for me and I just cannot figure out what is different with this example to produce this error.
#table_wrapper1 {
position: absolute;
top: 250px;
left: 20px;
height: 47px;
width: 500px;
}
#table1 {
table-layout: fixed;
position: absolute;
display: table;
font-size: 0.7em;
border: solid 1px;
z-index: 2;
width: 100%;
background-color: #F7F7F7;
}
#table_wrapper2 {
position: absolute;
top: 278px;
left: 20px;
width: 500px;
overflow: scroll;
height: 150px;
}
#table2 {
table-layout: fixed;
position: absolute;
display: table;
font-size: .7em;
border: solid 1px;
z-index: 2;
width: 100%;
background-color: #F7F7F7
}
td {
padding: 4px;
border: solid 1px black;
background-color: #FFF4C6;
vertical-align: middle;
text-align: center;
}
th {
padding: 6px;
Border: solid 1px black;
background-color: #BB8A76;
vertical-align: middle;
text-align: center;
}
<div id="table_wrapper1">
<table class="table" id="table1">
<thead>
<tr>
<th>Unit code</th>
<th>Description</th>
<th>Delete unit</th>
<th>Add new unit</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="table_wrapper2">
<table class="table" id="table2">
<thead></thead>
<tbody>
<tr>
<td><input class="unit <?php echo $class;?>" type="text" name="unit_code[]" value="<?php echo #$_POST['unit_code'][0]?>"></td>
<td><textarea cols="10" rows="3" class="<?php echo $class;?>" name="unit_description[]"><?php echo #$_POST['unit_description'][0]?></textarea></td>
<td><img title="remove unit" class="remove_row" src="../images/exit.png"> </td>
<td><img title="add more units" class="add_row" src="../images/add-resource.png"></td>
</tr>
</tbody>
</table>
</div>
It looks like the issue might be the overflow: scroll;. Removing this seems to work on my end.
Edit: Unfortunately you're going to continue running into this issue with the overflow: scroll due to the scrollbar naturally taking up space. You could trying applying negative right padding to your table body wrapper, but you'll then run into browser compatibility issues. Perhaps you could try applying the overflow: scroll to the upper wrapper as well? It wouldn't be pretty, but it might work nonetheless.
Related
I'm trying to make it so that images in cells in an html table expand when you hover over them. I want this to be universal to all tables on my website. Here's my code so far:
td img {
height: 150px;
}
td img:hover{
height: 175px;
}
This code makes the images appear at their correct height, but nothing hapens when I hover over them. Obviously I'm doing something wrong, but what is it?
Consider defining the width and height of the cells and adjust the image within those parameters. This way the rows don't shift around when you hover -- change table image size on hover
html {
padding: 50px;
}
table {
width: 600px;
padding: 10px;
background: #FFF;
border: 1px solid #BBB;
}
th {
padding: 10px;
}
td {
vertical-align: middle;
text-align: center;
padding: 5px;
border: 1px solid #DDD;
}
td:first-child {
width: 50px;
}
td:last-child {
width: 200px;
height: 200px;
}
td img {
width: 75%;
height: auto;
}
td img:hover{
width: 90%;
height: auto;
}
<table>
<thead>
<th>Image Title</th>
<th>Image</th>
</thead>
<tbody>
<tr>
<td>Image 1</td>
<td><img src="http://www.logoeps.net/wp-content/uploads/2013/06/stackoverflow_logo.jpg" /></td>
</tr>
</tbody>
</table>
you can do it with CSS
td:hover img{
height:175px;
}
you can use jQuery for this also :
$('td img').on('mouseenter',function(){
$(this).css({
'height':'175px'
});
});
* {
margin: 0;
padding: 0;
}
img {
height: 150px;
width: auto
}
td:hover img {
background: red;
height: 200px;
}
<table>
<tr>
<th>Title</th>
<th>Image</th>
</tr>
<tr>
<td>Image Title</td>
<td><img src="https://torange.biz/photofx/5/8/image-profile-picture-beautiful-exotic-flower-5532.jpg" alt=""></td>
</tr>
</table>
After going through many solutions non of them could solve my problem.
I have a <td> which has a <table> in it. However, the text inside this inner table does not fit in. Text clips out. I tried various things like overflow:hidden, table-layout: fixed on the <table> and word-wrap:break-word on <td> and still it didn't solve the problem.
Here's my code:
<table id="table1">
<tr>
<td id="td1">
<img src="http://lorempixel.com/165/232" />
</td>
<td id="td2">Long text goes here</td>
<td id="td3" rowspan="7">
<table id="table2">
<tr>
<td>Long text goes here</td>
</tr>
</table>
</td>
</tr>
And here's the CSS:
#table1 {
width: 765px;
border: 1px solid red;
border-spacing: 0;
padding: 0;
}
#td1 {
width: 175px;
vertical-align: top;
}
#td2 {
vertical-align: top;
}
#td3 {
width: 180px;
vertical-align: top;
background-color: #F3F3F3;
}
#table2 {
width: 100%;
border: 1px solid blue;
border-spacing: 0;
padding: 8px;
}
The content inside the inner table clips out. Could anyone please provide a solution so that the inner table can have proper content in it without clipping.
JSFiddle
This can be achieved much more simply. Let's do this with display: table; and display: table-cell;. We can layout block elements with similar behaviour to a table, but much simpler and easier to maintain.
Read more on CSS display
Have a Fiddle!
CSS
.box {
border: solid 1px #CCC;
display: table;
padding: 10px;
}
.box div {
display: table-cell;
vertical-align: top;
margin: 10px;
padding: 10px;
}
.right {
border: solid 1px #F00;
}
HTML
<div class="box">
<div class="left">
<img src="http://placehold.it/200" />
</div>
<div class="center">Content</div>
<div class="right">Content</div>
</div>
I have an HTML page in which there is a table which populates data from a database table and I am trying to restrict the size of the table by placing it in a div like in the following
<div id="scrollablebody">
<table class="clientTable">
<thead>
<tr>
<th>Grade</th>
<th>Term</th>
<th colspan="3">Actions</th>
</tr>
</thead>
<!--ko foreach: products-->
<tr>
<td class="clientproductHeader" data-bind="text: $data">
</td>
<td class="clientproductHeader" colspan="13"></td>
</tr>
<tbody data-bind="foreach: ko.observableArray($root.datainput()).extendsdistinct('Product').index.Product()[$data]">
<tr data-bind="template: { name: $root.displayMode, data: $data }"></tr>
</tbody>
<!--/ko-->
</table>
</div>
CSS for div
#scrollablebody{height:500px;overflow-y:auto;width:100%;}
But for some reasons the text in tbody is occupying all the space like in the following image
As you can see in the above picture the row with c5+ is unusually occupying lot of space
CSS for the Table
.clientTable {
max-width: 100%;
background-color: grey;
height:75%;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
width: 98%;
margin-left:0;
margin-right:100px;
float: left;
overflow:scroll;
}
table.clientTable thead tr .header {
background-image: url(images/bg.png);
background-repeat: no-repeat;
background-position: center right;
cursor: pointer;
}
table.clientTable td {
padding: 1px;
line-height: 10px;
text-align: center;
/*background-color:#3C78B5;*/
vertical-align: auto;
border: 1px solid #0088cc;
width: 120px;
}
.clientTable th {
padding: initial;
line-height: normal;
text-align: center;
width: initial;
height: 20px;
border: 1px outset gray;
background-color: black;
color: white;
cursor: pointer;
}
Change height to max-height. It's going grow to size if you don't specify and have the overflow as auto.
I have a table and when I set the table to a width of 100% and the table rows to a width pf 100% nothing happens or changes to the width.
.Table-Normal {
position: relative;
display: block;
margin: 10px auto;
padding: 0;
width: 100%;
height: auto;
border-collapse: collapse;
text-align: center;
}
.Table-Normal thead tr {
background-color: #E74C3C;
font-weight: bold;
}
.Table-Normal tr {
margin: 0;
padding: 0;
border: 0;
border: 1px solid #999;
width: 100%;
}
.Table-Normal tr td {
margin: 0;
padding: 4px 8px;
border: 0;
border: 1px solid #999;
}
.Table-Normal tbody tr:nth-child(2) {
background-color: #EEE;
}
<table id="top-leader" class="Table-Normal">
<thead>
<tr>
<td>Position</td>
<td>Name</td>
<td>Kills</td>
<td>Deaths</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John Doe</td>
<td>16 Kills</td>
<td>0 Deaths</td>
</tr>
<tr>
<td>2</td>
<td>John Smith</td>
<td>13 Kils</td>
<td>1 Death</td>
</tr>
<tr>
<td>3</td>
<td>Bob Smith</td>
<td>11 Kills</td>
<td>0 Deaths</td>
</tr>
</tbody>
</table>
Remove display: block in .Table-Normal
Fiddle
.Table-Normal {
position: relative;
//display: block;
margin: 10px auto;
padding: 0;
width: 100%;
height: auto;
border-collapse: collapse;
text-align: center;
}
By specifying display: block you've overriding the default value from the browser stylesheet for the table element: display: table. Removing display: block or replacing it with display: table fixes this.
As people have mentioned you have to remove display:block; for this to work. If you need to keep scrolling functionality wrap the table inside a div and set overflow rules on that
<div class = "table-container">
<table>...</table>
</div>
.table-container{
height:100px
width:100px
overflow-x:scroll;
table{
display: table;
width:100%;
}
}
I have made a table of which does not fill the full width of the parent div in CHROME & SAFARI.
This works fine in Firefox but I would like to get working in all browsers.
After some views on here I found that in some chrome cases can be fixed with setting parent div to...
display: block; width: 100%;
.. but the issue persists.
Also found another couple cases where specifying no margin & padding so gave that a shot and still there are issues with displaying in Chrome & Safari.
THE HTML
<div class='player_box info_pic_2'>
<div style='display: block; width: 100%;'>
<table style='margin: 0; padding: 0; width: 100%; border-style: solid; border-width: 1px; position: absolute; left: 0; top: 0; right: 0px; height: 30px;'>
<tr class='border_bottom'>
<td>CELL A</td>
<td>CELL B</td>
</tr>
</table>
<table style='margin: 0; padding: 0; width: 100%; border-style: solid; border-width: 1px; position: absolute; left: 0; right: 0px; top: 30px;'>
<tr class='border_bottom'>
<td>ROW A </td>
</tr>
<tr class='border_bottom'>
<td>ROW B </td>
</tr>
<tr class='border_bottom'>
<td>ROW C </td>
</tr>
<tr class='border_bottom'>
<td>ROW D </td>
</tr>
<tr class='border_bottom'>
<td>ROW E </td>
</tr>
<tr class='border_bottom'>
<td>ROW F </td>
</tr>
</table>
</div>
</div>
THE CSS
tr.border_bottom td {
border-bottom:1pt solid black;
}
.info_pic_2 {
position: absolute;;
height: 250px;
top: 130px;
right: 70px;
width: 350px;
max-width: 100%;
display: block;
border-style:solid;
border-width:5px;
color: black;
}
.player_box {
border:solid 4px #000000;
-moz-border-radius-topleft: 33px;
-moz-border-radius-topright:32px;
-moz-border-radius-bottomleft:32px;
-moz-border-radius-bottomright:32px;
-webkit-border-top-left-radius:33px;
-webkit-border-top-right-radius:32px;
-webkit-border-bottom-left-radius:32px;
-webkit-border-bottom-right-radius:32px;
border-top-left-radius:33px;
border-top-right-radius:32px;
border-bottom-left-radius:32px;
border-bottom-right-radius:32px;
text-align:center; background:#575757;
padding:100px 50px 100px 50px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
opacity: 0.8;
}
Your issue appears to be the padding values in your .player_box selector (Second to last line on your CSS. Remove the padding and it will fill correctly.
I can make it behave better by changing this CSS:
.info_pic_2 {
position: absolute;
height: 250px;
top: 130px;
right: 70px;
width: 350px;
max-width: 100%;
display: block;
border-style: solid;
border-width: 5px;
color: black;
}
to:
.info_pic_2 {
height: 250px;
top: 130px;
right: 70px;
max-width: 100%;
display: block;
border-style: solid;
border-width: 5px;
color: black;
}
I've found that mixing absolute positioning and percentage widths is a nightmare.
Edit: The padding doesn't help either, but see my updated version here:
http://jsfiddle.net/rcQmW/2/