gpt4 book ai didi

html - 嵌套的 Divs 退格问题

转载 作者:行者123 更新时间:2023-11-28 14:41:44 25 4
gpt4 key购买 nike

我有一个关于嵌套 div 的问题。两个 div 都是可编辑的。问题是,如果我在 div 中写入内容(即简单文本),然后将光标放在内部(子)div 的开头,然后按退格键,它会移动父 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>

问候,艾哈迈德

最佳答案

这可能不完全正确,但我认为您的 div 移动的原因是您设置子 div 宽度的方式。如果您对子 div 执行 width:100%,则该 div 的大小将拉伸(stretch)以包括所有间距。您也没有指定任何位置属性,因此父级 div 会将自己放在子级 div 的旁边。这意味着对子 div 的位置和宽度的任何更改(将随着您拥有的 ' ' 的数量而改变)也会更改父 div 的位置。如果您不希望父 div 移动,那么您需要 A) 为子 div 指定一组 width 或者,B ) 为每个 div 设置一个位置。如果你有一个 css 文件,它看起来应该是这样的:

一个)

/* You would need to add IDs to each div so I am just going to do child */
#child
{
width: 200px; /* Set number */
}

B)

#child
{
position: absolute /* Or however you wish to do this */
top: 10px; /* Some number */
left: 10px; /* Again whatever number */
}

关于html - 嵌套的 Divs 退格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5805075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com