Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to style a value of an input text?

Tags:

html

css

I'd like to know if is possible to style a value of an input box... such as :

<input class="textBox" type="text" rel="Inserisci il <span style=" value="Inserisci il <span style='color:#c83243;'>titolo</span> per l’URL personalizzato" name="ctl00$InsertDati1$txtTitolo">​​​​​​​​​​​​​​​​​​​​​​​​​​​​

but it doesnt render the span element. Any suggestions?

like image 918
markzzz Avatar asked Feb 17 '12 10:02

markzzz


People also ask

How do you style input value in HTML?

Styling Input Fields If you only want to style a specific input type, you can use attribute selectors: input[type=text] - will only select text fields. input[type=password] - will only select password fields. input[type=number] - will only select number fields.

Can we use style in input tag?

A style attribute on an <input> tag assigns a unique style to the input control. Its value is CSS that defines the appearance of the input element.

What is value in input text HTML?

The value attribute specifies the value of an <input> element. The value attribute is used differently for different input types: For "button", "reset", and "submit" - it defines the text on the button. For "text", "password", and "hidden" - it defines the initial (default) value of the input field.

How do you change the input text color in HTML?

Using HTML tagStep 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the Html tag. Step 2: Now, move the cursor at the starting of that text whose color we want to change. And then, type the empty Html <font> tag at that position.


2 Answers

You can style the content within an input box. For eg:

input{
    color:#ff0000;
    font: 1em/1.25em Arial, Helvetica, sans-serif;
}

If you want to use placeholder content on the other hand, you can add a 'placeholder' attribute on the input tag like so:

<input type="text" class="textbox" placeholder='Title' />

Note that placeholders only work in browsers that support HTML5 and the placeholder attribute. If you want compatibility for older browsers and dont mind using some JQuery, you can use a JQuery plugin like JQuery Watermark.

You can't however, place span elements within the value of an input tag.

like image 186
Sagar Patil Avatar answered Oct 19 '22 10:10

Sagar Patil


Using contentEditable attribute with div is very nice I think. Example: https://jsfiddle.net/scjnwrnf/ <div contenteditable="true">This is a paragraph.<span style = "color:red"> It is editable. </span> Try to change this text.</div> Then you can hide input element and put plain text value from div into input value via JavaScript. Thanks penartur.

like image 31
Petr Hajek Avatar answered Oct 19 '22 12:10

Petr Hajek