1

What I am after is to colour in just one character of my code throughout the page.

The lines between each of the words are what I would like to be a different colour from the rest of the text but I would like to do this in CSS rather than horribly adding to each one just to change its colour.

Anti-virus End Point | Disk Encryption | UTM | Email and Web Security

Is it possible through CSS?

here is what I have attempted but I don't think I'm coming close.

  | {
     color:#00FF00;
     }
4
  • I think you need to use javascript for this Commented Jul 30, 2013 at 8:18
  • 1
    The character would have to be enclosed in a <span> or other tag for this to be possible with pure CSS. Is it? Can you show the HTML source code? Commented Jul 30, 2013 at 8:19
  • @Pekka Yeah that does the job. A little more fiddly than I wanted because I have to add "<span>" to everything but it nicer than adding "<font color=...>" Commented Jul 30, 2013 at 8:22
  • possible duplicate of Style certain characters with CSS Commented Jul 30, 2013 at 10:13

5 Answers 5

3

If you wrap each of the | character in a span with a class you can use that:

<span class="separator">|</span>

.separator {
    color: #0F0;
}
Sign up to request clarification or add additional context in comments.

Comments

3

Another solution would be encapsulating the text (not the separators) inside <span/>s, and use :after pseudo-element to create the separator.

Then, specify that, for the last element, the separator is not required:

HTML

<div class="separator">
    <span>Anti-virus End Point</span>
    <span>Disk Encryption</span>
    <span>UTM</span>
    <span>Email and Web Security</span>
</div>

CSS

.separator > span:not(:nth-last-child(1)):after {
    content: ' | ';
    color:#00FF00;
}

Demo: http://jsfiddle.net/j9kZS/1/

Comments

0

AFAIK there is no pure CSS solution for this. If you are using jQuery it would probably be easiest to make use of the highlight plugin for this: http://bartaz.github.io/sandbox.js/jquery.highlight.html

Comments

0

try this

http://jsfiddle.net/v9Vbc/2/

css

 .divider {
     color:#00FF00;
     }

html

try <span class="divider">|</span> try

Comments

0

Another solution with pure js:

<style>
    .paint{
        color: #00FF00;
    }
</style>
<div id="result"></div>
<script>
        var str = "Anti-virus End Point | Disk Encryption | UTM | Email and Web Security";
        str = str.split('|').join('<span class="paint">|</span>');
        document.getElementById("result").innerHTML = str;
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.