Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you create tags like stackoverflow with text styling

Tags:

css

input

styles

I was wondering how you can create css styling inside an input field such as stackoverflow's tagging system?

When you click on a tag, the text will be styled. And also, when you click on the styled tag, it will be normal again. I guess my main concern is how to style text inside an input field?

Thanks!

like image 355
hellomello Avatar asked Oct 31 '11 22:10

hellomello


People also ask

How do I create a tag on stackoverflow?

When asking a question, any user can enter a tag into the tags box the same as any other tag. Make sure to hit space to ensure it gets formatted correctly as a tag on the edit screen. Once the question is submitted, the tag will automatically be created.

Where can I add style tag?

The <style> element must be included inside the <head> of the document. In general, it is better to put your styles in external stylesheets and apply them using <link> elements.


2 Answers

The tags are not input fields, they are links! On SO, the tags use the following styles:

.post-tag {
    color: #3E6D8E;
    background-color: #E0EAF1;
    border-bottom: 1px solid #3E6D8E;
    border-right: 1px solid #7F9FB6;
    padding: 3px 4px 3px 4px;
    margin: 2px 2px 2px 0;
    text-decoration: none;
    font-size: 90%;
    line-height: 2.4;
    white-space: nowrap;
}

a.post-tag:hover {
    background-color: #3E6D8E;
    color: #E0EAF1;
    border-bottom: 1px solid #37607D;
    border-right: 1px solid #37607D;
    text-decoration: none;
}
like image 168
Chris Shouts Avatar answered Oct 14 '22 20:10

Chris Shouts


Only the bit you type in is an input, the other tags are just styled a elements. When you hit return, the input moves right and gets shorter, and the value is copied and a new a element is created.

The text in the input isn't styled.

like image 35
Rich Bradshaw Avatar answered Oct 14 '22 19:10

Rich Bradshaw