views:

4947

answers:

3

I just noticed that if you give a html button a fixed width, the text inside the button is never wrapped. I've tried it with word-wrap, but that cuts of the word even though there are spaces available to wrap on.

How can I make the text of an html button with a fixed width wrap like any tablecell would?

<td class="category_column">
    <input type="submit" name="ctl00$ContentPlaceHolder1$DataList1$ctl12$ProCat_NameButton" 
           value="Roos Sturingen / Sensors" 
           id="ctl00_ContentPlaceHolder1_DataList1_ctl12_ProCat_NameButton" 
           class="outset" 
           style="height:118px;width:200px;font-size:18px;color:#7F7F7F;width:200px;white-space:pre;" />
</td>

the css classes do nothing but adding borders and modify the padding. If I add word-wrap:break-word to this button, it will wrap it like this:

Roos Sturingen / Sen
sors

And I dont want it to cut of in the middle of a word if it is possible to cut it off between words.

Thanks

A: 

Multi-line buttons like that are not really trivial to implement. This page has an interesting (though somewhat dated) discussion on the subject. Your best bet would probably be to either drop the multi-line requirement or to create a custom button using e.g. divs and CSS, and adding some JavaScript to make it work as a button.

Daan
The problem is that I am using ASP.Net, using the asp:button control with CommandName and CommandArgument attributes. I can't just use an other control.
Peter
+8  A: 

I found that you can make use of the white-space css property:

white-space: normal;

And it will break the words as normal text.

Hope it helps.

Siu
Genius. Worked for me.
MGOwen
...except it doesn't work on IE6. Please die already, IE6.
MGOwen
+1  A: 

You can force it (browser permitting, I imagine) by inserting line breaks in the HTML source, like this:

<INPUT value="Line 1
Line 2">

Of course working out where to place the line breaks is not necessarily trivial...

If you can use an HTML <BUTTON> instead of an <INPUT>, such that the button label is the element's content rather than its value attribute, placing that content inside a <SPAN> with a width attribute that is a few pixels narrower than that of the button seems to do the trick (even in IE6 :-).

Brian Nixon
For something very simple you can also use <button> with a <br> at the desired break point.
KevinH