I have the following problem of adding a row to a html table with css column specified but when a row is added the columns no longer use the css. Does anyone know why this is happening and how I can get around this? The code is below.
<table class="Grid" style="width: 740px;">
<thead><tr><th class="cbx"><input type='checkbox'/></th><th class="DocType">DT</th><th class="narrowColumn">Pg</th><th class="narrowColumn">V</th><th class="narrowColumn" id="sCol">S</th><th class="srcInfo">SI</th></tr></thead>
<tr id="node" class="gridrow">
<td class="cbx"><input class="cbxLeft" name="IDs" type="checkbox" value="4e420f8e-022a-4640-833e-e37bbdb6d856" /></td>
<td class="DocType"><div style='float:left'><a class="" href="/B/" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'GET', updateTargetId: 'Left', url: '/B/', onComplete: Function.createDelegate(this, Poll) });" target="_blank" title="">AA</a></div></td>
<td class="narrowColumn">1</td>
<td class="narrowColumn">1</td>
<td class="narrowColumn">1</td>
<td class="srcInfo"><img alt="SI" src="Content/Images/ico_properties.gif" /></td>
</tr>
<tr id="tr1" style="display: none;">
<td colspan="6" style="margin: 0px; padding: 0px;">
<div style="float: left; width: 50%; margin: 0px; padding: 0px;">Capture Channel: Auto Synchronous Reassembly</div>
<div style="float: left; margin: 0px; padding: 0px;">Indexed By: SomeNetworkId</div>
</td>
</tr>
<script language="javascript" type="text/javascript">
function ShowHide(id) {
var tr = document.getElementById(id);
if (tr.style.display == "none") tr.style.display = "";
else tr.style.display = "none";
}
</script>
<style type="text/css">
.SourceInfo
{
width: 732px;background: red;
border:none;
border-style:none;
}
th.cbx, td.cbx
{
margin: 0;
padding: 0;
width: 13px !important;
text-align: center;
vertical-align: middle;
}
table.Grid .cbx input
{
text-align: center;
padding: 0;
}
table.Grid th.cbx input
{
width: 13px;
margin: -2px 0px -2px 0px;
}
table.Grid td.cbx input
{
width: 15px;
margin: -3px 0px -2px 0px;
}
td.DocType img
{
margin-left:5px;
border:none;
}
th.narrowColumn, td.narrowColumn
{
width: 25px;
text-align: center;
}
.gridrow
{
background:#fff;
}
</style>
sorry all of this couldn't fit in the code for some reason.
thanks for any help,
bruce
when a row is added the columns no longer use the css
If you are talking about the way the column widths change in IE when you unhide the bottom (colspanned) row, this is to be expected.
You haven't specified the widths of all the columns, so in the default ‘table-layout: auto’ mode the browser will guess how to distribute the ‘spare’ table widths to each column. It does this by guessing at how much content there is in each column, based on all the rows. So when you add the extra row, which has an equal amount of content in every column (due to sharing with a colspan), the averaged cell widths get closer to equality and all the column widths change.
If you don't want this behaviour, set the style ‘table-layout: fixed’ on the table. With fixed layout, only the first row of cells makes any difference to the column widths, and any columns you leave with unspecified widths will share all the ‘spare’ width equally. This is probably what you wanted. It's also faster for the browser to render, and allows you to leave off styles on subsequent rows if you're only using them to set width.
Related
So I'm building a website, which features several pages describing (fantasy) people and places. To that end, several categories of page have a profilebox which include stuff like a heading, an image and a table with some summary data.
The HTML for such a box looks like this:
<profilebox class="red">
<p><i>His Majesty</i><br><span class="big-and-strong">The King</span>
</p>
<figure class="pbox"><img class="pbox" src="../images/armsroyal.svg">
</figure>
<table class="pbox">
<tr>
<td>Surname</td>
<td>N/A</td>
</tr>
<tr>
<td>Forename</td>
<td>N/A</td>
</tr>
<tr>
<td>Rank</td>
<td>King</td>
</tr>
<tr>
<td>Addressed As</td>
<td>‘‘Your Majesty’’</td>
</tr>
</table>
</profilebox>
Whereas the CSS looks like this:
profilebox {
display: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 1em;
margin-right: 0em;
width: 400px;
float: right;
text-align: center;
padding: 1em;
border-color: black;
border-style: solid;
border-width: 0px 0px 0px 5px;
}
table {
border-collapse: collapse;
width: 600px;
}
.mini {
width: 400px;
}
.maxi {
width: 100%;
}
.pbox {
width: 100%;
}
img {
margin: 1em;
}
.pbox {
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
}
figure.pbox {
width: 100%;
}
Now the pbox class of table has width set to 100%, so the table in the profile box should fill up its parent element, right? (I can feel a "Wrong!" coming on.) However, this is what the page actually looks like in Chromium:
Table too narrow
If I replace <table class="pbox"> with <table class="maxi">, I get the desired result:
Table just right
But the maxi and pbox classes of table are identical! Any idea what's going on here?
I had assumed - incorrectly - that if you put something like:
CSS
element1 {
property-a: setting1;
}
.class-name {
property-b: setting2;
}
element2 {
property-c: setting3;
}
.class-name {
property-d: setting4;
}
HTML
<element2 class="class-name"/>
Then element2 will have properties:
property-c: setting3;
property-d: setting4;
In fact, all definitions of .class-name will be applied, so element2 will have properties:
property-b: setting2;
property-c: setting3;
property-d: setting4;
If we amend the CSS as follows:
element1 {
property-a: setting1;
}
element1.class-name {
property-b: setting2;
}
element2 {
property-c: setting3;
}
element2.class-name {
property-d: setting4;
}
Then everything works!
I have a table under a searchbar. When I write something inside it, it filters that word with my skills list and the table appears bottom the bar.
Everything works well but not the size of this div because it have an height of 300px so if I have 10 skills is ok, but if the skill are, for example, 2, every td will have a height of 150px.
So I would like to fix this with a max height of 300px and when the rows decrease I want the table to get smaller.
HTML
<div class="container">
<ng-container
*ngIf="searchString.searchString && (searchSkills.getAllSkill() | filterAll : searchString.searchString) as filteredSkills">
<ng-container *ngIf="filteredSkills.length > 0">
<div class="suggerite">
<cdk-virtual-scroll-viewport [itemSize]="10" class="sugtab style-bar modal-bar">
<table class="sugtab">
<tbody>
<tr *cdkVirtualFor="let skill of filteredSkills" class="sugtag">
<td (click)="addToSearch(skill)" class="skill">
{{skill.name}}
</td>
</tr>
</tbody>
</table>
</cdk-virtual-scroll-viewport>
</div>
</ng-container>
</ng-container>
</div>
CSS
.suggerite{
position: relative;
border: 1px solid #064a94;
border-radius: 5px;
background-color: rgba(255,255,255,0.9);
color: #064a94;
z-index: 100;
cursor: pointer;
padding-left: 0 !important;
padding-right: 0 !important;
}
.sugtab{
height: 200px;
width: 100%;
font-family: sans-serif;
}
tr.sugtab {
height: 50px;
}
td.skill{
padding: 3px;
}
I tried to use max height and different things but probably in wrong places.
My HTML:
<table style="width:100%;">
<tbody>
<tr style="cursor:pointer; border-bottom:1px solid #ACACAC; height:60px;">
<td style="text-align:right; vertical-align:middle; padding:10px 10px 10px 0px;">
<span style="color:#F87E20;">Copy</span>
<div style="display:inline; color:#ACACAC;"> | </div>
<span style="color:#F87E20;">Export</span>
<div style="display:inline; color:#ACACAC;"> | </div>
<span style="color:#F87E20;">Delete</span>
</td>
</tr>
</tbody>
</table>
The result:
This is all fine, and is working wonderfully. I want to make some QOL changes, though, and while looking into some of the changes I wanted to make, ran into something that is confusing me quite a bit.
The entire row is clickable, as well as the Copy, Export and Delete spans. This becomes a problem when I try to click on Export, but miss by 2 or 3 pixels, and instead navigate away from this area. I wanted to make the clickable area for the spans bigger, so I gave the a style property like so: padding:10px 0px 10px 0px;
The padding works as intended, enlarging the clickable area around the spans, making it easier to click on them. However, I was expecting the padding to also make the entire row taller, but instead it's as if the spans' padding is just flowing over the padding on the parent.
Here are some images to help explain the situation:
Parent:
And Child:
I don't understand why the child's padding is flowing outside it's container, and I don't want to go on in this direction without understanding what's going on. I was wondering if anyone could please help me understand what's happening here?
Your spans are inline elements. Top and bottom padding is ignored in case of inline elements.
By default, spans are inline, and divs are block. However, you can always override these with display: block; or display: inline;. Block elements (also inline-blocks) have full padding support.
See:
table {
width: 100%;
border-bottom: 1px solid #ACACAC;
}
tr {
cursor: pointer;
height: 60px;
}
td {
text-align: right;
vertical-align: middle;
padding: 10px 10px 10px 0px;
background-color: #e0c000;
}
span {
display: inline-block;
color: #F87E20;
background-color: #f0e000;
}
.padded {
padding: 10px 0 10px;
}
div {
display: inline;
color: #ACACAC;
}
<table>
<tbody>
<tr>
<td>
<span>Copy</span>
<div> | </div>
<span class="padded">Export</span>
<div> | </div>
<span>Delete</span>
</td>
</tr>
</tbody>
</table>
See also this article for more on this.
I have a table I have simplified for this question while preserving the problem.
It is a single row with three cells. The middle one contains an image and the first and last ones fill the remaining space and are textually supposed to be empty.
The height of the first and last cell adapts to that of the central (image) one as it is the highest, which does work -
but they become a tad bigger than they should visually creating a hole beneath the central cell.
HTML:
<article class="content" id="pc">
<table id="contentTable">
<tr>
<td class="pad" id="padL"></td>
<td id="cc">
<a href="#"><img src="http://38.media.tumblr.com/b9dc51057ece7352d07d40f4c59f0c65/tumblr_nb0xmfghdm1tin2h1o1_500.jpg" width="250"/>
</a>
</td>
<td class="pad" id="padR"></td>
</tr>
</table>
</article>
CSS:
#contentTable {
table-layout: fixed;
width: 700px;
}
#cc {
width: 500px;
}
.pad {
background-color: gray;
vertical-align: middle;
}
#padR {
border-top-right-radius: 2em;
border-bottom-right-radius: 2em;
}
#padL {
border-top-left-radius: 2em;
border-bottom-left-radius: 2em;
}
Here is a screen shot of the problem with the space highlighted in blue
And a CodePen if it helps.
Why does it occur and how can I remove it?
Since your image is inline, it obeys rules of baseline and has space at the bottom.
I had success by setting:
img {
display:block;
}
To get rid of other table spacing (not showing in your screen-shot), I suggest adding:
#contentTable {
border-collapse:collapse;
...
}
#contentTable tr td{
padding:0;
}
WORKING EXAMPLE
EDIT
Per your comment, here's an example using an embedded YouTube video (iframe). Iframes default to display:inline (replaced element), too.
iframe { display:block; }
WORKING EXAMPLE
Add a class to the cell containing the picture.
<td class="pad" id="cc">
I have the following content:
It is a table, with one row and three cells, two blue cells, and the middle cell, and in the middle cell I have a div, for now it looks good.
But if I put the zoom property in the div (zoom: 0.8) I get an extra space in IE11, as if the div was still the same size, like this:
In chrome, the table just adjusts to the div size, but not in IE, is there anyway I can achieve this?
This is the fiddle of the example:
http://jsfiddle.net/Z3wbN/3/
HTML:
<table class="container">
<tr>
<td class="border">
</td>
<td>
<div class="content">
This is a test
</div>
</td>
<td class="border">
</td>
</tr>
CSS:
.container {
background-color: #ddd;
}
.border {
background-color: blue;
width:10px;
}
.content {
margin: auto;
width: 500px;
border: 2px solid yellow;
zoom: 0.8;
}
One possible solution, although I don't know if you'll like it, could be this one: http://jsfiddle.net/Z3wbN/14/
On that solution:
A couple of classes/ids are added to the tags;
The width is assigned to the middle cell instead of to the div inside that cell;
if it's an IE browser, the div width is adjusted to 125% (100% / 0.8 that is the zoom).
The way of detecting the browser is JavaScript but you could try any that you want (I got it from Detect IE version (prior to v9) in JavaScript):
// if it's an IE browser then update the class to "container ie"
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
document.getElementById("container").className = "container ie";
}
Then the CSS is adjusted as specified in the list above:
td.middle {
width:500px;
}
.content {
margin: auto;
border: 2px solid yellow;
zoom: 0.8;
}
.ie .content {
width:125%;
}
This solution displays a "similar" result on IE and Chrome/Firefox.
You need to use display:table-cell; to class .content
Here is the updated fiddle:
.container {
background-color: #ddd;
}
.border {
background-color: blue;
width: 10px;
}
.content {
margin: auto;
width: 500px;
border: 2px solid yellow;
zoom: 0.8;
display: table-cell;
}
zoom: 0.5;
<table class="container">
<tr>
<td class="border">
</td>
<td align="center">
<div class="content">
This is a test
</div>
</td>
<td class="border">
</td>
</tr>
</table>
All you need to do is to apply zoom to .container too :
.container {
zoom: 0.8
}
Here's the JSFiddle: http://jsfiddle.net/Z3wbN/12/