473,662 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1298
"Bob Altman" <rd*@nospam.nos pamwrote in message
news:eD******** ******@TK2MSFTN GP04.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.nos pamwrote in message
news:eD******** ******@TK2MSFTN GP04.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.nosp amwrote in message
news:eO******** ******@TK2MSFTN GP06.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.nos pamwrote in message
news:O8******** ******@TK2MSFTN GP06.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.nosp amwrote in message
news:eO******** ******@TK2MSFTN GP06.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.nosp amwrote in message
news:ec******** ******@TK2MSFTN GP02.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.nos pamwrote in message
news:O8******** ******@TK2MSFTN GP06.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.nosp amwrote in message
news:eO******* *******@TK2MSFT NGP06.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.nos pamwrote in message
news:ee******** ******@TK2MSFTN GP05.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.nosp amwrote in message
news:ec******** ******@TK2MSFTN GP02.phx.gbl...
>Bob, that would be done using JavaScript because it requires the
functionalit y 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.nos pamwrote in message
news:O8******* *******@TK2MSFT NGP06.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.nosp amwrote in message
news:eO****** ********@TK2MSF TNGP06.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
5281
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 from that point on. If I remove the table everything renders correctly, and I have no problems. Unfortunately, I need to nest this menu within a table. I am currently having this problem in IE 6. Thanks in advance for the help! <html>...
2
1685
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 problems is that CSS does not seem to support variables or conditionals (if/else). This makes it IMO difficult to arrange the code, especially if several tags share one attribute (same background for example). How do you organise your files? 1....
17
2382
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 sider bar is to the right and in place however if I post a topic with a long name then the box where the sidebar is displays recent topics, but if the topic is too long then it wraps underneath the main content box and throws off the whole scheme. I...
21
3963
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 nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
1
2029
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 font size it's reflected, etc... Here's my style sheet code: ..Footer { border-top-style:double; border-top-color:Black;
15
3850
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; margin-left: -400px; width: 800px; height: 26px"> <!-- CODE GOES HERE --> </div>
7
1352
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 the right being the main page body. A problem I'm running into that I didn't have using tables is when content is too big in a div, it throws the layout of the page off. For example... here's a link to my page ...
8
13515
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" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
1951
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 works fine when I stream it out in my html page like this: <DIV ID="popSearch" STYLE=" position:absolute; visibility:hidden;
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.