HTML: Changing colors of specific words in a string of text

后端 未结 8 1707
轻奢々
轻奢々 2020-12-02 18:17

I have the below message (slightly changed):

\"Enter the competition by January 30, 2011 and you could win up to $$$$ — including amazing summer tri

相关标签:
8条回答
  • 2020-12-02 18:47

    You could use the HTML5 Tag <mark>:

    <p>Enter the competition by 
    <mark class="red">January 30, 2011</mark> and you could win up to $$$$ — including amazing 
    <mark class="blue">summer</mark> trips!</p>
    

    And use this in the CSS:

    p {
        font-size:14px;
        color:#538b01;
        font-weight:bold;
        font-style:italic;
    }
    
    mark.red {
        color:#ff0000;
        background: none;
    }
    
    mark.blue {
        color:#0000A0;
        background: none;
    }
    

    The tag <mark> has a default background color...at least in Chrome.

    0 讨论(0)
  • 2020-12-02 18:48
    <font color="red">This is some text!</font> 
    

    This worked the best for me when I only wanted to change one word into the color red in a sentence.

    0 讨论(0)
提交回复
热议问题