Solved

Is it possible to define custom colors in html and use them in a css

Posted on 2011-03-03
5
154 Views
Last Modified: 2012-05-11
I want to define a custom color and use it in my css
such as

.highlightedtext{
backgroundcolor:myhighlightcolor;
}

where myhighlightcolor can be a color which I choose.Is it possible to do this in html or css ?If yes, then where do i define the color?

0
Comment
Question by:res_this
5 Comments
 
LVL 4

Expert Comment

by:mars-vie
ID: 35029039
You should do this with Javascript or PHP.
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 35029141
I would use javascript for changing the class
more on this
http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript

if you spend sometimes with jQuery framework - it will be a lot easier in the future
http://docs.jquery.com/Tutorials
0
 
LVL 2

Expert Comment

by:nedlogan
ID: 35029554
Hi,
You've pretty much answered your own question, in your stylesheet define:
.highlightedtext{
    background:#ffcc00;/*or your own color*/
    }

Then set the class of the tag that surrounds the text to be highlighted for example:
<span class="highlightedtext">blah blah</span>

No need to resort to PHP or JavaScript

Regards.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 35029903
If you are wanting 'myhighlightcolor' to be a variable that you can change in one place and use in many, then you will need to use a programming language like Javascript, ASP, or PHP.  HTML and CSS are 'description' languages but not programming languages but you can use programming languages to alter the HTML and CSS that is generated.
0
 

Author Closing Comment

by:res_this
ID: 37503775
not clear
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

821 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