views:

458

answers:

9

I have the following code:

<html>

<style type="text/css">

DIV { display:inline; border: solid red 1px; }

.editable { background:yellow; }

</style>

<div class="editable" contentEditable="true"> This is test text. This is test text.This is test text.This is test text.This is test text.Thihis is test text.This is test text.</div>

<div class="editable" contentEditable="true"> short </div>

<div class="editable" contentEditable="true"> This is test text.This is test text.This is test text.his is test text.Thihis is test text.Thihis is test text.Thihis is test text.Thi </div>

And I need IE7 (IE6 not needed and FF3.x works fine) to wrap the text correctly, which it does if I remove the contentEditable="true" from the divs. Just try this code with and without contentEditable and you'll see what I mean. Make the browser window small enough so you see how the text wraps.

Thanks.

A: 

Have you tried the overflow property?

Cesar Lopez
A: 

i found exactly the same issue in ie8. i tried to work around using -ms-word-break : break-all, to make it clear to ie that i want default line breaking, but no chance. all other browsers do it correctly.

A: 

O my! IE Developer Toolbar reveals that contentEditable triggers the infamous layout property

Having layout basically means an element is rectangular.

While there are several hacks out there forcing a layout, I think there's no way to actually remove it. :(

Pumbaa80
A: 

Why don't you use display: block for the divs?

You could even use inline-block if they really need to be inline:

http://www.brunildo.org/test/InlineBlockLayout.html Do note that according to quirksmode the support in IE 6 and 7 is incomplete for this

Exapmles: http://jsfiddle.net/SNzBn/

Litso
A: 

Have you tried white-space: normal?

Chris Cox
A: 

Have you tried to use a SPAN instead of an DIV?

SPAN-tags are inline, without the need of display:inline.

Sorry, that I didn't tried, but I don't have any IE7, at this moment.

ckuetbach
A: 

dear friend, all versions of IE have some disadvantages. specially in parsing style sheets. for each version sytle rule have to modified. i suggest , you must use style rule for each version. ie. IE style hacks. from my knowledge , IE 6 version is best in all version of IE. it displays correctly what you write in style sheets.

paraguma
+1  A: 

DEMO: http://jsbin.com/icavu4

try this can help solve a little the problem!

<!--[if gte IE 7]>
<style type="text/css">
.editable {
    overflow:hidden;
    float:left;
    height:20px;
    border: solid red 1px;
    background: yellow;
}
</style>
<![endif]-->

UPDATED:

Since this can be considered a workaround in part, it allow you to display it like FF but it cut of last part of the text, you may want provide the full text to edit on hover by using a little bit of javascript!

aSeptik
A: 

Short Answer: If you use display:inline-block instead of display:inline, then all the other browsers will behave like IE!

Detail: IE9 behaves the same way. SPAN behaves the same as DIV {display: inline}, which it should. Pumbaa80's Sep 1 response is the best one. Basically, ContentEditable must be rectangular in IE. So both SPAN and your DIV render as display:inline-block in IE. I use ContentEditable all the time in a content management system. I take advantage of the "feature" so that the user has some space to work with when the editable DIV is initially empty. In your example, if you delete all the text in "short", then good luck getting the cursor back into the element to put text back in. It just collapses down to nothing. In the CMS I toggle ContentEditable off and on, depending on if the user has selected Edit or Preview mode. At the same time, I toggle display between inline and block/inline-block, and I toggle the edit guides (your red border) off and on. ...Tom

Tom Robinson