I try to remove white space between Table1Header and Table2Header. I tried border:0px, padding:0px and border-spacing:0px; styles. Firefox and Opera tell me that my border-spacing style is overrided by the user agent style (which is 2px). How can I force browser to use my styleshits?
http://jsfiddle.net/cdjDR/2/
<table class="tableGroup">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr class="tableHeader">
<td><span class="tableHeader"><label>Table1Header</label></span>
</td>
</tr>
<tr class=" tableData">
<td>
<div class="ui-datatable">
<div>
<table>
<thead>
<tr>
<th>
<div><span><span class="ui-header-text">Table1Col1</span></span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><span>2</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr class="tableHeader">
<td><span class="tableHeader"><label>Table2Header</label></span>
</td>
</tr>
<tr class="tableData">
<td>
<div class="ui-datatable">
<div>
<table>
<thead>
<tr>
<th>
<div><span><span class="ui-header-text" >Table2Col1</span></span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><span>12345</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
span.tableHeader > label {
display: inline-block;
float:left;
line-height:30px;
padding-left:10px;
color: #202020;
font-size: 13px;
}
tr.tableHeader {
background-color: #EEEEEE;
}
table.tableGroup, table.tableGroup > tr > td > table {
border-spacing: 0px;
}
table.tableGroup div.ui-datatable th > div > span >span.ui-header-text {
color: #808080;
font-size: 11px;
}
table.tableGroup td, table.tableGroup th {
padding: 0px;
border: 0px;
}
You can simply use border-collapse: collapse; or even border-spacing: 0; is fine
table { /* Will apply to all tables */
border-spacing: 0;
/* OR border-collapse: collapse; */
}
Demo
You can easily override the useragent stylesheet with a simple element selector.
If you want to normalize the styles, you should use CSS Reset
Coming to your selector which is seems dirty to me, as yo are targeting the table with class .tableGroup and the table nested under that
table.tableGroup, table.tableGroup > tr > td > table {
border-spacing: 0px;
}
So you better use
table.tableGroup,
table.tableGroup table {
border-spacing: 0;
}
you need to add (border="0" cellpadding="0" cellspacing="0") Table tributes in every table tag
example
<table border="0" cellpadding="0" cellspacing="0">
*example with your classes *
<table border="0" cellpadding="0" cellspacing="0" class="tableGroup">
Try this
table {
border-spacing:0px;
}
works by using css
The browsers are not telling you that your border-spacing style is overridden by the user agent style sheet. Instead, they may indicate that inheritance does not take place for it. This is simply caused by the fact that some style sheet sets the property on the element.
The reason why your rule is not applied to the inner table element is that it does not match any of your selectors. The selector
table.tableGroup > tr > td > table
does not match it, because a tr element is never a child of table even if might appear to be. By HTML syntax, there is an intervening tbody element, even if its start and end tag are missing. The following selector would match:
table.tableGroup > tbody > tr > td > table
Of course, a mere table selector would do the job as well, provided that you want all table elements to be styled by the rule.
Related
I have the following code and cannot figure out why it doesn't work :
table {
border: 1px solid black;
}
table.whole > tr > td {
padding: 20px 0 20px 0;
}
<!-- doesn't work via css rule -->
<table class="whole">
<tr>
<td>
<table>
<tr>
<td>abcd</td>
</tr>
</table>
</td>
</tr>
</table>
<hr>
<!-- works inline -->
<table>
<tr>
<td style="padding:20px 0 20px 0">
<table>
<tr>
<td>abcd</td>
</tr>
</table>
</td>
</tr>
</table>
May I misunderstand how the child selector > works or is there some kind of limitation here, or a bug ?...
If you inspect your code in the Chrome devtools, you will see that the browser has automatically inserted the required <tbody> element between the <table /> and rows for you. Because of this, the <tr /> is no longer the direct descendent of the <table />. So the issue is that your HTML is malformed/not adhering to the spec. If you add the <tbody /> element and rewrite your CSS accordingly, it will work just fine:
table {
border: 1px solid black;
}
table.whole > tbody > tr > td {
padding: 20px 0 20px 0;
}
<!-- doesn't work via css rule -->
<table class="whole">
<tbody>
<tr>
<td>
<table>
<tr>
<td>abcd</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
In HTML, there must be a <tbody> element between <table> and <tr> elements. Chrome is being nice, so it helpfully inserts it for you. However, that breaks your CSS, because now <tbody> is the child of <table>, and not <tr>.
Solution:
Include a <tbody> (otherwise it would be invalid and confusing), and change your CSS code to:
table.whole > tbody > tr > td {
padding: 20px 0 20px 0;
}
table {
border: 1px solid black;
}
table.whole > tbody /* ...and put it here. */ > tr > td {
padding: 20px 0 20px 0;
}
<table class="whole">
<tbody> <!-- include a <tbody> element... -->
<tr>
<td>
<table>
<tbody>
<tr>
<td>abcd</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Note: the inline styles work because they don't have any random selector errors because they're placed right in the <tbody> element.
I have a problem with my direct descendant selector. Look at a simple example:
.myDiv > table tr:first-child td {
font-weight: bold;
text-align: center;
}
<div class="myDiv">
<table style="width:100%">
<tr>
<td style="width:37%">Revenue & Cost</td>
<td style="width:43%">Name</td>
<td style="width:20%">Income</td>
</tr>
<tr>
<td>column 1</td>
<td colspan="2">
<table id="tableChild" width="100%">
<tr>
<td>child 1 - Should NOT bold</td>
<td>child 2 - Should NOT bold</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
As you can see, it will effect table id tableChild. I expect to get a bold font on the first row on the first table.
Here is my JSFiddle
First, finish defining the table correctly:
<table>
<thead>
<tr> TITLE ROW HERE </tr>
</thead>
<tbody>
CONTENT ROWS HERE
</tbody>
</table>
Then your CSS selector becomes:
.myDiv>table>thead>tr>td {
...
}
The browser fills in your missing table elements:
Try this:
.myDiv > table > tbody > tr:first-child td
https://jsfiddle.net/85t8qm5r/3/
I made a simple HTML table for this question.
I want to have a different style for the text and a different one for the numbers in the <td> and in the <tfoot>.
Can I style text differently from numbers in <td> and the <tfoot>?
and
What is the best way in the web practice to style a more complex table?
Update
Like this?
<td> 12<b>x</b>6 </td>
Here is my fiddle.
HTML
<table>
<caption>Woah</caption>
<thead>
<tr>
<th></th>
<th>Animalistic</th>
<th>People</th>
</tr>
</thead>
<tfoot>
<td>Run</td>
<td>1 x 92</td>
<td>1 x 92</td>
</tfoot>
<tbody>
<tr>
<td>John</td>
<td>9889 x 92</td>
<td>9889 x 92</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Bill</td>
<td>9889 x 92</td>
<td>9889 x 92</td>
</tr>
</tbody>
</table>
CSS
table {
width:300px;
background:#f5f7f3;
}
caption {
background:#000;
color:#fff;
}
th {
border:1px solid #000;
height:40px;
background:#b2b2b2;
}
td {
border:1px solid #b2b2b2;
}
add a < span > tag to the text with the style you want.
<td><span style="some style" or class = "some class"> some text </span></td>
You can't set different color for numeric value and text if they are in same tag. You have to give them separate tag. Like:
<td><span>1</span> text <span>92</span></td>
Then add css:
td span{
color:red;
}
Note: numeric values are in span tag and text value don't have any
tag. so with this css we can set color for numeric value and text
value different
There are numerous ways to target table elements. Here is an excellent list of available CSS selectors.
Example of the below.
Basic HTML structure (only one <tbody>):
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>9999 x 9999</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
</tr>
</tfoot>
</table>
To target the numbers separately, use a <span>:
<td>9999 <span>x</span> 9999</td>
OR
<td><span>9999</span> x <span>9999</span></td>
Target in the CSS with:
tbody td span {
/* styles */
}
Target every second row in the tbody with nth-child:
tbody tr:nth-child(even) {
background: #F00;
}
Target every td in the tbody:
tbody td {
text-align: center;
}
Target the first td of each row:
tbody td:first-child {
text-align: right;
}
Target the tfoot itself
tfoot {
background: #CCC;
}
<table class="table table-bordered table-hover table-condensed data_table">
<tbody data-bind="foreach: outboundFaxLogs">
<tr>
</tr>
<tr>
<td></td>
<td colspan="8">
<table>
<tr style="border:none">
<td>ReFax Status</td>
<td>FaxTo</td>
<td>Completion</td>
<td>FaxID</td>
</tr>
<tbody data-bind="foreach: ResubmissionHistory"">
<tr style="border:none">
<td data-bind="text: Status" ></td>
<td data-bind="text: FaxToNbr"></td>
<td data-bind="text: $root.formatDateTime(CompletionTime)"></td>
<td data-bind="text: OutboundFaxLogId"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
The parent table has a css class applied to it which is table-bordered. Its a twitter bootstrap style element. I don't want that style to be applied to the child table. How can I do this ? I do not want the lines that appear in between the table cells for the child table.
You can set this in your CSS
.table-bordered table, .table-bordered table th, .table-bordered table td {
border:0 none;
}
That makes your table inside the table with class .table-bordered no border.
If you open your bootstrap.css you can see that the tr and td borders are defined through
.table-bordered th,
.table-bordered td {
border: 1px solid #ddd !important;
}
so if you want to change it through inline you should use
<tr style="border:none!important;">
hope this helps
You should try to cancel style in your stylesheet :
.table-bordered table th,
.table-bordered table td {
border: 0 none !important;
}
For this Bootstrap styled table, I want the three columns (Sub1, Sub2, Sub3) widths to grow and align with their corresponding columns in the nested table.
http://jsfiddle.net/jamesholcomb/r55Zc/
Instead of using a nested <table>, simply use the rowspan attribute on the first column. Borders (and some padding) can be removed with some creative CSS (example):
CSS
th { text-align: center; }
tbody td {
border-width: 0 !important;
padding-top:0 !important;
}
tbody tr th ~ td {
border-top-width: 1px !important;
padding-top:8px !important;
}
tbody tr td:first-of-type {
border-left-width: 1px !important;
}
HTML
<div class="row">
<div class="span*">
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th colspan="3">Col1</th>
</tr>
<tr>
<th></th>
<th>Sub1</th>
<th>Sub2</th>
<th>Sub3</th>
</tr>
</thead>
<tbody>
<tr>
<th rowspan="3">Row1</th>
<td>[-01234543333545]</td>
<td>[4567]</td>
<td>[1]</td>
</tr>
<tr>
<td>[1]</td>
<td>[456.789]</td>
<td>[2]</td>
</tr>
<tr>
<td>[0]</td>
<td>[1]</td>
<td>[0000789.0123]</td>
</tr>
</tbody>
</table>
</div>
</div>
If you want the entire row to highlight correctly, I suggest you tweak your table as others have suggested. However, instead of creating multiple trs and giving the td a rowspan of 3 (which causes row highlighting problems), just list the data in the td as an unordered list and make some adjustments to the css.
Table:
<div class="row">
<div class="span*">
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th colspan="3">Col1</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>Sub1</td>
<td>Sub2</td>
<td>Sub3</td>
</tr>
<tr>
<td>Row1</td>
<td><ul><li>[-01234543333545]</li><li>[1]</li><li>[0]</li></ul></td>
<td><ul><li>[4567]</li><li>[456.789]</li><li>[1]</li></ul></td>
<td><ul><li>[1]</li><li>[2]</li><li>[0000789.0123]</li></ul></td>
</tr>
</tbody>
</table>
</div>
</div>
CSS:
td > ul {
list-style-type:none;
margin:0;
}
Here is the updated fiddle forked from #Mr.Alien's suggestions.