CSS combine table styles - css

I've found similar tops for combining classes using the comma to separate them; however when I try it with the table class only the last table is receiving the style. Here is a small sample of what I'm trying to clean up:
table.tslist {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
cellspacing: 0;
border-collapse: collapse;
width: 225;
}
table.djrlist {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
cellspacing: 0;
border-collapse: collapse;
width: 225;
}
table.vacation {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
cellspacing: 0;
border-collapse: collapse;
width: 225;
}
table.tslist td {
border-left: 1px solid #999;
border-top: 1px solid #999;
padding: 2px 4px;
}
table.djrlist td {
border-left: 1px solid #999;
border-top: 1px solid #999;
padding: 2px 4px;
}
table.vacation td {
border-left: 1px solid #999;
border-top: 1px solid #999;
padding: 2px 4px;
}
As I mentioned I tried table.tslist, table.djrlist, table.vacation {....} but no luck.

I'm guessing that you are doing something like this:
table.x, table.y td { }
and assuming that it'll expand out and apply to all the TD elements. It won't. You need something like this instead:
table.x td, table.y td { }

Be sure to include the element type in your seperators:
table.tslist,
table.djrlist,
table.vacation
{
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
cellspacing: 0;
border-collapse: collapse;
width: 225;
}
table.tslist td, <-----
table.djrlist td, <-----
table.vacation td <----- {
border-left: 1px solid #999;
border-top: 1px solid #999;
padding: 2px 4px;
}

I'm guessing you don't even need to do multiple styles like that. Classes are not like IDs, you can use them more than once.
If all of your tables are styled the same, just replace all of this:
<table class="tslist">...</table>
<table class="vacation">...</table>
<table class="djrlist">...</table>
with
<table class="tslist">...</table>
<table class="tslist">...</table>
<table class="tslist">...</table>
You can then remove the unused style entries from the css file.

Related

Adding some space between tables with css

I have generated a HTML page with several tables.
Right now they show one after another without any space between them
my current css file is very simple
table {
font-family: arial, sans-serif;
border-collapse: collapse;
/*width: 100%;*/
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
How can I add some spacing between the tables using only css?
I tried
table{
margin-right: 10px;
float: left;
}
but it did not work out
I modified it to
margin-bottom:10px;
float:bottom;
and it seems to work.
Your code should work. Check this snippet:
table {
font-family: arial, sans-serif;
border-collapse: collapse;
margin-right:10px;
float:left;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
<table>
<tr><td>aaaaa</td></tr>
</table>
<table>
<tr><td>bbbb</td></tr>
</table>
<table>
<tr><td>aabbbbaaa</td></tr>
</table>
If you have width: 100%; you need to add margin-top:10px for example.

CSS multiple tables in same page with different IDs [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
We have two different tables in the same page. different IDs required for another purpose. So we created multiple CSS table elements in the Style . But only the first one is working. If i keep the customers design on top it will be applied , but only one at a time.
#salescss {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#salescss td, #salescss th {
border: 1px solid #ddd;
padding: 8px;
}
#salescss tr:nth-child(even){background-color: #f2f2f2;}
#salescss tr:hover {background-color: #ddd;}
#salescss th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #357EC7;
color: white;
body {font-family: Arial;}
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}
#customers tr:nth-child(even){background-color: #f2f2f2;}
#customers tr:hover {background-color: #ddd;}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #357EC7;
color: white;
body {font-family: Arial;}
You had a missing } after #salescss th { and #customers th {
#salescss {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#salescss td, #salescss th {
border: 1px solid #ddd;
padding: 8px;
}
#salescss tr:nth-child(even){background-color: #f2f2f2;}
#salescss tr:hover {background-color: #ddd;}
#salescss th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #357EC7;
color: white;
}
body {font-family: Arial;}
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}
#customers tr:nth-child(even){background-color: #f2f2f2;}
#customers tr:hover {background-color: #ddd;}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #357EC7;
color: white;
}
body {font-family: Arial;}

Table CSS left border Issue with CSS Code

Far Left borders shows nothing in entire table. how do I fix it in below CSS code ? Border is now showing any of the color all other cells are good.
Below is my existing CSS Code. Thanks in Advance.
#mytable {
padding: 0;
margin: 0;
border-spacing: 0px;
border-collapse: separate;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(/images/bg_header.jpg) no-repeat;
}
th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(/images/bullet1.gif) no-repeat;
font: bold 10px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}
th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(/images/bullet2.gif) no-repeat;
font: bold 10px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
/* Below CSS is used for jQuery Popup window used for File Upload*/
#fade {
/*--Transparent background layer--*/
display: none;
/*--hidden by default--*/
background: #000;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: .80;
z-index: 9999;
}
.popup_block {
display: none;
/*--hidden by default--*/
background: #fff;
padding: 20px;
border: 20px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%;
left: 50%;
z-index: 99999;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
img.btn_close {
float: right;
margin: -55px -55px 0 0;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
position: absolute;
}
*html .popup_block {
position: absolute;
}
<table id="mytable">
<tr>TEST</tr>
<tr>
<td>TEST</td>
<td>TEST</td>
<td>TEST
<td>TEST</td>
</tr>
</table>
If I understand right you want the same border in left td. You can use this:
td:first-child {
border-left: 1px solid #C1DAD7;
}
#mytable {
padding: 0;
margin: 0;
border-spacing: 0px;
border-collapse: separate;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(/images/bg_header.jpg) no-repeat;
}
th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(/images/bullet1.gif) no-repeat;
font: bold 10px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}
th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(/images/bullet2.gif) no-repeat;
font: bold 10px"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
/* Below CSS is used for jQuery Popup window used for File Upload*/
#fade {
/*--Transparent background layer--*/
display: none;
/*--hidden by default--*/
background: #000;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: .80;
z-index: 9999;
}
.popup_block {
display: none;
/*--hidden by default--*/
background: #fff;
padding: 20px;
border: 20px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%;
left: 50%;
z-index: 99999;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
img.btn_close {
float: right;
margin: -55px -55px 0 0;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
position: absolute;
}
*html .popup_block {
position: absolute;
}
td:first-child {
border-left: 1px solid #C1DAD7;
}
<table id="mytable">
<tr>TEST</tr>
<tr>
<td>TEST</td>
<td>TEST</td>
<td>TEST
<td>TEST</td>
</tr>
</table>
Well, you could just add border-left: 1px solid #C1DAD7; to your td definition and maybe change border-collapse: separate; to border-collapse: collapse; in #mytable.
It's also possible to add left border-left: 1px solid #C1DAD7; on entire table in #mytable.
The common solution is to either use :first-child or the adjacent operator: + but these are not supported in IE6. You may need to handle that browser separately for these styles if this is a requirement. (Use conditional comments, maybe?)
Anyway, I've tried to pull out the relevant CSS and assumed some things about the markup to come up with this:
#mytable {
padding: 0;
margin: 0;
border-spacing: 0px;
border-collapse: separate;
border: 1px solid #C1DAD7;
}
td + td, th + th {
border-left: 1px solid #C1DAD7;
}
tr + tr {
border-top: 1px solid #C1DAD7;
}
td {
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(/images/bg_header.jpg) no-repeat;
}
<table id="mytable">
<tr>
<th>TEST1</th>
<th>TEST2</th>
<th>TEST3</th>
<th>TEST4</th>
</tr>
<tr>
<td>TEST1</td>
<td>TEST2</td>
<td>TEST3</td>
<td>TEST4</td>
</tr>
</table>

CSS Table width not being able to be set

2 Columns, a few rows.
The width of the entire table seems to be set for good. No chance of changing it. All I can do is move the row separator so one columns gets stretched while the other expands.
This is the CSS file.
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
}
a {
color: #c75f3e;
}
#mytable {
width: 450px;
padding: 0;
margin: 0;
height: 39px;
}
caption {
padding: 0 0 5px 0;
width: 489px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}
th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(images/bullet1.gif) no-repeat;;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}
th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(images/bullet2.gif) no-repeat;;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
And this the table.
<table id="mytable" cellspacing ="0">
<caption>Table 1: Descriptions </caption>
<tr>
<th scope="col" abbr="Configurations" class="nobg" style="width: 47px">Configurations</th>
<th scope="col" abbr="Dual 1.8GHz">Original Stack</th>
</tr>
<tr>
<th scope="row" class="spec" style="width: 47px">Model</th>
<td class="style1">3xPa</td>
</tr>
<tr>
<th scope="row" class="specalt" style="width: 47px">Year</th>
<td class="alt" style="width: 181px">1998/A</td>
</tr>
</table>
I'm not sure what's preventing me from changing the width of the entire table. I've tried changing the width property in #mytable but it's doing absolutely nothing. I'm using VS 2010, aspx webform.
Any idea?
Changing the table width in the css works fine for me on chrome.
Try removing the width for your caption, the absolute width on the caption might be tricking you into thinking the table size is not changing...
caption {
padding: 0 0 5px 0;
/*width: 489px; Commented Out */
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}

Is it possible to have the menu link color change on the table hover for an asp.net menu control?

I'm using an ASP.net menu and when i hover inside my menu item's table, i change the background color on the table column, but unless i hover over the link text itself, the link text color will not change.
Is it possible to have the link text color changed on the table hover?
Example below shows what happens.
Excuse the ugly CSS:
.TopStaticSelectedStyle
{
cursor: pointer;
font-size: 11px;
font-family: Verdana;
}
.TopStaticMenuStyle a,
.TopStaticMenuStyle a:visited,
.TopStaticMenuStyle a:active
{
color: #ffffff;
text-decoration: none;
font-weight: bold;
font-family: Verdana;
}
.TopStaticMenuStyle a:hover
{
color: #000000;
text-decoration: none;
font-size: 11px;
font-weight: bold;
font-family: Verdana;
}
.TopStaticMenuItemStyle td
{
padding: 0px 12px 0px 12px;
text-align: center;
background-color: #6c85b0;
height: 18px;
border-top: solid 1px #012754;
border-bottom: solid 1px #012754;
border-left: solid 1px #012754;
border-collapse:collapse;
}
.TopStaticHoverStyle
{
font-weight: normal;
font-family: Verdana;
}
.TopStaticHoverStyle td
{
padding: 0px 12px 0px 12px;
text-align: center;
background-color: #ffffff;
height: 18px;
border-top: solid 1px #012754;
border-bottom: solid 1px #012754;
border-left: solid 1px #012754;
border-collapse:collapse;
color: #000000;
}
I scrapped your css and just started from scratch but you should be able to get the idea from this.
So some basic table html:
<table>
<tr>
<td>
Test
</td>
<td>
Test 2
</td>
</tr>
</table>​
And then the css:
a {
color:#000;
}
td {
border:solid 1px black;
background:#234567;
padding:5px 10px;
}
td:hover {
background:#eee;
}
td:hover a {
color:#ccc;
}
td a:hover {
color:#777;
}
​
The key here is the td:hover a selector which is what you need to change the color on hover of the td.

Resources