473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use one CSS style for both border and background color?

Hi all,

I have a table whose style is:

..main_table
{
border: thin solid #000000;
width: 666px;
border-collapse: collapse;
}

This table contains a cell whose style looks like this:

..copyright
{
height: 22px;
font-size: small;
text-align: right;
color: #FFFFFF;
background-color: #000000;
}

Is there any way to have a single CSS style that I can attach to both the
table and the cell to specify the table's border color as well as the cell's
background color? The tricky part (for me) is that I don't know how to
separate the table border color from the other border attributes ("thin" and
"solid").

TIA - Bob

Aug 28 '08 #1
6 1289
"Bob Altman" <rd*@nospam.nospamwrote in message
news:eD**************@TK2MSFTNGP04.phx.gbl...
Hi all,

I have a table whose style is:

.main_table
{
border: thin solid #000000;
width: 666px;
border-collapse: collapse;
}

This table contains a cell whose style looks like this:

.copyright
{
height: 22px;
font-size: small;
text-align: right;
color: #FFFFFF;
background-color: #000000;
}

Is there any way to have a single CSS style that I can attach to both the
table and the cell to specify the table's border color as well as the
cell's
background color? The tricky part (for me) is that I don't know how to
separate the table border color from the other border attributes ("thin"
and
"solid").
You can separate out border attributes as:-

{border-width: thin; border-style: solid; border-color:black}

However since border-color and background-color are different attributes you
can't create style that will let you include the color value once.
--
Anthony Jones - MVP ASP/ASP.NET
Aug 28 '08 #2
You can't do that because you want one rule that affects different
properties of different elements. The fact that these two things happen to
use the same color isn't enough to be able to make one rule out of them.

-Scott

"Bob Altman" <rd*@nospam.nospamwrote in message
news:eD**************@TK2MSFTNGP04.phx.gbl...
Hi all,

I have a table whose style is:

.main_table
{
border: thin solid #000000;
width: 666px;
border-collapse: collapse;
}

This table contains a cell whose style looks like this:

.copyright
{
height: 22px;
font-size: small;
text-align: right;
color: #FFFFFF;
background-color: #000000;
}

Is there any way to have a single CSS style that I can attach to both the
table and the cell to specify the table's border color as well as the
cell's background color? The tricky part (for me) is that I don't know
how to separate the table border color from the other border attributes
("thin" and "solid").

TIA - Bob

Aug 29 '08 #3
>Is there any way to have a single CSS style that I can attach to both the
>table and the cell to specify the table's border color as well as the
cell's background color?
"Scott M." <s-***@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP06.phx.gbl...
You can't do that because you want one rule that affects different
properties of different elements. The fact that these two things happen
to use the same color isn't enough to be able to make one rule out of
them.

Thanks Anthony and Scott. Now that I've learned a bit more about how to
slice and dice CSS styles, let me ask a slightly different question on the
same theme.

Suppose my web page is laid out inside of a top-level table, and one or more
of the table cells always wants to be the same color as the table border. I
can create a CSS rule that I attach to the table that includes "border: thin
solid #aabbcc". I can create another rule that I attach to the specific
table cells that want to match the border color, with "background-color:
#aabbcc".

Obviously, what I'd like is some way to define the color ("aabbcc") once and
plug it in to both rules automagically. How is this sort of thing done?

Bob

Aug 30 '08 #4
Bob, that would be done using JavaScript because it requires the
functionality of a data variable that can hold a value that can be accessed
from other spots. CSS is not a programming language, it is more declarative
(you declare what you want and that happens).

In short, for your scenario, you're just going to have to specify the same
color value in the two spots if you plan to do the work solely in CSS.

-Scott

"Bob Altman" <rd*@nospam.nospamwrote in message
news:O8**************@TK2MSFTNGP06.phx.gbl...
>>Is there any way to have a single CSS style that I can attach to both
the table and the cell to specify the table's border color as well as
the cell's background color?

"Scott M." <s-***@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP06.phx.gbl...
>You can't do that because you want one rule that affects different
properties of different elements. The fact that these two things happen
to use the same color isn't enough to be able to make one rule out of
them.


Thanks Anthony and Scott. Now that I've learned a bit more about how to
slice and dice CSS styles, let me ask a slightly different question on the
same theme.

Suppose my web page is laid out inside of a top-level table, and one or
more of the table cells always wants to be the same color as the table
border. I can create a CSS rule that I attach to the table that includes
"border: thin solid #aabbcc". I can create another rule that I attach to
the specific table cells that want to match the border color, with
"background-color: #aabbcc".

Obviously, what I'd like is some way to define the color ("aabbcc") once
and plug it in to both rules automagically. How is this sort of thing
done?

Bob

Aug 30 '08 #5
That's what I figured, but I was hopeful that this was a common enough
scenario that there would be an elegant approach baked into something that
"every experienced web developer" knew about. Oh well... maybe in the next
version of CSS ;-)

"Scott M." <s-***@nospam.nospamwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
Bob, that would be done using JavaScript because it requires the
functionality of a data variable that can hold a value that can be
accessed from other spots. CSS is not a programming language, it is more
declarative (you declare what you want and that happens).

In short, for your scenario, you're just going to have to specify the same
color value in the two spots if you plan to do the work solely in CSS.

-Scott

"Bob Altman" <rd*@nospam.nospamwrote in message
news:O8**************@TK2MSFTNGP06.phx.gbl...
>>>Is there any way to have a single CSS style that I can attach to both
the table and the cell to specify the table's border color as well as
the cell's background color?

"Scott M." <s-***@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP06.phx.gbl...
>>You can't do that because you want one rule that affects different
properties of different elements. The fact that these two things happen
to use the same color isn't enough to be able to make one rule out of
them.


Thanks Anthony and Scott. Now that I've learned a bit more about how to
slice and dice CSS styles, let me ask a slightly different question on
the same theme.

Suppose my web page is laid out inside of a top-level table, and one or
more of the table cells always wants to be the same color as the table
border. I can create a CSS rule that I attach to the table that includes
"border: thin solid #aabbcc". I can create another rule that I attach to
the specific table cells that want to match the border color, with
"background-color: #aabbcc".

Obviously, what I'd like is some way to define the color ("aabbcc") once
and plug it in to both rules automagically. How is this sort of thing
done?

Bob


Aug 31 '08 #6
Again, CSS isn't a programming language, so you aren't going to find any
kind of built in behaviors like this. That is what JavaScript and DHTML are
for. I wouldn't hold my breath for any new versions of CSS that
fundamentally change the fact that you can't program with it alone.

-Scott
"Bob Altman" <rd*@nospam.nospamwrote in message
news:ee**************@TK2MSFTNGP05.phx.gbl...
That's what I figured, but I was hopeful that this was a common enough
scenario that there would be an elegant approach baked into something that
"every experienced web developer" knew about. Oh well... maybe in the
next version of CSS ;-)

"Scott M." <s-***@nospam.nospamwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
>Bob, that would be done using JavaScript because it requires the
functionality of a data variable that can hold a value that can be
accessed from other spots. CSS is not a programming language, it is more
declarative (you declare what you want and that happens).

In short, for your scenario, you're just going to have to specify the
same color value in the two spots if you plan to do the work solely in
CSS.

-Scott

"Bob Altman" <rd*@nospam.nospamwrote in message
news:O8**************@TK2MSFTNGP06.phx.gbl...
>>>>Is there any way to have a single CSS style that I can attach to both
the table and the cell to specify the table's border color as well as
the cell's background color?

"Scott M." <s-***@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP06.phx.gbl...
You can't do that because you want one rule that affects different
properties of different elements. The fact that these two things
happen to use the same color isn't enough to be able to make one rule
out of them.
Thanks Anthony and Scott. Now that I've learned a bit more about how to
slice and dice CSS styles, let me ask a slightly different question on
the same theme.

Suppose my web page is laid out inside of a top-level table, and one or
more of the table cells always wants to be the same color as the table
border. I can create a CSS rule that I attach to the table that
includes "border: thin solid #aabbcc". I can create another rule that I
attach to the specific table cells that want to match the border color,
with "background-color: #aabbcc".

Obviously, what I'd like is some way to define the color ("aabbcc") once
and plug it in to both rules automagically. How is this sort of thing
done?

Bob



Aug 31 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: T | last post by:
I am attempting to create a menu using <div> and <span> tags within a table cell. When the page loads, some of the classes don't seem to be applied. If I hover over the menu everything is fine...
2
by: Florian Brucker | last post by:
Yeah, that's right, this question is not about styling HTML with CSS, but instead about how one should arrange his CSS code so that it is easy to understand and modify. The thing that I've got...
17
by: ryan.fairchild | last post by:
Ok, I have a problem with my boxes. I am making a blog currently but I don't think I am implementing my boes correctly. My website is www.ryanfairchild.com. Currently it looks fine as the...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
1
by: Roy | last post by:
Hey all. All I'm trying to do is get a darn double solid bar in my datagrid footer. Doesn't seem to work. Any tips? The weird thing is all the other stylesheet attributes work. If I increase the...
15
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px;...
7
by: ~john | last post by:
I'm trying to move myself off of using tables for page layout so I'm giving DIV tags a shot, mostly for the header, right and left columns... with left being the traditional navigational side and...
8
by: Amit | last post by:
I have a master page and a content page but the stylesheet isnt getting applied like how it looks in visual studio design view. The master page is defined like this: <%@ Master Language="VB"...
3
Claus Mygind
by: Claus Mygind | last post by:
I want to move some style setting into a javaScript function so I can make them variable but I get "invalid assignment left-hand side" error? see my question at the bottom of this message. It...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.