Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 嵌套Divs退格问题_Html_Css - Fatal编程技术网

Html 嵌套Divs退格问题

Html 嵌套Divs退格问题,html,css,Html,Css,我有一个关于嵌套div的问题。两个div都是可编辑的。 问题是,如果我在div中写入内容,即简单文本,然后将光标放在innerchild div的开头,然后按backspace键,则会移动父div中的文本。 为什么会这样?我知道这是默认行为。 这个问题的解决方案是什么 <head> <title>----</title> </head> <body style="100%"> <br /> <

我有一个关于嵌套div的问题。两个div都是可编辑的。 问题是,如果我在div中写入内容,即简单文本,然后将光标放在innerchild div的开头,然后按backspace键,则会移动父div中的文本。 为什么会这样?我知道这是默认行为。 这个问题的解决方案是什么

<head>
    <title>----</title>
</head>

<body style="100%">
    <br />
    <br />
    <br />

<div contenteditable="true" style="min-height:80%; min-width:100%; background-color:#00ffff">
    <div id="test" style="margin:auto; width:100%; background-color:#e3e3e3; 
border-width:5px; border-color:e9e9e9; word-wrap: break-word; overflow:hidden;  
min-height:25px;" contenteditable="true">

        Child Div Text here!!!

    </div>
                    Parent Div Text Here
</div>

</body>
问候,,
Ahmed

这可能不完全正确,但我认为您的div正在移动的原因是您设置子div宽度的方式。如果您在子div上设置宽度:100%,则该div的大小将拉伸以包括所有间距。您还没有指定任何位置属性,因此父div将自己放在子div的旁边。这意味着对子div位置和宽度的任何更改(将随您拥有的“”的数量而更改)也将更改父div的位置。如果不希望父div移动,则需要A为子div指定一个设置的宽度,或B为每个div设置一个位置。如果有css文件,它将如下所示:

A

B


你的意思是如果删除子div中的空格数,那么父div将正确移动?我做了一个JSFIDLE:当你在子div的左边缘并点击backspace时,子div将被删除。我看到你是dilema。我尝试了各种方法来阻止父div文本合并到子div文本中,但没有成功。虽然我已经看过了。不知道这些对你是否有用。。。和
/* You would need to add IDs to each div so I am just going to do child */
#child
{
   width: 200px; /* Set number */
}
#child
{
    position: absolute /* Or however you wish to do this */
    top: 10px; /* Some number */
    left: 10px; /* Again whatever number */
}