HTML table with vertical headers & cells with equal width - html-table

I'm trying to create a table that the header is to the left and content is at the same line with same width.
Result of my trying is in the code snippet below. Cells content is not barking in to reasonable cell size and it is render just into a very long horizontal line (instead of breaking into few lines).
.table-demo {
text-align: center;
border-collapse: collapse;
table-layout: fixed;
overflow: visible;
display: table;
}
.table-demo tr {
display: inline-block;
}
.table-demo th, td {
display: block;
/*width:100%;*/
border: 1px solid;
}
.wrapper {
/*overflow-x: auto;*/
white-space: nowrap;
max-width:600px;
}
<div class=" col-md-10 wrapper " >
<table class="table table-responsive table-demo" width="100%;">
<tr>
<th>
Spec
</th>
<th>
Spec 2
</th>
<th>
Tect de
</th>
<th>
Price
</th>
<th>
Terms
</th>
</tr>
<tr>
<td>
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
<td>
Offertext 2
</td>
<td > Lorem Ipsum is simply dummy text of the printing and t versions of Lorem Ipsum.
</td>
<td>
<p>789.00</p>
</td>
<td>
+40
</td>
</tr>
<tr>
<td>
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
<td>
Offertext 2
</td>
<td > Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</td>
<td>
<p >999.00</p>
</td>
<td>
30
</td>
</tr>
<tr>
<td>
Lorem Ipsum issoftware like Aldus PageMaker including versions of Lorem Ipsum.
</td>
<td>
Offertext 2
</td>
<td > Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.
</td>
<td>
811.00
</td>
<td>
30
</td>
</tr>
</table>
</div>
I would like it to:
a. The table to fit into bootstrap 10 col.
b. All cells to have the same width.
c. Long text to brake the multi line.

Hi,
to achive vertical headers in a table I suggest simply put a th cell into a table row instead of attempt do it with CSS.
I prepared a sample which meets your requirements from the question.
table, th, td {
border: 1px solid tomato;
border-collapse: collapse;
}
/*Point b: all cells have the same width*/
th, td {
width: 50%;
}
<table>
<tr>
<th>Short</th>
<td>Mallard is a kind of duck.</td>
</tr>
<tr>
<th>Empty row</th>
<td></td>
</tr>
<tr>
<th>What is Lorem Ipsum?</th>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
</tr>
</table>
Cheers

Related

How to find span element in selenium webdriver which is not having any other attributes?

I have a report which is completely of HTML based. I'm trying to automate and using selenium webdriver for finding the elements. In one of the part, below is the HTML format
<tbody>
<tr>
<td style="border: 1px solid #D1D1D1; background-color:#F4F4F4; color: #707070;padding :2px;">
<table style="width: 100%;
border-collapse: collapse; font-size: 15px;font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;" role="presentation">
<tbody><tr>
<!--Action Date -->
<td></td>
<td width="100%" valign="top" align="right">
<span style="font-size: 12px;">12/7/20 10:21 AM</span>
</td>
</tr>
<tr>
<!-- Name and status column -->
<td style="" width="25" valign="top" align="center">
<img src="images/qual_checkmark_24.png" alt="">
</td>
<td width="535">
<span>First line of <strong>TEXT</strong></span>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td style="border: 1px solid #D1D1D1; background-color:#F4F4F4; color: #707070;padding :2px;">
<table style="width: 100%;
border-collapse: collapse; font-size: 15px;font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;" role="presentation">
<tbody><tr>
<!--Action Date -->
<td></td>
<td width="100%" valign="top" align="right">
<span style="font-size: 12px;">12/7/20 10:18 AM</span>
</td>
</tr>
<tr>
<!-- Name and status column -->
<td style="" width="25" valign="top" align="center">
<img src="images/qual_arrowupcircleblue_24.png" alt="">
</td>
<td width="535">
<span>Second line of<strong>TEXT</strong></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
I wanted to find the text in span tag (eg: first line of text, second line of text ) where i don't have any other attributes. I tried various other way of finding it via xpath, cssSelector and nothing works. Could someone help?
Try to use this XPath to select span nodes without attributes:
//span[not(#*)]
//tbody/tr[2]/td/span
you can use the parent as reference, in the html you provided the span is under the tr which is second element of tbody.
//tbody/tr[2] , will find all elements which are second child of tbody , and then direct child td/span
A combination of both answers would be probably best:
//tbody/tr/td/span[not(#*)]
It's still flexible and less error-prone at the same time.
There are two sets of <span> tags. One that holds the datetime e.g. 12/7/20 10:18 AM and the other that holds the text e.g TEXT.
To print the list of <span> tag texts you need to induce WebDriverWait for the visibilityOfAllElementsLocatedBy() and you can use Java8 stream() and map() and you can use either of the following Locator Strategies:
xpath:
List<String> myTexts = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//tbody//tr/td/table/tbody//tr//td/span[./strong]"))).stream().map(element->element.getText()).collect(Collectors.toList());
System.out.println(myTexts);

How to align misaligned p-table headers in angular after enabling the scroll?

I am having a p-table with and body. Before enabling the scroll, checkboxes in header and body and other header alignments were perfect. But after adding [scrollable]=true and scrollHeight="200px" to p-table tag, headers are misaligned with rows.
Below is my code for p-table :
<p-table [columns]="columns" [value]="values" [(selection)]="selectedRowData"
[scrollable]="true" scrollHeight="200px">
<ng-template pTemplate="header" let-gridColumns>
<tr>
<th style="width: 3em">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
<th *ngFor="let col of gridColumns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-gridColumns="columns">
<tr>
<td>
<p-tableCheckbox [value]="rowData"></p-tableCheckbox>
</td>
<td *ngFor="let col of gridColumns" style="word-break: break-all; max-width: 100px;">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
can someone help me aligning the headers with its row?
Thanks in advance
I faced same issue and in my scenario it was resolved by adding [scrollable]="true" after scrollHeight and add width to columns. like
<p-table [columns]="columns" [value]="values" [(selection)]="selectedRowData" [responsive]="true"
scrollHeight="248px" scrollDirection="both" [autoLayout]="true" [scrollable]="true">
<ng-template pTemplate="header" let-gridColumns>
<tr>
<th style="width: 3em">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
<th style="width: 100vw;" *ngFor="let col of gridColumns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-gridColumns="columns">
<tr>
<td style="width: 3em">
<p-tableCheckbox [value]="rowData"></p-tableCheckbox>
</td>
<td *ngFor="let col of gridColumns" style="width: 100vw !important; overflow: hidden; text-overflow: ellipsis;">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
Note:
Data is displayed as ellipsis after 100vw
Width on th accordingly same as on td
I had the same issue and my resolution had part of the previous answers but also required min-width to be set. Yours may work without the min-width but mine required it to function properly. We are on PrimeNG "primeng": "11.3.1",
Working example:
#idOfPTableElement {
th {
width: 100vw !important;
min-width: 210px;
}
td {
width: 100vw !important;
min-width: 210px;
}
}
Relative to this topic/issue, the header and the body of the p-table are separate tables. In addition, I had to use the following to fix the body (actual table data section/body) alignment issues I experienced. Without it, the lower table was indented looking and was never in alignment with the upper table (header table)
.p-datatable-scrollable-header-box {
padding-right: 0px !important;
}

How to indent kit component items on Advanced PDF packing slip

I am setting up a customized packing slip form via Advanced PDFs in NetSuite and need help fulfilling a certain formatting request. I am having trouble with the placement of the code to indent only kit items and not their components. NetSuite will not accept my changes on the form due to the misplacement of #list and #if tags. If someone could assist clearing this issue up for me by showing an example of what that should look like, it would be most appreciated. Let me know if more information is needed here and thanks! -Ryan I have tried placing the code before and after the #list tag.
<table class="itemtable" style="width: 100%; margin-top: 10px;">
<thead>
<tr>
<th colspan="12">${salesorder.item[0].item#label}</th>
<th align="right" colspan="4">${salesorder.item[0].quantityordered#label}</th>
<th align="right" colspan="4">${salesorder.item[0].quantityremaining#label}</th>
<th align="right" colspan="4">${salesorder.item[0].quantity#label}</th>
</tr>
</thead>
<#list salesorder.item as tranline> //callout to list items from item fulfillment
<#if tranline.custcol_9r_noncomponent='T'> //checks to see if items are kits items or not
<#if tranline.custcolitemtype="Kit/Package"><tr style="font-weight:bold"> //bolds kit items
<#else><tr style="font-weight:normal"> //if not kit item, uses normal formatting
</#if> //for kit items use this formatting
<td width="15%" class="item" font-size="7pt">${tranline.item}</td>
<td width="20%" class="item">${tranline.description}</td>
<td width="8%" class="item" align="center">${tranline.quantityremaining}</td>
<td width="8%" class="item" align="center">${tranline.quantity}</td>
<td width="8%" class="item"> </td>
<td width="9%" class="item"> </td>
</tr>
<#else> //for component items, use this formatting
<tr>
<td width="15%" class="kititem" font-size="7pt"> ${tranline.item}</td>
<td width="20%" class="kititem">${tranline.description}</td>
<td width="8%" class="kititem" align="center">${tranline.quantityremaining}</td>
<td width="8%" class="kititem" align="center">${tranline.quantity}</td>
<td width="8%" class="kititem"> </td>
<td width="9%" class="kititem"> </td>
</tr>
</#if> //should refer to tranline.custcol_9r_noncomponent='T'statement
</#list> //should close the callout for list items
</table> //ends table

Attempting to make block elements touch each other in Mailchimp

Even though I set padding to "0" in Mailchimp design areas, my content blocks don't butt up and touch each other, there is a whitespace between the blocks. I dragged over and inserted a code block, but I don't know what to put in it to make these items touch. I added a picture of the code block input area. Can somebody please tell me what code to put in this area? Thanks so much in advance. I removed the > so that it would render on the page. Sorry for being such a newbie with this.
This is in the code box. div class="mcnTextContent" Use your own custom HTML /div
I found this Mailchimp workaround in a Facebook feed:
Use the Code block to build your sections and remove padding and spacing.
Drag a Code block into your layout. Delete the code that is already in there. Copy and paste the code shown below into the block, save and close.
<table style="max-width:100%; min-width:100%;background-color:#FF0000;" class="mcnTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left">
<tbody>
<tr>
<td class="mcnTextContent" style="padding: 10px 18px 9px; line-height: 200%;" valign="top">
<p class="null" style="font-family: helvetica; font-weight:700; font-size: 35px;text-align:center;color:white">September 2018 Newsletter</p>
</td>
</tr>
</tbody>
</table>
Drag another Code block into your layout, below the block you just created. Delete the code that is already in there. Copy and paste the code shown below into the block, save and close.
<table class="mcnTextBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody class="mcnTextBlockOuter">
<tr>
<td class="mcnTextBlockInner" style="padding-top:0px;" valign="top">
<!--[if mso]>
<table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;">
<tr>
<![endif]-->
<!--[if mso]>
<td valign="top" width="600" style="width:600px;">
<![endif]-->
<table style="max-width:100%; min-width:100%; background-color:#c0c0c0" class="mcnTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left">
<tbody><tr>
<td class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;" valign="top">
<h1 style="text-align:center">It's time to design your email.</h1>
<p>Now that you've selected a template, you'll define the layout of your email and give your content a place to live by adding, rearranging, and deleting content blocks.</p>
<p>By using image with caption blocks in multi-column templates, you can create a product grid that works perfectly for e-commerce.</p>
<p>If you need a bit of inspiration, you can <a class="mc-template-link" href="http://inspiration.mailchimp.com">see what other MailChimp users are doing</a>, or <a class="mc-template-link" href="http://mailchimp.com/resources/email-design-guide/">learn about email design</a> and blaze your own trail.</p>
</td>
</tr>
</tbody></table>
<!--[if mso]>
</td>
<![endif]-->
<!--[if mso]>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
Original Facebook feed - click on comments to see original feed

Outlook not respecting table cell width in html email

I am trying to create an HTML email that uses gradients that will render properly in all email clients. I initially tried a vertically repeating 1px by 13px image background using a TD property and CSS but Outlook said "no." Now I have gone to making 13 TD's with a width of 1px and background colors that make up the gradient, but outlook is rending them as about 3px wide with 1px borders.
Here is the code. How can I please Outlook, or is there a way to please Outlook?
<table width="730px" cellpadding="0px" cellspacing="0" border="0" style="border-collapse:collapse; font-size: 12px; line-height: 1.2; font-family: Arial; margin-left:auto; margin-right:auto; margin-bottom:0;" bgcolor="#fbebd8">
<tr valign="top">
<td bgcolor="#fff" width="1px"> </td>
<td bgcolor="#fff" width="1px"> </td>
<td bgcolor="#fdfcfa" width="1px"> </td>
<td bgcolor="#fcf8f5" width="1px"> </td>
<td bgcolor="#f7f2ee" width="1px"> </td>
<td bgcolor="#f2e7e1" width="1px"> </td>
<td bgcolor="#efded4" width="1px"> </td>
<td bgcolor="#e9d3c5" width="1px"> </td>
<td bgcolor="#dfc8b6" width="1px"> </td>
<td bgcolor="#d9bba3" width="1px"> </td>
<td bgcolor="#e4cab3" width="1px"> </td>
<td bgcolor="#ddc7b0" width="1px"> </td>
<td bgcolor="#ebd9c3" width="1px"> </td>
<td bgcolor="#f9e7d1" width="1px"> </td>
<td>
<!-- embedded half-left table -->
<table width="348px" cellpadding="5px" cellspacing="0" border="0" style="border-collapse:collapse; font-size: 12px; line-height: 1.2; font-family: Arial;">
<tr>
<td colspan="3" valign="top">
<p><strong>Lorem Ipsum</strong></p>
</td>
</tr>
<tr>
<td>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</td>
<td > <img width="4px" src="CaseNotes/greenbox.jpg" /> </td>
<td valign="top"> <img src="CaseNotes/archive/20120815-honors-college.jpg" alt="" height="81" width="100" /> </td>
</tr>
</table>
<!-- end half-left table -->
</td>
<td bgcolor="#999999" > <img width="2px" src="CaseNotes/greybox.jpg" /> </td>
<td>
<table width="348px" cellpadding="5px" cellspacing="0" border="0" style="border-collapse:collapse; font-size: 12px; line-height: 1.2; font-family: Arial;" >
<!-- half-right table -->
<tr valign="top">
<td valign="top" colspan="3">
<p><strong>Lorem Ipsum</strong></p>
</td>
</tr>
<tr>
<td valign="top">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</td>
<td > <img width="4px" src="CaseNotes/greenbox.jpg" /> </td>
<td> <img src="CaseNotes/superman.jpg" alt="" height="150px" width="150px" /> </td>
</tr>
</table>
<!-- end half-right table -->
</td>
<td bgcolor="#f9e8d4" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#e7cfb8" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#ead2bb" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#e5c8b0" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#b17853" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#b88460" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#c29371" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#cca385" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#d5b39a" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#ddc2ad" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#e5cfbe" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#ebdbce" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#f1e5dc" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#f6efe9" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#faf5f2" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#fdfaf9" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#fefefd" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
<td bgcolor="#fffefe" width="1px"> <img src="http://greenandgold.uaa.alaska.edu/chancellor/casenotes/images/clear1x1.png" /> </td>
</tr>
</table>
<!-- end super table -->
I don't know if this is the issue or not but, when defining a width out of css, but as a property, you don't define it with a px.
For instance: <td width="1">
In comparison, css would make it: <td style="width:1px;">;
Try declaring your width twice. Once as an html attribute and once as an inline css-style.
For example try this:
Some e-mail clients use the html attributes, I think Outlook 2010 uses the inline style.
foolproof backgrounds for emails: http://emailbg.net/
put your hosted image url on the top left, make sure sure your image dimensions are correct in the code (you may have to hit enter again in the top left text-box), and make sure you click single table cell :)
I use this frequently. Tested in Litmus and fully compliant across the board.