Using colspan and rowspan in same cell in HTML table - html

My default table looks like this, with 4 separate cells:
I want to create a table with this schema (merge r1c1 & r1c2 &r2c2):
My default table code is:
<table border="2">
<caption style="border: 1px dotted;">Table 1</caption>
<tr>
<td>r1c1</td>
<td>r1c2</td>
</tr>
<tr>
<td>r2c1</td>
<td>r2c2</td>
</tr>
</table>
And my merged table code look like this (but doesn't do what I wanted!):
<table border="2">
<caption style="border: 1px dotted;">Table 1</caption>
<tr>
<td colspan="2" rowspan="2">r1c1 & r1c2 & r2c2</td>
</tr>
<tr>
<td >r2c1</td>
</tr>
</table>
How do I get those three cells merged using colspan and rowspan?

No you cannot implement this with table cells. However, A similar layout can be displayed using css styles as shown in this fiddle.
html
<table border="2">
<caption style="border: 1px dotted;">Table 1</caption>
<tr>
<td id="r1c1" colspan="2">r1c1 & r1c2</td>
</tr>
<tr>
<td>r2c1</td>
<td id="r2c2" rowspan="2">r2c2</td>
</tr>
</table>
css
#r1c1 {
border: none !important;
}
#r2c2 {
border: none !important;
}
You can create a similar L shape using div tags by applying similar css styles as shown in this fiddle. Also you can refer this link to find css styles for creating various shapes.

Related

HTML table - td under another td

I want to layout my table TDs like the image below.
I tried a few ways and tried looking up how, but I couldn't get my hands on much. This is the code I have currently. It doesn't work and makes it look like a normal table with all the TDs aligned horizontally. Any tip or clue would be wonderful!
<table>
<td rowspan="2" colspan="1">td1</td>
<td rowspan="1" colspan="2">td2</td>
<td rowspan="1" colspan="2">td3</td>
</table>
<table border="1">
<tr>
<td rowspan="2">td1</td>
<td>td2</td>
</tr>
<tr>
<td>td3</td>
</tr>
</table>
Fiddle: http://jsfiddle.net/oou92y33/

HTML tables side by side (sharepoint) (without CSS/style)

I am trying to have two HTML tables side by side on a Sharepoint webpage. I have noticed that Sharepoint strips anything away from in between <style></style> tags. Also strips information in <div><\div> tags.
I have this, currently.
<body>
<div>
<table style="width:40%" border="1px solid black" float="left" width="148px" margin-right=" 4%">
<caption>List</caption>
<tr>
<td>3</td>
<td>3 TB</td>
<td>10</td>
</tr>
<tr>
<td><b>P</b></td>
<td><b>S</b></td>
<td><b>U</td>
</tr>
</table>
<table style="width:40%" border="1px solid black" float="left" width="148px" margin-right=" 4%">
<caption>Arts List</caption>
<tr>
<td>3</td>
<td>3</td>
<td>10</td>
</tr>
<tr>
<td><b>P</b></td>
<td><b> S</b></td>
<td><b>U</td>
</tr>
</table>
/div>
Is it even possible to have two HTML tables side by side in sharePoint. (Without div/style tags)
Use nested tables.
<table>
<tr>
<td>
<table>
...
</table>
</td>
<td>
<table>
...
</table>
</td>
</tr>
</table>
You can have two tables next to each other by floating them left and making the widths small enough to fit horizontally like so:
<table style="float:left;width:50%;box-sizing:border-box;">
...
</table>
<table style="float:left;width:50%;box-sizing:border-box;">
...
</table>
The style attribute should be one continuous string.
So this
<table style="width:40%" border="1px solid black" float="left" width="148px" margin-right=" 4%">
should be this
<table style="width: 40%; border: 1px solid black; float: left; width: 148px; margin-right: 4%;">
I had the same problem in my job and I do not have the permission to use SharePoint designer;
To have 2 different tables in a single "Layout Column" I did the following:
1) Create a table with 1 row and 2 columns.
2) Inside each column add the table. The table would fit automatically or you can modify the width and the high on the ribbon.
3) Change the style of the 1st table to "Table Style 1 - Clear" to eliminate the border.

HTML table border issue in nested table

I have nested table. Both tables needs border. The only difference is that I need only the bottom border of the inner table rather having top, bottom, right and left. I need the default border style which comes using the following code.
<table border="1">
Problem comes when I use this code for the inner table. It sets the outer border too rather setting bottom border. If I remove top right and left border it does not remove the border correctly. Please check the following code which I used to fix this issue.
<table border="1" width="100%">
<tr>
<td valign="top">VMware Certified Professional</td>
<td style="padding:0px;">
<table border="1">
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
</table>
</td>
</tr>
<tr>
<td valign="top">VMware Certified Associate</td>
<td style="padding:0px;">
<table border="1">
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
<tr><td>hello</td></tr>
</table>
</td>
</tr>
</table>
Screenshot is attached to show default border style which I need.
Attached is the layout which I want
Is this what you are looking for?
http://jsfiddle.net/5Ax52/1/
Using CSS:
table.inner td {
border-top: 1px solid #444;
border-bottom: 1px solid #afafaf;
width:100%;
}
There are two inner tables, and assuming that “I need only the bottom border of the inner table rather having top, bottom, right and left” refers to both of them, just set the borders you don’t want to none as follows (see jsfiddle):
<style>
table table {
border-top: none;
border-left: none;
border-right: none;
}
</style>
An alternative, pure HTML way (which works well, despite being flagged “deprecated” in HTML 4 and “obsolete” in HTML5) is to use the attribute frame="below" in the inner <table> elements. See alternative jsfiddle.
The results look odd, though, and maybe you meant to ask something different.
After going trough many solutions. I found the following solution good for me.
<style>
.tbl_head{ width:35%;}
</style>
<table cellpadding="3" border="1" align="center">
<tr>
<td rowspan="3" valign="top" class="tbl_head">ALIGNVALIGNALIGN</td>
<td>First</td>
</tr>
<tr>
<td>Second</td>
</tr>
<tr>
<td>Third</td>
</tr>
<tr>
<td rowspan="3" valign="top" class="tbl_head">VALIGNALIGNVALIGN</td>
<td>First</td>
</tr>
<tr>
<td>Second</td>
</tr>
<tr>
<td>Third</td>
</tr>
</table>

Aligning both rows and columns in a nested table

I am trying to process an XML file via XSLT to produce an HTML report. The report contains a table with 3 columns: Description, Date and Note. One row of this table may contain one description, but multiple dates and notes. The dates and notes for a single description form pairs, but sometimes either a date or a note is missing. I could have the following problems:
A note does not have a corresponding date, so the date-note pair representation is skewed (See Date 1.2 and Note 1.2 in the example). A desired representation would have an empty line followed by Date 1.2 on a different line.
A note spans multiple lines, but its corresponding date does not, so the following notes are not aligned with their dates.
Here is an example. I used <br/> elements for demonstration purposes.
<table>
<tr>
<td class="firstcolumn">Description</td>
<td>Date</td>
<td class="lastcolumn">Note</td>
</tr>
<tr>
<td class="firstcolumn">Description 1. Could span multiple lines.</td>
<td valign="top" align="right">Date 1.2</td>
<td valign="top" align="right" class="lastcolumn">Note without date 1.1<br/> Note 1.2</td>
</tr>
<tr>
<td class="firstcolumn">Description 2.</td>
<td valign="top" align="right">Date 2.1<br/> Date 2.2</td>
<td valign="top" align="right" class="lastcolumn">Some really long note<br/>spanning multiple lines 2.1<br/> Note 2.2</td>
</tr>
</table>
Here is a link to a fiddle: JSFiddle.
I tried to solve this with nested tables: for each row of the outer table, I created a nested table with 2 columns, each row of which contained a date-note pair (or an empty cell and a note). The dates and notes now align. However, the nested table column widths do not align across the rows of the outer table. I tried to solve this by setting all nested table widths using the styles
table { width:100%;table-layout:fixed;} /* for each nested table */
td {width:90px;} /* for the columns of nested tables */
The columns now align. However, sometimes the notes are cut off and not visible (using the overflow style I can make them appear outside the table border, but it looks ugly). Ideally, I would want to have column widths that adjust to the notes' lengths.
I think I made it!
What I did is:
I broke the 2nd and 3rd rows in two
to the first one I gave rowspan="2"
I created two classes: bt and bb
table {
border-collapse: collapse;
width: 75%;
}
td {
border-collapse: collapse;
border: 1px solid black;
padding: 0px;
margin: 0px;
font-family: Calibri;
}
td.firstcolumn {
width: 60%;
}
td.lastcolumn {
width: 25%;
}
.bt {
border-top: 0;
}
.bb {
border-bottom: 0;
}
<table>
<tr>
<td class="firstcolumn">Description</td>
<td>Date</td>
<td class="lastcolumn">Note</td>
</tr>
<tr>
<td rowspan="2" class="firstcolumn">Description 1. Could span multiple lines.</td>
<td class="bb" valign="top" align="right"></td>
<td class="bb" valign="top" align="right">Note without date 1.1</td>
</tr>
<tr>
<td class="bt" valign="top" align="right">Date 1.2</td>
<td class="bt" valign="top" align="right" class="lastcolumn"> Note 1.2</td>
</tr>
<tr>
<td rowspan="2" class="firstcolumn">Description 2.</td>
<td class="bb" valign="top" align="right">Date 2.1</td>
<td class="bb" valign="top" align="right" class="lastcolumn">Some really long note<br/>spanning multiple lines 2.1</td>
</tr>
<tr>
<td class="bt" valign="top" align="right"> Date 2.2</td>
<td class="bt" valign="top" align="right" class="lastcolumn">Note 2.2</td>
</tr>
</table>
Here's a fiddle
Assuming that you need to adjust width automatically based on contents try changing in example provided here
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_td_width
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td width="70%">January</td>
<td width="30%">$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
<p>The width attribute is not supported in HTML5. Use CSS instead.</p>
</body>
</html>

Issue with aligning table cell exactly on dotted line

I have dotted line separating two rows of the table like below.
<table cellspacing="0">
<tr>
<td>Issue</td>
<td>Date</td>
</tr>
<td style="border-bottom: 1px dotted red;padding-top:2px;width:800px;"></td>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td></tr>
</table>
This is fiddler version. I want to align that date on line somewhere not at the end. How can I do that.
Add colspan = "2" to the td that has the dotted line. colspan and rowspan define how many columns or rows the cell spans, respectively.
Here's a modified version of your demo: little link.
<table cellspacing="0">
<tr>
<td>Issue</td>
<td >Date</td>
</tr>
<tr>
<td class="td"></td>
<td class="td"></td>
<tr>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td>
</tr>
</table>​
CSS:
.td{
border-bottom: 1px dotted red;width:800px;padding-top:2px;
}
DEMO
Please try this:
<table cellspacing="0">
<tr>
<td>Issue</td>
<td>Date</td>
</tr>
<tr style="border-bottom: 1px dotted red;padding-top:2px;width:800px;"><td></td><td ></td></tr>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td></tr>
</table>