Solved

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

Posted on 2011-03-03
5
151 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
Comment Utility
You should do this with Javascript or PHP.
0
 
LVL 7

Expert Comment

by:dxdinh
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
not clear
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now