Different CSS styling for left and right side table data - css

This is my table:
<table width="100%">
<tr ><td width="35%" height="30" class="left-info" >Criminal Id :</td>
<td width="65%" class="right-info" >CR7887898652</td></tr>
<tr><td height="30" class="right-info" >Full Name :</td><td class="left-info" ></td></tr>
<tr><td height="30" class="right-info" >Date of Birth :</td><td class="left-info" ></td></tr>
</table>
How can I remove these repeating use of class for each table data. As, I've used class="left-info" for left side table data and class="right-info" for right side table data. But, this make the mesh of coding, can anyone suggest me how can I do the same style with minimal code?

You can either switch to a non-table layout (perhaps a DL may suit your needs better), or if you must use a table, consider using the col element, which you can apply a class attribute to.
Example
Using your example above, this is how I would suggest using the col element.
<table id="example">
<col class="label" />
<col class="value" />
<tr>
<td>Criminal Id :</td>
<td>CR7887898652</td>
</tr>
<tr>
<td>Full Name:</td>
<td>Foo Bar</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td>01/14/1983</td>
</tr>
</table>
But, taking into account your example, I think you could accomplish your goal with better semantics and less code if you make use of TH elements and pure CSS:
#example th {
text-align: right;
font-weight: normal;
}
#example td {
text-align: left;
}
...
<table id="example">
<tr>
<th>Criminal Id :</th>
<td>CR7887898652</td>
</tr>
<tr>
<th>Full Name:</th>
<td>Foo Bar</td>
</tr>
<tr>
<th>Date of Birth:</th>
<td>01/14/1983</td>
</tr>
</table>
At this level, it shouldn't really matter if you use a DL or a TABLE as they both are semantically rich elements when used like this. IMHO, I still prefer a DL, but truthfully they can be more difficult to style.

Related

Angular components in html table cells overlap

I am using Angular CLI: 8.3.14 and Node: 12.18.0.
I have components A, B, and C, and I tried to put them into individual cells in a traditional HTML table, but they come out overlap, I've tried many CSS formatting tricks, below are a few of them that I tried, but none worked.
.gfg {
border-collapse:separate;
border-spacing:0 15px;
}
table td.expand {
width: 99%;
height: 99%;
}
<table class="gfg" width="100%">
<tr> <td class="expand"> <componentA></componentA> </td> </tr>
<tr> <td class="expand"> <componentB></componentB> </td> </tr>
<tr> <td class="expand"> <componentC></componentC> </td> </tr>
</table>
One more piece of information: this whole thing is also inside another <div> that I have made its height:100vh, so I don't think it is a space issue, what I want is to have the components stack up on top of one another.

nth-child td width stretching other elements?

I have a two column layout in sharepoint online and upon page inspection I can see that it has a table with two columns. I'm trying to hide one of the columns for printing, which is working just fine, but sharepoint has specified the width of the first column as 66%. It has no class or id. I cannot change this.
I am able to change the width of the column, but the problem I'm seeing is then that the % of the columns on the inside table is also changing, even when I use a specification of nth-child(1) on the id of the outer table.
I won't submit you to the mess of code that is sharepoint but the layout is like this:
<table>
<tbody>
<tr>
<td>
<table width="100%>
<tbody>
<tr>
<td style="width: 25%>></td> <-this is getting stretched.
<td style="width: 25%>></td>
<td style="width: 25%>></td>
<td style="width: 25%>></td>
</tr>
</tbody>
</table>
</td>
<td>
</td>
</tr>
</tbody>
</table>
#media print {
table#layoutsTable td:nth-child(1) {
width: 100% !important;
}
}

Mootools not show colspan td in tr hidden

I want to hide information that is in a hidden row as shown no respect colspan. I have:
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td><div id="se">click here!!</div></td>
<td>value 2</td>
<td>value 3</td>
</tr>
<tr><td colspan="3" style="display:none;;">content</td></tr>
and Mootools code
$('se').addEvent('click',function(){
this.getParent('tr').getNext('tr').getElement('td').setStyle('display','block');
});
when I click on "click here!" hidden row is shown, but not colspan.
See example here: http://jsfiddle.net/Xvnhw/1/
this is not to do with MooTools but browser repaint of an element that it has not considered for rendering before.
move to using a CSS based setup, which gets applied after the engine parses the cells and sets correct position.
http://jsfiddle.net/Xvnhw/3/
$('se').addEvent('click',function(){
this.getParent('tr').getNext('tr').getElement('td').removeClass('hide');
});
and css
.hide {
display: none
}
yet another example of why inline element styles are a bad thing.
This has nothing to do with inline styling and everything to do with the display value. The display style should be set to 'table-cell', not 'block'.
Here is the original code, with the only change being change being setting the display value to 'table-cell':
http://jsfiddle.net/L2zz3/
HTML:
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td><div id="se">click here!!</div></td>
<td>value 2</td>
<td>value 3</td>
</tr>
<tr><td colspan="3" style="display:none;;">content</td></tr>
</table>
Mootools code:
$('se').addEvent('click',function(){
this.getParent('tr').getNext('tr').getElement('td').setStyle('display','table-cell');
});
Note how this example has inline styles and still works.
Here is a CSS based setup that sets the display value to 'block':
http://jsfiddle.net/z7hXc/
HTML:
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td><div id="se">click here!!</div></td>
<td>value 2</td>
<td>value 3</td>
</tr>
<tr><td colspan="3" class="hide">content</td></tr>
</table>
Mootools code:
$('se').addEvent('click',function(){
this.getParent('tr').getNext('tr').getElement('td').removeClass('hide').addClass('show');
});
CSS:
.hide {
display:none;
}
.show {
display:block;
}
Notice how this example has the same issues as the original code, but does not use any inline styles. Therefore, this is clearly an issue with 'display':'block', and not due to inline styling.

Standard fixed table width

Is there a standard method for calculating fixed width values for tables in HTML? Right now, I'm working on formatting tables on a web page to be a fixed width, I have a table that's within another table, when testing the page in IE I notice that the alignment of the colon is off as the second picture below illustrates. My intention is to make sure the colons are properly aligned as they are in Firefox and was just curious if the misalignment was due to the settings in the HTML or if it has more to do with how the browser renders the page.
Firefox:
Internet Explorer:
UPDATE:
Sorry for not providing any reference code, here's a snippet of the particular section I'm working with.
<div style="width: 1600px; text-align: center; position: absolute; top: 10%; left: 0%;">
<span id="labelInstructions" style="font-size: xx-large;">PAGE TITLE <br><br></span>
<table style="width: 1000px;" align="Center" border="0">
<tbody>
<tr>
<td style="width: 1000px;"><label for="FileUpload1" style="font-size: x-large;">ENTER: </label><input name="FileUpload1" id="FileUpload1" size="70%" type="file"></td>
</tr>
<tr>
<td style="width: 1000px;"><span id="fileUploadError" style="color: Red; font-size: medium;"><br><br></span></td>
</tr>
<tr>
<td style="width: 1000px;">
<table style="width: 1260px;" border="0">
<tbody>
<tr>
<td style="font-size: x-large; width: 800px;" align="right" valign="top">FILE INSTRUCTIONS:</td>
<td style="font-size: x-large; width: 1800px;" align="left" valign="top">INSTRUCTION 1<br>INSTRUCTION 2<br></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td style="font-size: x-large; width: 800px;" align="right" valign="top">FILE EXAMPLE:</td>
<td style="font-size: x-large; width: 1800px;" align="left" valign="top">EXAMPLE 1<br>EXAMPLE 2<br><br></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
I know it's ugly, just a note, this is an ASP.Net generated webpage and I'm setting the attributes of the HTML elements pro-grammatically from the code behind. I sorta inherited this and my employer wants to keep major changes to a minimum.
UPDATE 2:
When I adjust the inner table width I can get it to align in IE when set to 1377px. For Firefox, the sweet spot for alignment is 1260px.
All you have to do is make the table columns the same width as each other.
Example of style:
table tr td:first-child { background-color:yellow; width:200px; }
HTML:
<table>
<tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
<tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
<tr><td>Row 3 Cell 1</td><td>Row 3 Cell 2</td></tr>
</table>
Sorry for not directly answering to your question, but...
Stoneage is over! You really shouldn't use Tables for layouting-purposes, as they are hardly-accessible for disabled people and make your HTML-File way too big (in relation to the content).
Seperate Content and Layout, use CSS.
Make sure to place the the parts that you want to align together in one table.
<table id="layout">
<tr><td>HEADER</td>
<tr><td>
<table id="form">
<tr><td>LABEL</td><td>INPUT FIELD</td></tr>
<tr><td>LABEL</td><td>INPUT FIELD</td></tr>
<tr><td>LABEL</td><td>INPUT FIELD</td></tr>
</table>
</tr>
<tr><td>FOOTER</td>
</table>
i would create two classes, left and right and apply the left class to the <td> on the left and the right class to the <td> on the right. the left class would be something like
.left{width:100px; text-align:right;}
heres an example

vertically stack table td elements using css

Is there a way to vertically stack selected td elments? I would like to have the same table, though display it differently using only css. Would this be possible, or do I have to have separate html markups? I would like to try to have the same html markup, though use different css for different sites/looks.
<table>
<tr>
<td class="vertical" id="one" >i'm</td>
<td class="vertical" id="two" >above</td>
<td class="vertical" id="three" >this</td>
<td class="horizontal" id="four" >i'm horizontal</td>
</tr>
</table>
You can also make them display:block but I''m not quite sure what effects this would hev on table lay-out.
.vertical{
display:block;
}
For others trying to achieve this, for any weird reason, you could use
.vertical{
display:flex;
}
https://jsfiddle.net/mr5dhwj3/
I needed this in a responsiveness situation where the table was rendered horizontally normally, but only vertically in some cases.
You need to create the table stacked
<table>
<tr>
<td class="vertical">i'm</td>
<td class="horizontal" rowspan="3">i'm horizontal</td>
</tr>
<tr>
<td class="vertical">above</td>
</tr>
<tr>
<td class="vertical">this</td>
</tr>
</table>
That is what tables are made for.
If you want to use CSS you have to use DIVs.

Resources