IE7 contentEditable word wrapping

2019-04-20 07:39发布

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.

7条回答
在下西门庆
2楼-- · 2019-04-20 08:26

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.

查看更多
别忘想泡老子
3楼-- · 2019-04-20 08:27

Have you tried the overflow property?

查看更多
男人必须洒脱
4楼-- · 2019-04-20 08:31

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

查看更多
一纸荒年 Trace。
5楼-- · 2019-04-20 08:32

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. :(

查看更多
太酷不给撩
6楼-- · 2019-04-20 08:34

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.

查看更多
\"骚年 ilove
7楼-- · 2019-04-20 08:35

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/

查看更多
登录 后发表回答