简体   繁体   English

围绕浮动图像包装 contenteditable div 的 CSS 问题

[英]CSS Issue in wrapping contenteditable div around Floating image

I have a problem in floating a contenteditable div around a image.我在图像周围浮动 contenteditable div 时遇到问题。 Here's my code:这是我的代码:

HTML: Section title HTML:部分标题

CSS: CSS:

.fl {
    float: left;
}

.rgtDiv {
    min-height: 300px;
    border: solid 1px #ccc;
}
    

I want the rgtDiv to have left border at the right end of the image but right now it appears at the left end of the image.我希望rgtDiv在图像的右端有左边框,但现在它出现在图像的左端。

When I click on the rgtDiv the cursor goes to the image and not inside the rgtDiv .当我单击rgtDiv ,光标会转到图像而不是rgtDiv内部。 How to make the cursor come inside the rgtDiv ?如何使光标进入rgtDiv

Also the border of the rgtDiv applies to the entire parent Div. rgtDiv的边框也适用于整个父 Div。 How to make it to apply only for the rgtDiv .如何使其仅适用于rgtDiv

Can anyone help resolving my problem?任何人都可以帮助解决我的问题吗?

Here's my jsfiddle link: http://jsfiddle.net/n8WJ2/这是我的 jsfiddle 链接: http : //jsfiddle.net/n8WJ2/

Thanks in advance!提前致谢!

yadav亚达夫

try giving the rgtDiv a float: left;尝试给 rgtDiv 一个 float: left; and a width ... should work and don´t forget to clear your floats和一个宽度......应该可以工作,不要忘记清除你的浮点数

You can add this:你可以添加这个:

.rgtDiv {
    position: relative;
    overflow:hidden;
    min-height: 300px;
    border: solid 1px #ccc;
}

Demo演示

It will resize depending of the width of the image.它将根据图像的宽度调整大小。

Try this尝试这个

HTML HTML

<div>
 <div class="section-title">Section title</div>
 <div class="rgtDiv">
  <img src="http://www.destination360.com/north-america/us/montana/images/s/great-falls.jpg" height="300" width="300"/>
 <div contenteditable="true" class="editableblock"></div>
</div>

CSS CSS

.fl, .rgtDiv img  {
 float: left;
}

.rgtDiv {
 border: solid 1px #ccc;
 display:block;
}

.editableblock {
 min-height: 300px;
}

If anyone still cares.如果还有人关心的话。 To workaround the issue with caret position, you can add zero-width space to the div in HTML:要解决插入符号位置的问题,您可以在 HTML 中向 div 添加零宽度空间:

<div contenteditable="true" class="rgtDiv">&#8203;</div>

and restore it every time user clears it:并在每次用户清除它时恢复它:

$('.rgtDiv').keyup(function(){
    if($(this).text().length == 0){
        $(this).text('\u200B');
    }
});

Demo演示

overflow: hidden can be used for the contenteditable block :empty pseudo-class. overflow: hidden可用于 contenteditable 块 :empty 伪类。 Please note that it has to be really empty: no spaces or tabs inside, just <div contenteditable="true"></div>请注意,它必须是空的:里面没有空格或制表符,只有<div contenteditable="true"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM