HTML Table Border: User Agent style sheet overrides CSS? - html

I have an HTML table that needs its border color changed. I can't figure it out.
HTML
<table>
<thead>
<tr>
<th>Name</th>
<th>Conditions</th>
<th>Characteristics</th>
</tr>
</thead>
<tbody>
<tr class="zebra-stripe">
<td class="first-field">Element</td>
<td>version}</td>
<td></td>
</tr>
<tr>
<td class="first-field">ApplicationTransactionID</td>
<td>string, up to 64 chars, Optional</td>
<td>A number assigned by the calling application to uniquely identify this request.</td>
</tr>
</tbody>
</table>
CSS
/* Global CSS */
table {
border-color: red;
}
tr {
border-color: red;
}
td {
border-color: red;
/* Table CSS */
.zebra-stripe {
border-color: red;
background: #002D38;
border: solid;
border-width: 1px;
}
.zebra-stripe table {
border-color: red;
}
.zebra-stripe tr {
border-color: red;
}
.zebra-stripe td {
border-color: red;
}
I have even tried to change the border color with an inline style. Still no luck! It doesn't work in Chrome or Safari. The border is simply just gray and its from the user agent style sheet. Am I wrongly targeting it? I targeted it like 10 different ways. The class CSS should be enough. I can change the border style or the border width just fine, but I can't change the color. But at the most, targeting the table row should be enough as well.
Cannot fathom what is going wrong.

you haven't defined the rest of the border attributes. You can use:
table {
border: 1px solid red;
}
(which is border-width, border-style and border-color)
instead of
table {
border-color: red;
}
FIDDLE
Also a note about your current CSS, you have .zebra-stripe added as a class to a tr but the CSS states .zebra-stripe table and .zebra-stripe tr which means it's targeting a table or tr inside of a parent with a class of .zebra-stripe
UPDATE
To explain, there were 2 issues, 1 being you forgot to close this
tr {
border-color: red;
}
td {
border-color: red;
<------ //no '}' tag
this prevented .zebra-stripe from working at all. Secondly, .zebra-stripe had the following issue:
.zebra-stripe
border-color: red;
background: #002D38;
border: solid; <------ this should be 'border-style', 'border' is overwriting the others
border-width: 1px;

Wow many careless mistakes on my part. Was pretty flustered, doing a lot of poking around in the dark to see if something would work.
HTML
<table>
<thead>
<tr>
<th>Name</th>
<th>Conditions</th>
<th>Characteristics</th>
</tr>
</thead>
<tbody>
<tr class="row-edge">
<td class="first-field">Element</td>
<td>version}</td>
<td></td>
</tr>
<tr>
<td class="first-field">ApplicationTransactionID</td>
<td>string, up to 64 chars, Optional</td>
<td>A number assigned by the calling application to uniquely identify this request.</td>
</tr>
</tbody>
</table>
CSS
.row-edge {
border-top: 1px solid #0A454F;
border-bottom: 1px solid #0A454F;
}
Changed a few colors and labels. But this is just what I needed.
Thanks again!

Related

What is the value in CSS for border when using tables?

What is the value in CSS for border when using tables? For example:
This is my desired look.
<table border=4px >
<tr>
<th>1</th>
<th>1</th>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</table>
but I want to do it with CSS only. So I tried inline like so
<table style="
border-width: 4px;
border-spacing: 3px;
border-style: outset;
border-color: gray;
border-collapse: separate;
background-color: white;
border-width: 2px;
padding: 1px;
border-style: inset;
border-color: gray;
background-color: white;
border-width: 2px;
" >
<tr>
<th>1</th>
<th>1</th>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</table>
When I do this the cell borders are gone (at least in Firefox). I tried using the wizard from here http://www.somacon.com/p141.php but it does not help. No matter what I do I can not get these "inner walls" to appear without using "table border=1px"?
first thing i would suggest, is have a look Here
now after you learnt basic css and how to use styles, to apply "inner" borders to a table, you basically apply the borders to the cells themselves:
table tr th,
table tr td{
border:1px solid black;
}
or separately:
table tr th,
table tr td{
border-style: solid;
border-width: 1px;
border-color: black;
}
and then, to get rid of the cell spacing you apply this to the table itself:
table{
border-collapse: collapse;
}
EXAMPLE
You can add a separate style tag elsewhere:
<style type="text/css">
table tr td {
border: 4px gray solid;
}
table tr th {
border: 4px gray solid;
}
</style>

CSS for specific table rows

I have a simple table with several rows. The top rows contains headings, while the rows under it have the id attribute of data. I have been trying to set CSS for the table rows that only have the id attribute data, but have so far only been able to set it for the entire table.
<table width = "80%" align="center" id="example">
<tr>
<td><h3>ID</h3></td>
<td><h3>First Name</h3></td>
<td><h3>Last Name</h3></td>
</tr>
<tr id="data">
<td>1</td>
<td>Joe</td>
<td>Schmoe## Heading ##</h3><td>
</tr>
</table>
and the CSS. I tried changing #example tr to tr #data with no luck. I know that I am overlooking something simple, but I am unsure what.
table#example {
border-collapse: collapse;
}
tr #data{
background-color: #eee;
border-top: 1px solid #fff;
}
tr #data:hover {
background-color: #ccc;
}
tr #data {
background-color: #fff;
}
tr #data th, tr #data td {
padding: 3px 5px;
}
tr #data td:hover {
cursor: pointer;
}
I'm not using classes because I'm not familiar enough with CSS and being able to use id only once is not a limitation for what I need.
You could use a class, but better yet, don't use classes at all (HTML markup is your friend)! Here's a clean solution to your problem:
HTML
<table>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>1</td>
<td>Joe</td>
<td>Schmoe</td>
</tr>
</table>
CSS
th {
font-weight: bold;
/* More styles here */
}
td {
background: #EEE;
border-top: 1px solid #FFF;
}
tr:hover td {
cursor: pointer;
background: #CCC;
}
/* Styles upon styles */
Simply use the th element to specify the table header. To get each table data row to highlight as you mouse over it, simply use the tr:hover td rule to catch that case. See this fiddle for a working example.

Table Border Overlap

please see this example:
http://jsfiddle.net/qTjdX/
I want the red border-bottom to show as 1 solid line, but right now the yellow border is splitting it up in 3. Is there any way to have the border-bottom take precedence? Like a z-index of sorts?
I have tried both border-collapse:collapse and border-collapse:separate.
The only thing that is working is if I make the red line thicker, but I want it to have the same width.
table {
width:100%;
border:1px solid blue;
border-collapse:separate;
}
th, td {
border:1px solid yellow;
padding:5px;
}
th {
background:black;
color:white;
}
th {
border-bottom:1px solid red !important;
}
td {
background:#efefef;
}
​
The problem you're having is because the border is composed of four separate sides, which meet at 45 degree angles at the corners, which is rounded in various ways. So having a bottom-border a different color to that of the sides will always cause the borders to break.
If you look at this demo:
div {
float: left;
border-width: 25px;
border-style: solid;
border-top-color: red;
border-right-color: green;
border-bottom-color: blue;
border-left-color: yellow;
}
JS Fiddle demo.
You can see how the various borders meet, because a pixel can't be subdivided this leads to the corner-pixels being the same solid colour as one of the sides and therefore a different colour, if the colours are different, to the other side with which it connects.
To compensate the only option you really have is to use a nested element within the th:
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><div>col 1</div></th>
<th><div>col 2</div></th>
<th><div>col 3</div></th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
With the following CSS:
table {
width:100%;
border:1px solid blue;
border-collapse:collapse;
}
th {
border-bottom: 2px solid yellow;
}
th div, td {
border: 1px solid red;
}
th div {
border-bottom-width: 0;
}
JS Fiddle demo.

How can I make my border-bottom not overwrite my border for my table?

How can I make my border-bottom not overwrite my border for my table? I what the sides to be complete black and not with a little bit of gray -- or "grey" for you all in England. ;)
UPDATE: Not concerned with the bottom border of the table getting overwritten -- I'm hoping to eliminate on the sides where the border is gray.
Here is my code I'm working with and a jsfiddle.net page for your convience ;)
<table>
<tr>
<td>row1</td>
</tr>
<tr>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
</tr>
<tr>
<td>row4</td>
</tr>
</table>
table {
border: 4px solid #000;
width: 400px;
}
table tr {
border-bottom: 4px solid #CCC;
}
Set border-collapse:separate to your table, and add the border to the td's instead of the tr's:
http://jsfiddle.net/ptriek/uJ5zN/2/
At this point, #ptriek's solution seems to be the one that better addresses your question but, just for reference, here's a workaround using a <div> to wrap things up. This solution also keeps the last <tr>'s boarder intact and might come in handy in other situations.
Fiddle: http://jsfiddle.net/uJ5zN/4/
HTML
<div class="wrapper">
<table>
<tr>
<td>row1</td>
</tr>
<tr>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
</tr>
<tr>
<td>row4</td>
</tr>
</table>
</div>
CSS
.wrapper
{
border: 4px solid #000;
width: 400px;
}
table {
width: 400px;
}
table tr{
border-bottom: 4px solid #CCC;
}
One way would be to use the CSS last-child selector as follows:
table {
border: 4px solid #000;
width: 400px;
}
table tr {
border-bottom: 4px solid #CCC;
}
table tr:last-child {
border-bottom: 4px solid #000;
}

Set border to table tr, works in everything except IE 6 & 7

I set the border for the table event_calendar tr to be red, it works in everything except IE 6 & 7. What is wrong with my CSS?
table#event_calendar tr {
border:1px solid red;
}
<div class="content-body">
<table id="event_calendar">
<tr class="calendarHeader">
<th><div class="calendarMonthLinks"><<</div></th>
<th colspan="5"><h1>April 2009</h1></th>
<th><div class="calendarMonthLinks"><a class="calendarMonthLinks" href="http://webdev.herkimer.edu/calendar/2009/05/">>></a></div></th>
</tr>
<tr>
<td class="calendarDayHeading">Sunday</td>
<td class="calendarDayHeading">Monday</td>
<td class="calendarDayHeading">Tuesday</td>
<td class="calendarDayHeading">Wednesday</td>
<td class="calendarDayHeading">Thursday</td>
<td class="calendarDayHeading">Friday</td>
<td class="calendarDayHeading">Saturday</td>
</tr>
</table>
</div>
IE does not honor the border property for <tr> tags. However, there are workarounds by putting a top and bottom border around each cell, and using "border-collapse: collapse;" so there's no space between cells. I will refer to this resource here on the exact method, but it will essentially look like this for you (I haven't tested it myself, so I'm not sure if this is exactly right, but I think you can riff on it.)
table#event_calendar {
border-collapse: collapse;
border-right: 1px solid red;
border-left: 1px solid red;
}
table#event_calendar td, table#event_calendar th {
border-top: 1px solid red;
border-bottom: 1px solid red;
}
Your CSS is sensible enough, but IE just doesn't do borders on tr elements. If you use this style you should get the intended result though:
table#event_calendar {
border-top:1px solid red;
border-right:1px solid red;
border-left:1px solid red;
border-collapse:collapse;
}
table#event_calendar td, table#event_calendar th {
border-bottom:1px solid red;
}
Setting the border on the td is the easiest solution. But if you really really want to make the borders on <tr>, you can always set:
tr { display:block; border-bottom:1px dotted #F00; }
By doing this, you loose the common width between the <td>. If you want to make all of them equal on width, set the display for <td> to inline-block and set some width:
td { display:inline-block; width:20%; }
It helps when you want to draw some border on the <td> and on <tr>.
CSS generated content like tr:before{} or tr:after{} can always help as well.
Change your CSS selector to "table#event_calendar tr td" and it should work.