Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a degree symbol after content with CSS

Tags:

css

I know that I can add a degree symbol in HTML with "°", and I am looking at examples of CSS using :after selector and the content property, but I'm having trouble putting it all together.

I want a degree symbol to show up after the text that appears in an input box.

<div class="threshold">
    <input type="text" value="12" name="thresholdSelect" disabled="disabled">
</div>

And the CSS:

.threshold input:after {
    content: "&deg;"
}

But that doesn't seem to work. Any ideas on how to fix it. I could store the degree symbol in the value, but that would require a lot of extra javascript for things like validation and whatnot. Any way to do it with CSS?

like image 871
BishopZ Avatar asked Jan 11 '13 16:01

BishopZ


People also ask

How do you add symbols in CSS?

The simplest way to add an icon to your HTML page, is with an icon library, such as Font Awesome. Add the name of the specified icon class to any inline HTML element (like <i> or <span> ). All the icons in the icon libraries below, are scalable vectors that can be customized with CSS (size, color, shadow, etc.)

How do you put the degree symbol in the input field?

Following are the steps for inserting a degree symbol using Microsoft Excel's built-in features: Open Microsoft Excel and click on the cell where you want to insert the degree symbol. Type "=CHAR(176)" and then press the "Enter" button on your keyboard.

How do I add text after CSS content?

CSS can insert text content before or after an element. To specify this, make a rule and add ::before or ::after to the selector. In the declaration, specify the content property with the text content as its value.


2 Answers

Try something like this

HTML

<div class="threshold">
    <input type="text" value="12" name="thresholdSelect" disabled="disabled">
</div>

CSS

.threshold:before {
    content: "\00b0"
}

DEMO: http://jsfiddle.net/Tt2hU/ OR http://jsfiddle.net/Tt2hU/1/

like image 164
Enve Avatar answered Oct 18 '22 23:10

Enve


This might help: Can I use the :after pseudo-element on an input field?

It seems it may not be possible in CSS with an input tag.

like image 25
97ldave Avatar answered Oct 18 '22 22:10

97ldave