Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML + CSS: Add a class/id to simple text

Tags:

html

css

I'm currently stuck at a probably very trivial problem:

I have a simple HTML/CSS page with a text:

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

How is it possible to assign a CSS-class/id to the word Text without breaking the format? Let's say I want to add the class .yellow to it, which displays the text with a yellow background.

I think I got something blocking my mind cause it can't be that difficult... But all I can google (mostly trivial tutorials) uses CSS just on usual HTML-elements like <p> or <b> which would break my format.

like image 833
MOnsDaR Avatar asked Feb 06 '13 17:02

MOnsDaR


People also ask

How do I add a class to a paragraph in CSS?

"Add a class attribute with the value intro to the <p> element." To add a class, you go to your element, <p>, and just like IDs, you add class= (Instead of id=) and insert your class name. "Select the class intro and set its font weight to bold." To select the class via CSS, you add a period before it.

Can you add a class and ID in HTML?

Yes, any HTML element (like div, input, nav, body, etc) can have both “id” and “class” together and at the same time. The only difference here is that “id” can have only one unique value and “class” can have more than one.

Can you add an ID in CSS?

A CSS ID selector uses the ID attribute of an HTML element to select one unique element on a page. To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element.


1 Answers

I think you are missing out on <span> tag. Try this out:

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

And in CSS:

.yellow{
color:yellow;
}
like image 148
Abubakkar Avatar answered Oct 10 '22 11:10

Abubakkar