views:

207

answers:

5

I'm currently in a horrible situation that requires me to style an input of type "button" over two lines. Having a fixed width on the button causes the text within the button to wrap onto two lines in all other browsers except IE.

My question is therefore, how do I specify that an input with value="Button to Wrap" wraps onto two lines in IE?

I'm willing to accept any hacks or workarounds to make this happen.

Much appreciated!

A: 

Have you tried using br tags?

bic72
<br> tags wouldn't work as the break occurs within the value=" " attribute.
Stuart Memo
+2  A: 

Have you tried hard returns in your source code? Works for me...

<p>
<input type='button' value='3
Line
Button'
/>
</p>
Fortega
Yes, sorry should've said. The value is being passed as a string from a Java variable, so can't do hard returns. Thanks though!
Stuart Memo
[I'm willing to accept any hacks or workarounds to make this happen.] -> measure the size of the string, compare to the fixed width you are setting the button to and add \n on the right place
Fortega
Unfortunately, \n doesn't seem to work within value=" ".
Stuart Memo
hm, maybe you could try System.getProperty("line.separator");in stead of \n?
Fortega
Interesting, not doing the Java dev myself, so will pass it on. Thanks a lot for your help!
Stuart Memo
A: 

The word-wrap CSS attribute seems to be the word on this one. If that doesn't work, you'll have to try using a div tag style to look like a button and an onClick handler...

<input type=button value="test" style="word-wrap: break-word"></input>

This might need position, height and width attributes as well to work.

Gyuri
Hmm, doesn't seem to be working either. Didn't really know about break-word though, thanks for letting me know about it!
Stuart Memo
OK, take 2: I put in a windows line break into the text, and it worked. (used the html test on w3schools).
Gyuri
A: 

Why not to use image button? Make image for button, and pressed button... Or make button in flash (:

pytho
+5  A: 

Use the button element instead - it can contain other markup:

<button type="button">
First Line<br />
Second Line<br />
Third Line<br />
</button>
NickFitz
But read the important note here: http://www.w3schools.com/tags/tag_button.asp
AakashM
That's only relevant if the `type` attribute is `submit`, but the question refers to an input of type `button`. IE is completely broken even with the `input` element of type `submit` anyway, so as usual, w3schools' information is just wrong enough to be dangerous under certain circumstances.
NickFitz