HTML + CSS: add class / id to plain text

I'm currently stuck with a possibly very trivial problem:

I have a simple HTML / CSS page with text:

<head></head>
<body>
    This is a Text about Foobar.
</body>

How can I assign a CSS class / id to a word Textwithout breaking the format? Let's say I want to add a class to it .yellowthat displays text with a yellow background.

I think something is blocking my mind because it cannot be so difficult ... But all I can do with Google (mostly trivial tutorials) uses CSS only on regular HTML elements like <p>or <b>that break my format.

+5
source share
4 answers

I think you are missing the tag <span>. Try it:

<head></head>
<body>
    This is a <span class="yellow">Text</span> about Foobar.
</body>

And in CSS:

.yellow{
color:yellow;
}
+13

. . , , <em> <strong> - :

strong.highlight{
    font-weight:normal;
    font-style:normal;
    background:yellow;
}
+2

You just need to wrap the section in between, for example:

<span>This is a <span class='yellow'>Text</span> about Foobar.</span>

See a working example here http://jsfiddle.net/dZZfB/

Hope that helps

+2
source

HTML for example:

<center><span class="t1">Test1</span></center>

CSS:

<style type="text/css">
    .t1 {
        color: white; 
        text-shadow: black 0.1em 0.1em 0.2em;
    }
</style>
+1
source

All Articles