Can I use DOM in CSS?

Posted on 2006-07-04
Last Modified: 2013-11-19
Can I use DOM in CSS? I want the set the bgColor of an element to the bgColor of the parent by using CSS – How can I?
Question by:madchat1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 49

Expert Comment

ID: 17040304
You can set the element to be transparent:
#parentDivId element {background:transparent;}


Author Comment

ID: 17040325

I tried transparent by it's no good coz in FireFox it doesn't work so well.
(And what does #parentDivId mean? Why do need the parent if it is transparent)

LVL 49

Accepted Solution

Roonaan earned 125 total points
ID: 17040348
The official answer to your question would be: No you cannot use DOM in crossbrowser CSS.

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

LVL 15

Expert Comment

ID: 17041558
Actually, you can use JavaScript in your CSS files. However, it's only executed once, so it may not be just what you want (see An alternative is to manipulate the CSS in onPageLoad, where you can set the colors as you wish.
LVL 49

Expert Comment

ID: 17041634

That is why I wrote it in this way: "No you cannot use DOM in --> crossbrowser CSS <--."

LVL 15

Expert Comment

ID: 17041785
Yes, Roonan, the embedded JS in CSS only works in IE and Opera (and is regarded as a naughty thing to do). However, the idea of manipulating styles in an onload function is perfectly valid and works across browsers.

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question