Solved

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

Posted on 2011-03-03
5
155 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
[X]
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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
migrating to phpbb forum from vBulletin 4.2 3 97
How do I Enable submit button only if listbox has items 4 65
title attribute 5 33
Scroll 5 news at a time using vticker 2 41
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

710 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