html table background not showing? - html

I have a nested table inside each cell of my outer table.I want to set a background image for one of the cells so I created a specific class called "innerraya" to set the background image for that nested table.However,nothing seems to be changed at all.
HTML
<td class="luar">
<table class="innerraya">
<tr>
<td>7</td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="3" id="d7">
<p id="d7Event"></p>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td style="text-align:right">29</td>
</tr>
</table>
</td>
CSS
.innerraya
{
width:100%;
height:100%;
position:absolute;
background-image:url("daunketupat.jpg");
}
OUTPUT
it works now but the whole table is screwed up
The image is there if I used it as a td background or a normal img src but does not work if the whole table background is changed.What is the reason?

IT IS SOLVED!
The issue is that inner table layout is not fixed so I had to add this code inside the innerraya class.
table-layout: fixed;
The whole code looks like this :
table.innerraya
{
width: 100%;
height: 100%;
table-layout: fixed;
background-image: url("daunketupat.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
}
OUTPUT

Please go the url below, I have created a jsfiddle for you:
https://jsfiddle.net/ew55L41b/
Hope this will help you :)
Also the code is below:
<table>
<tr>
<td>
<table class="innerraya">
<tr>
<td>7</td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="3" id="d7">
<p id="d7Event"></p>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td style="text-align:right">29</td>
</tr>
</table>
</td>
<td>
<table class="">
<tr>
<td>7</td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="3" id="d7">
<p id="d7Event"></p>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td style="text-align:right">29</td>
</tr>
</table>
</td>
</tr>
</table>
CSS---
table.innerraya
{
width:100%;
height:100%;
position:absolute;
background-image: url("http://www.w3schools.com/cssref/paper.gif");
}

Related

Pattern table in HTML

I want to create a table as given. I have written the code for the first two columns but the output is incorrect. Need help figuring out my mistakes.
Ignore the little imperfections of the image of the table given in the question. They are not part of the output I desire.
Question-
My attempt for first two columns-
<table border="1" width="50%" height="50%">
<tr>
<td rowspan="6"></td>
<td rowspan="3"></td>
<td rowspan="1"></td>
</tr>
<tr>
<td rowspan="0" colspan="0"></td>
<td rowspan="3"></td>
<td rowspan="1"></td>
</tr>
</table>
Output-
What am I missing here?
I believe that this is what you're after:
table, td {
border: 1px solid #999;
}
table {
width: 100%;
}
td {
height: 50px;
}
<table>
<tr>
<td rowspan="4"></td>
<td rowspan="2"></td>
<td></td>
</tr>
<tr>
<td rowspan="2"></td>
</tr>
<tr>
<td rowspan="2"></td>
</tr>
<tr>
<td></td>
</tr>
</table>

How to set width of elements by relative ratio?

For example, I want to set the ratio of width of red:green:blue be 1:2:1 relative to parent, I tried using em, which seems got my desired result:
<table style="width:100%;height:50px;">
<tr>
<td style="height:100%;background-color:red;width:1em;">
</td>
<td style="height:100%;background-color:green;width:2em;">
</td>
<td style="height:100%;background-color:blue;width:1em;">
</td>
</tr>
</table>
but the element doesn't disappear when it has 0em:
<table style="width:100%;height:50px;">
<tr>
<td style="height:100%;background-color:red;width:1em;">
</td>
<td style="height:100%;background-color:green;width:0em;">
</td>
<td style="height:100%;background-color:blue;width:1em;">
</td>
</tr>
</table>
And according to the description of em, it seems unlikely used to define the relative width/height of element.
Is using em the correct way?If not, what is the correct way to achieve this?
Table element has cellspacing and cellpadding. Set cellpadding="0" like following. It will resolve your issue.
<table style="width:100%;height:50px;" cellpadding="0">
<tr>
<td style="height:100%;background-color:red;width:1em;">
</td>
<td style="height:100%;background-color:green;width:0em;">
</td>
<td style="height:100%;background-color:blue;width:1em;">
</td>
</tr>
</table>
This is called "cell-padding" simply give your table cell td a padding: 0;
<table style="width:100%;height:50px;">
<tr>
<td style="height:100%;background-color:red;width:1em;">
</td>
<td style="height:100%;background-color:green;width:0em;padding: 0;">
</td>
<td style="height:100%;background-color:blue;width:1em;">
</td>
</tr>
</table>
EDIT: After reading your post again, what you're searching for is percentage. This will allow you to use a percentage of the parents width.
A 1:2:1 ratio will be 25% : 50% : 25%
<table style="width:100%;height:50px;">
<tr>
<td style="height:100%;background-color:red;width:25%;">
</td>
<td style="height:100%;background-color:green;width:50%;">
</td>
<td style="height:100%;background-color:blue;width:25%;">
</td>
</tr>
</table>
<table style="width:100%;height:50px;border-collapse: collapse;">
<tr>
<td style="height:100%;background-color:red;width:50%;">
</td>
<td style="height:100%;background-color:green;width:0;">
</td>
<td style="height:100%;background-color:blue;width:50%;">
</td>
</tr>
</table>
Instead of em you can use %. check snippet below. Also add cellpadding="0"
<table style="width:100%;height:50px;" cellpadding="0">
<tr>
<td style="height:100%;background-color:red;width:25%;">
</td>
<td style="height:100%;background-color:green;width:50%;">
</td>
<td style="height:100%;background-color:blue;width:25%;">
</td>
</tr>
</table>
or you can go with flexbox
ul {
list-style: none;
display: flex;
padding: 0px;
}
li {
flex-grow:1;
}
li.double {
flex-grow: 2;
}
<ul>
<li style="background-color:red;">1</li>
<li class="double" style="background-color:green;">2</li>
<li style="background-color:blue;">3</li>
</ul>
I would insist not using tables for layout purposes and instead use divs but for your answer
<table style="width:100%;height:50px;">
<tr>
<td style="height:100%;background-color:red;width:50%;">
</td>
<td style="height:100%;background-color:green;width:0;">
</td>
<td style="height:100%;background-color:blue;width:50%;">
</td>
</tr>
</table>

How can i can keep my divs from resizing when i add/remove text?

I have a table with a lot of records and a search box
<table>
<tr>
<td class="col-3">name1</td>
<td class="col-3">sName1</td>
<td class="col-3">age1</td>
</tr>
<tr>
<td class="col-3">name..</td>
<td class="col-3">sName..</td>
<td class="col-3">age..</td>
</tr>
<tr>
<td class="col-3">nameN</td>
<td class="col-3">sNameN</td>
<td class="col-3">ageN</td>
</tr>
</table>
.col-3{
width:33,33%
}
Some of the records may be displayed as none, so if the search box returns a full "none" column it gets wraped to none as if it didnt have the "witdh:33,33%" atribute.
Anyone knows a way to keep the elements in his original size even if they dont have content?
Thanks in advance.
Try table-layout: fixed along with a fixed width for the table
table {
width: 100%;
table-layout: fixed;
}
.col-3 {
width: 33, 33%;
border: 1px solid grey;
}
<table>
<tr>
<td class="col-3">name1 askdlhaslkdhsaldsad asjd;kadaj as;dj;asjd as ;asjsd;asjd;ja</td>
<td class="col-3">sName1</td>
<td class="col-3">age1</td>
</tr>
<tr>
<td class="col-3">name..</td>
<td class="col-3">sName..</td>
<td class="col-3">age..</td>
</tr>
<tr>
<td class="col-3">nameN</td>
<td class="col-3">sNameN</td>
<td class="col-3">ageN</td>
</tr>
</table>
try this one:
<table style="border:1px solid">
<tr>
<td style="min-width:50px">one</td>
<td style="min-width:100px">two</td>
</tr>
</table>

Merging cells in a table doesn't work as expected

This is a table that I would like to achieve:
But I keep getting something like this:
This is what I've tried:
<table>
<tr>
<td rowspan="2">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2">d</td>
<td>e</td>
</tr>
</table>
Here's a link to JSFiddle with this (with some extra code for illustration): http://jsfiddle.net/2292D/
You need only vertical-align:middle and text-align:center
Apply this css to div
div {
display:table-cell; // Change
vertical-align:middle; //Change
border: 1px solid blue;
}
td {
border: 1px solid red;
text-align:center; // Change
}
Fiddle Demo
Good old days using table, use rowspan and colspan to achieve that kind of tablular structure, if you are using this for layout than don't, use div instead with float and CSS Positioning.
Demo
<table border="1" width="100%">
<tr>
<td rowspan="2" width="30%">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2" width="70%">d</td>
<td>e</td>
</tr>
</table>
I guess you need 3 rows for that, try my code:
<table>
<tr>
<td rowspan="2"><div id="a">a</div></td>
<td colspan="2"><div id="b">b</div></td>
</tr>
<tr>
<td colspan="2"><div id="c">c</div></td>
</tr>
<tr>
<td colspan="2"><div id="d">d</div></td>
<td><div id="e">e</div></td>
</tr>
Here's my fiddle: http://jsfiddle.net/LLe5c/
apply your id on td
html:
<table>
<tr>
<td id="a" rowspan="2"><div>a</div></td>
<td id="b" colspan="2"><div >b</div></td>
</tr>
<tr>
<td id="c" colspan="2"><div >c</div></td>
</tr>
<tr>
<td id="d" colspan="2"><div >d</div></td>
<td id="e"><div >e</div></td>
</tr>
</table>
Here is the Solution
<table>
<tr>
<td rowspan="2">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2">d</td>
<td>e</td>
</tr>
</table>
<style>
table {
border-collapse: collapse;
border-spacing: 0;
}
td {
border: 1px solid red;
}
</style>

Center a Table inside a TD

I have a very simple problem: I need to center a table inside a TD element. If I were using HTML 4 I'd do it like this:
​<table style="border:solid;width: 100%">
<tr>
<td align="center">
<table style="border:solid; width:50%">
<tr>
<td >I must be in the center</td>
</tr>
</table>
</td>
</tr>
</table>​
But I'm trying not to use deprecated attributes and do it the CSS way. I already tried this:
<td style="text-align:center">
And this:
<td style="margin: 0 auto">
And the tables keeps in the left-side of the cell. Any suggestions?
You had the right idea with margin:auto 0; just take off the 0.
Working example: http://jsfiddle.net/cxnR8/
<table style="border:solid;width: 100%">
<tr>
<td>
<table style="margin:auto;border:solid; width:50%">
<tr>
<td >I must be in the center</td>
</tr>
</table>
</td>
</tr>
</table>​
But, more importantly, do you really need to use tables and in-line styling?
Center the table using the deprecated align="" attribute.
<table>
<tr>
<td>
<table align="center">
<tr>
<td>in the middle</td>
</tr>
</table>
</td>
</tr>
</table>​
Your seccond suggestion is correct. See this working example.
HTML:
<table class="outer">
<tr>
<td>
<table class="inner">
<tr>
<td>in the middle</td>
</tr>
</table>
</td>
</tr>
</table>​
CSS:
.outer
{
width: 100%;
border: solid 1px red;
}
.inner
{
width: 25%;
margin: auto;
border: solid 1px blue;
}
​