Why are my CSS classes having no effect - html

Why cant i get background to change when i reference via a css style sheet, but works okay when done directly with color on inline style (i.e only columns 1 and 4 change their background color)
<table>
<tr>
<td bgcolor="#D6D6C2">Column 1</td>
<td class="releasetableheading">Column 2</td>
<td class=".releasetableheading">Column 3</td>
<td style="background-color:#D6D6C2">Column 4</td>
</tr>
</table>
CSS
.releasetableheading {
background-color=#D6D6C2;
}
See http://jsfiddle.net/ijabz/vnkqhz5h/ for full example

Your syntax is off. Use colon instead of equals sign, and remove period from class declaration.
Updated Fiddle - http://jsfiddle.net/vnkqhz5h/1/
HTML:
<table>
<tr>
<td bgcolor="#D6D6C2">Column 1</td>
<td class="releasetableheading">Column 2</td>
<td class="releasetableheading">Column 3</td>
<td style="background-color:#D6D6C2">Column 4</td>
</tr>
</table>
CSS:
.releasetableheading {
background-color: #D6D6C2;
}
Note that bgcolor is deprecated and should not be used and you should use classes, not inline styles whenever possible.

You should not use bgcolor attribute, it's not supported in HTML5. In HTML, you simply define your class that way :
<td class="myClass"></td>
And you can define a unique ID for an HTML element that way
<td id="myId"></td>
Then, in your CSS, the syntax has to be written that way:
.myClass{
background-color: #000;
}
#myId{
background-color: #fff;
}
Suffix for class is a dot (.) and for id is a hashtag (#).
You always write your property that way in CSS. "property: value".
Hope it helped !

Related

CSS applied to one table does not work on another

While working on some dynamic styling for tables I ran across an issue that took me down a rabbit hole trying to apply a class and is driving me crazy. I believe I found the root of my problem with this, but do not understand why it is happening. I have a working CSS class applied to a table and displaying as expected - lets call the class "foo". I noticed that I could not get any CSS to work on another table - lets call that CSS class "bar". Here is the HTML for it:
.foo th,
.bar th {
background-color: #007FA4;
}
.foo tr:nth-child(even),
.bar tr:nth-child(even) {
background-color: #D5D8DC;
}
.foo tr:hover,
.bar tr:hover {
background-color: #3498DB;
}
.foo th,
.bar th {
background-color: #87BED4;
}
<table class="foo">
<tr>
<th>Foo Header</th>
</tr>
<tr class="sub-header">
<th>Col</th>
</tr>
<tr>
<td>Test 1</td>
</tr>
<tr>
<td>Test 2</td>
</tr>
</table>
<table class="bar">
<tr>
<th>Bar Header</th>
</tr>
<tr>
<th>Col</th>
</tr>
<tr>
<td>Test 1</td>
</tr>
<tr>
<td>Test 2</td>
</tr>
</table>
When I apply this, my "bar" table does not have any formatted applied to it. However, if I change the "bar" table's class to be "foo" (no change to the CSS) it works and both tables are formatted.
This leads me to believe I am missing/do not understand something that is going on behind the scenes of CSS. What would cause this type of behavior?

how to transform my HTML table to responsive without additional CSS file?

how to transform my HTML table to responsive without additional CSS file?
<table style="overflow-x:auto;">
<tbody>
<tr>
<td><b>title 1</b></td>
<td><b>title 2</b></td>
<td><b>title 3</b></td>
</tr>
<tr>
<td>text 1</td>
<td>text 2</td>
<td>text 3</td>
</tr>
</tbody>
If you want to add CSS to make your table responsive, but do not want the CSS to be in a separate file, then you have two options:
You can put your CSS rules inside a <style> tag in the HTML file (reference)
You can use inline styles as #Peter suggested. (reference)
Inline styles can quickly become messy and hard to read, so I would recommend that you use a <style> tag.

Overriding <tr> styling for <td> using sass

I'm currently working on a rails application where I want to highlight a row with a background colour, but in addition to that, within that row highlight a data cell with a different colour.
The problem I have is the styling for the td appears to be ignored. I just get the background colour for the whole row.
Inspecting the css client side it appears that the styling I apply for the td simply isn't there.
The generated html
<table id="project-table" class="table table-hover">
<thead>
<tr>
<th>Row</th>
<th>Fubar</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row cheese">
<td>Row 1</td>
<td class="'wibble'">Hello World</td>
</tr>
</tbody>
</table>
The sass
#project-table tbody tr.cheese {
background-color: yellow;
& td.wibble {
background-color: blue;
}
}
What am I doing wrong?
ps: using bootstrap 3 but I don't think that's relevant to this issue, is it?
UPDATE [SOLVED]
Ok, it appears I was being blind and hadn't realised an extra set of double quotes were being generated for class="'wibble'" - thanks to #Dekel for quickly pointing that out, and allowing me to find the cause of the real issue.
To solve the issue of the generation of extra quotes I had to mark the output as html_safe:
<td<%= ((index == #project.active_pattern_index) ? ' class="wibble"' : '').html_safe %>>
<%= pattern.row(count).instruction %>
</td>
The class in the td tag should be wibble (and not 'wibble').
You should not use the single-quotes inside the class attribute classes: ''
<table id="project-table" class="table table-hover">
<thead>
<tr>
<th>Row</th>
<th>Fubar</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row cheese">
<td>Row 1</td>
<td class="wibble">Hello World</td>
</tr>
</tbody>
</table>

css mouseover highlight with table rowspan

I have a simple HTML table generated with PHP from a database where in some cases one cell spans over more than one row. As a simple example:
<table>
<tr class ="highlightRow">
<td>Cell 1</td>
<td rowspan="2">Cell over more rows</td>
</tr>
<tr class ="highlightRow">
<td>Cell 2</td>
</tr>
</table>
I highlight the row the mouse is over with a simple CSS rule:
.highlightRow {
background-color: #FFF;
}
.highlightRow:hover {
background-color: #EEE;
}
I can not find any solution (that is CSS only) to highlight 'Cell over more rows' when the mouse hovers over 'Cell 2'.
I don't know if this will satisfy your need, but have a look at my solution
.highlightRow {
background-color: #FFF;
}
.highlightRow:hover{
background-color: #EEE;
}
table:hover .include{
background-color: #EEE;
}
<table>
<tr class ="highlightRow">
<td>Cell 1</td>
<td rowspan="2" class="include">Cell over more rows</td>
</tr>
<tr class ="highlightRow">
<td>Cell 2</td>
</tr>
</table>
Thr trick is to highlight .include cell every time the table has been hovered and add some rule to highlight tr everytime it's hovered.
I had meet same problems in my projects.We cannot do it.That is why most of all developers perefered jquery DOM traversing methods(parent(),child(),sibling(),next(),prev(),After(),etc..,)
Reference: Is there a CSS parent selector?
Conclusion is :there is no option in CSS for select the parent.we can with javascript help.
**we love coding..*

IE9 table-layout fixed colspan not respected

I found this topic, mine is related but not the same:
Table rendering with cols and colspan on tds in IE9
The problem I am having is that the 2nd colspan=2 in my table is not being read by IE9, funnily enough it works find in IE7 and IE8, but not IE9. Maybe I've done something completely wrong so here it is:
HTML:
<table id="test">
<tbody>
<tr>
<td>COLSPAN = 1</td>
<td colspan="2">COLSPAN = 2</td>
<td>COLSPAN = 1</td>
<td colspan="2">COLSPAN = 2</td>
</tr>
</tbody>
</table>
CSS:
#test {
width: 100%;
border-spacing: 20px;
border-collapse: separate;
table-layout: fixed;
}
#test td {
position: relative;
background-color: #cccccc;
box-shadow: 3px 3px 2px rgba(0,0,0,0.5);
padding: 10px;
}
jsFiddle: http://jsfiddle.net/DUCPp/1/
What is supposed to happen:
What IE9 gives me:
I am convinced this is a IE9 bug, but I haven't been able to find it on google (maybe I'm not searching the right keywords?). Any solutions or links to bug reports will be greatly appreciated!
UPDATE:
I added an extra column after the 2nd colspan=2 column, and it will render correctly. I have deduced that if the last column in a row has colspan > 1, then it will only be rendered as if colspan = 1.
Any ideas on fixing? I'm now almost positive that this is a IE9 bug <_<
Heh... IE9...
Found a "fix"... idea came from: Colspan on cell in one row seems to prevent setting TD width in all the other rows. Why?
Basically I had to add a empty row with the correct # of empty cells in it:
<table id="test">
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>COLSPAN = 1</td>
<td colspan="2">COLSPAN = 2</td>
<td>COLSPAN = 1</td>
<td colspan="2">COLSPAN = 2</td>
</tr>
</tbody>
</table>
Not pretty... and I needed to remove the padding for the cells in order for it not to display. Sigh...
jsFiddle: http://jsfiddle.net/DUCPp/5/
What you want to do is set the width of columns through TH in the header because that's what the browser will use for determining the width of the table and columns in subsequent rows.
Have a look at the following example:
<table>
<thead>
<tr style="height: 0px;">
<th style="width: 110px; height:0px;"></th>
<th style="width: 160px; height: 0px;"></th>
<th style="width: 210px; height: 0px;"></th>
<th style="width: 110px; height: 0px;"></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">Hello</td>
<td>There</td>
</tr>
</tbody>
</table>
You don't appear to have defined any fixed widths for the columns. You should use something like this before the <tbody>:
<col span="6" style="width:16%;" />
I fixed a similar issue by adding the doctype declaration at the start of my HTML code. See http://www.w3.org/QA/2002/04/valid-dtd-list.html
The specific declaration I added was for version 'HTML 4.01 Transitional'.
i.e. placed before the initial tag.
Hope this helps?