i have a problem by open an html table to word.
I have a complex designed table, with table into tables-cells and so on. And now I need this table with the cell background-colors and the given borders in MS-Word.
<table class="tablebox">
<tr class="head">
<td class="cell10">Icon</td>
<td class="cell10">Status</td>
<td class="cell50">
<table class="group">
<tr class="colGroup">
<td>
<table class="box yellow">
<tr class="color">
<td class="leftbox"></td>
<td class="rightbox">6</td>
</tr>
</table>
</td>
<td>
<table class="box red">
<tr class="color">
<td class="leftbox"></td>
<td class="rightbox">12</td>
</tr>
</table>
</td>
<td>
<table class="box green">
<tr class="color">
<td class="leftbox"></td>
<td class="rightbox">7</td>
</tr>
</table>
</td>
<td>
<table class="box blue">
<tr class="color blue">
<td class="leftbox"></td>
<td class="rightbox">7</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td class="cell30">Maßnahmen</td>
</tr>
<tr class="sub">
<td colspan="4">
<table>
<tr class="colGroup">
<td>
<table class="box yellow">
<tr class="color yellow">
<td class="leftbox"></td>
<td class="rightbox">6</td>
</tr>
</table>
</td>
<td>
<table class="box red">
<tr class="color red">
<td class="leftbox"></td>
<td class="rightbox">12</td>
</tr>
</table>
</td>
<td>
<table class="box green">
<tr class="color green">
<td class="leftbox"></td>
<td class="rightbox">7</td>
</tr>
</table>
</td>
<td>
<table class="box blue">
<tr class="color blue">
<td class="leftbox"></td>
<td class="rightbox">7</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
http://jsfiddle.net/ndxp5h12/8/
But when i open the document with word my css-style is gone. The most of my cells an tables don't have a border, and the background color is gone too?
When i remove the element styling (table, th etc.) then the border are ok, but the color's doesn't show in Word.
Where is the problem? How can I fix my stylesheet or how can i structure my table? Is there a common way?
Which element or class override another in Word? Or what should I not do that word read the CSS correct?
Thank you
Felix
You may have to add all of your styles within style attributes on your individual tables and cells.
For example:
<table style="background-color:green">
<tr>
<td style="*leftbox styles*"></td>
<td style="*rightbox styles*">7</td>
</tr>
</table>
This maybe can help:
go to "insert" tab, click "object" button (it's on the right)
choose "OpenDocument Text" which will open a new embedded word document
copy and paste your code from Visual Studio / Eclipse inside this embedded word page
save and close
How do you display code snippets in MS Word preserving format and syntax highlighting?
Unfortunately Word has issues with many different HTML/CSS tags, so I'm afraid it's a case of trial and error. When it comes to dt and dd you could replicate the formatting you want by using CSS classes and then applying them to suitable HTML alternatives.
Related
I'm working on some HTML code for which I was given a UI. I tried to do most to make it look as close as possible. But I'm stuck with the header and line spacing pieces. Here is my code:
<div>
Hello, Alice! Here are your appointments for the day:
</div>
<div style="font-style:italic">
**All times are Arizona Time**
</div>
<table style="border:1px solid #e9e9e9">
<thead bgcolor="#8c8c8c" style="border-bottom:1px solid #e9e9e9; padding:none !important">
<tr>
<th style="width:auto">10:00AM - 10:30AM (30 MIN)</th>
<th style="width:auto; float:right">Abc</th>
</tr>
</thead>
<tbody>
<tr>
<td><div style="line-height:2em">
Topic:</div></td>
<td><div>Resume Review</div></td>
</tr>
<tr>
<td><div style="line-height:2em">Phone:</div></td>
<td>1234567890</td>
</tr>
<tr>
<td><div style="line-height:2em">Email:</div></td>
<td>abc#gmail.com</td>
</tr>
<tr>
<td><div style="line-height:2em">Student notes:</div></td>
<td>Hello,
My resume is pretty ugly, I built it based on what I learned in TAPS in military out-processing.
I will be standing by for the phone call, I missed my last one because I mixed up the appointment time zone.</td>
</tr>
</tbody>
</table>
Note: I need to use the inline styling, I can't use external CSS in my system.
Here is the UI provided:
How can I match the UI and also make it responsive?
Instead of using table for header, you can use div.
Check the below code.
<div>
Hello, Alice! Here are your appointments for the day:
</div>
<div style="font-style:italic">
**All times are Arizona Time**
</div>
<div style="border: 1px solid black">
<div style="width:100%; background-color:#8c8c8c; height:20px; display:flex;justify-content:space-between;align-items:center">
<p>10:00AM - 10:30AM (30 mins)</p>
<p>Data</p>
</div>
<table>
<tbody>
<tr>
<td>
<div style="line-height:2em">
Topic:</div>
</td>
<td>
<div>Resume Review</div>
</td>
</tr>
<tr>
<td>
<div style="line-height:2em">Phone:</div>
</td>
<td>1234567890</td>
</tr>
<tr>
<td>
<div style="line-height:2em">Email:</div>
</td>
<td>abc#gmail.com</td>
</tr>
<tr>
<td>
<div style="line-height:2em">Student notes:</div>
</td>
<td>Hello, My resume is pretty ugly, I built it based on what I learned in TAPS in military out-processing. I will be standing by for the phone call, I missed my last one because I mixed up the appointment time zone.</td>
</tr>
</tbody>
</table>
</div>
I need to add a display block to my tbody in order to make my page-break-inside working.
When I do that, the page break works on printing, but the table's shape is modified for one specific tbody.
html:
<div class="row section-content">
<table>
<tbody class="subsection">
<tr>
<th colspan="2">Personal infos</th>
</tr>
<tr class="check">
<td class="control-title">Is licensed</td>
<td class="check-body control-body">false</td>
</tr>
<tr class="text">
<td class="control-title">First name</td>
<td class="text-body control-body"> Gc yt?tv</td>
</tr>
<tr class="text">
<td class="control-title">Last name</td>
<td class="text-body control-body">Bhvug7y</td>
</tr>
<tr class="text">
<td class="control-title">Adress</td>
<td class="text-body control-body">Guvyb</td>
</tr>
<tr class="radioBtn">
<td class="control-title">Wants to suscribe to monthly discount</td>
<td class="radio-body control-body">No</td>
</tr>
<tr class="number">
<td class="control-title">Annual household income</td>
<td class="number-body control-body">10</td>
</tr>
</tbody>
<tbody class="subsection">
<tr>
<th colspan="2">Accomodation</th>
</tr>
<tr class="gps">
<td class="control-title">Location</td>
<td class="gps-body control-body">55.8755037, -4.2547716</td>
</tr>
<tr class="number">
<td class="control-title">Iso reference</td>
<td class="number-body control-body">15</td>
</tr>
<tr class="radioBtn">
<td class="control-title">Accomodation type</td>
<td class="radio-body control-body">House</td>
</tr>
</tbody>
</table>
</div>
Before:
]
After with display block:
After struggling with the same issue for days, i found that using display:table-row-group works perfectly for this situation.
display:block will disconnect the element from the parent table, causing this issue.
display:table-row-group render the element just like a <tbody>, keeping the DOM correct.
reference: https://www.w3schools.com/jsref/prop_style_display.asp
I do had the same problem and after searching all over i found a solution for my problem which is, first add a class to table which you dont want to break while printing like unbreakable now add css
.unbreakable td{
width: 100% !important;
}
.unbreakable tr{
page-break-inside: avoid !important;
}
It worked fine for me hope it works for you too... :) Thanks...
This sounds very similar to previous questions, but I've not found something that matches what I'm trying to do here.
My current code (very verbose with everything in line) looks like this:
td { border: 1px solid black }
<table style="table-layout:fixed">
<tr>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
</tr>
<tr>
<td style="width:25%;text-align:center">Some text here</td>
<td style="width:25%;text-align:center">More text</td>
<td style="width:25%;text-align:center">Hi</td>
<td style="width:25%;text-align:center">Somewhat longer text</td>
</tr>
</table>
What I'm trying to accomplish should look like this:
That is, the four main columns should all be the same width, which is the width of the largest content of any of the columns.
The green columns should always be 30px, and the red and blue columns should fill the remaining space each side of that middle column, only up to the width available in the auto-sized outer column.
Setting the internal tables to 100% width makes this happen, but of course the outer table then takes up the entire page width.
I'm also aware that using tables for this is probably not a great idea now we can use CSS, but I'd like to get this example working in tables before 'translating' it.
I'm very opposed to using JavaScript to solve this, for the record!
Edit: I also tried putting all 'subcolumns' in one row, and setting the text to colspan three at a time, with the 25% then applied to that. This ended up confusing the engine, and the width ended up about 75% of the page.
<table style="table-layout:fixed" border="1">
<tr style="font-size: 1px;">
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
</tr>
<tr style="font-size: 6px;">
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
</tr>
<tr>
<td colspan="3" style="text-align:center">Some text here</td>
<td colspan="3" style="text-align:center">More text</td>
<td colspan="3" style="text-align:center">Hi</td>
<td colspan="3" style="text-align:center">Somewhat longer text</td>
</tr>
</table>
this might solve your answer, your previous code html elements are not properly closed look on that also.
I'm trying to solve a problem: it's a HTML exercise in which I must write the HTML code for a table with this design:
But I can't seem to set it straight, here's my code:
<table border>
<tr>
<td rowspan="2" colspan="2"> Batatas </td>
<td rowspan="3" colspan="2"> Couves </td>
<td> Alhos </td>
<td> Cebolas </td>
</tr>
<tr>
<td rowspan="2" colspan="2"> Alface </td>
</tr>
<tr>
<td colspan="2"> Nabos </td>
</tr>
</table>
And here's the result:
Shouldn't the rowspan="2" in the first "td" tag make the first cell larger (in height)?
What am I doing wrong?
Try this online tool here: http://html-tables.com/
and you will see how the 3 rows collapse to 2 rows visually if you are using just cell merging.
I think you need to nest tables to achieve that effect.
Actually the problem you are facing is not because of your code it is because of general rules of html table rendering, this arises because of merging of table cells
To resolve this drawback of <table> tag, I'll recommend to use <div> tag as better approach.
Try this....
<table border>
<tr>
<td rowspan="2" colspan="1"> Batatas </td>
<td rowspan="3" colspan="1"> Couves </td>
<td rowspan="1" colspan="1"> Alhos </td>
<td rowspan="1" colspan="1"> Cebolas </td>
</tr>
<tr>
<td rowspan="1" colspan="2"> Alface </td>
</tr>
<tr rowspan="1" colspan="2">
<td> Nabos </td>
</tr>
</table>
Update
As I've noticed, this can't be done using <table> tag, You can use the div approach. These div tag are able to generate your layout.
I just finished working on your problem, and I've just solved your problem using <div> tag, Have a look
<div style=" background-color: powderblue;border:1px solid black; width:410px; height:310px">
<div style="float:left;">
<div style="border:1px solid black; width:100px; float:none; height:200px">Batatas
</div>
<div style="border:1px solid black; width:100px; float:none; height:99px">Nabos
</div>
</div>
<div>
<div style="border:1px solid black;width:100px; float:left; height:301px">Couves
</div>
<div style="border:1px solid black;width:100px; float:left; height:100px">Alhos
</div>
<div style="border:1px solid black;width:100px; float:left; height:100px">Cebolas
</div>
<div style="border:1px solid black;width:202px; float:left; height:199px">Alface
</div>
</div>
</div>
Good question. The closest I got (without getting crazy with nested tables) is simply this:
<table border>
<tr>
<td colspan="2"> Batatas </td>
<td rowspan="3" colspan="2"> Couves </td>
<td> Alhos </td>
<td> Cebolas </td>
</tr>
<tr>
<td colspan="2"></td>
<td rowspan="2" colspan="2"> Alface </td>
</tr>
<tr>
<td colspan="2"> Nabos </td>
</tr>
</table>
If this doesn't work for you (and you don't want to get into complex nested html tables), then I the common belief seems to be to move away from html tables to using CSS. Obviously with CSS/divs you have much more control.
i have a table that consists of two rows, the second row is a table, which i want it's elements to be centered to the main table, so my code is as follows:
<TABLE>
<TBODY>
<TR>
<TD>
<DIV id=gform:scan_area>
<OBJECT></OBJECT>
</DIV>
</TD>
</TR>
<TR>
<TD>
<TABLE style="PADDING-LEFT: 300px"> // works in firefox but doesn't work in ie9
<TBODY>
<TR>
<TD>
<INPUT>
</TD>
<TD>
<SPAN></SPAN>
</TD>
<TD>
<INPUT>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
ISSUE: TABLE style="PADDING-LEFT: 300px" works fine in firefox but doesn't work in IE9 (Quirks mode), please advise how to fix this issue or if you have any other ideas.
I think your code is not written well enough, it was much better if you used "colspan" for solving this issue.
Any way, I tried to change your code in a way that centralize the second table in the first table:
<TABLE>
<TBODY>
<TR>
<TD>
<DIV id='gform:scan_area'>
<OBJECT></OBJECT>
</DIV>
</TD>
</TR>
<TR>
<TD>
<TABLE style="width:60%">
<TBODY>
<TR>
<TD style="width:20%;padding-right:160px;">
<INPUT>
</TD>
<TD style="width:20%">
<SPAN></SPAN>
</TD>
<TD style="width:20%">
<INPUT>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
You need to do it this way
<div style="padding-left: 300px;">
<table>
...
</table>
</div>
For more read this answer: Padding table with CSS doesn't work on IE
Table padding is only applied to cells. By adding it to the <td> you will see it work in IE9 and Firefox. See: W3schools: Tables
<TABLE> // works in firefox but doesn't work in ie9
<TBODY>
<TR>
<TD style="PADDING-LEFT: 300px">
<INPUT>
</TD>
<TD >
<SPAN></SPAN>
</TD>
<TD>
<INPUT>
</TD>
</TR>
</TBODY>
</TABLE>