当附加<详细信息>时元素到带有innerHTML的div,div会“向下”移动也详细信息>
通过此处的示例可以轻松描述该问题。
代码如下:
HTML:
<div id="example">Hello </div>
JS:
document.getElementById('example').innerHTML += '<details style="display: inline"><summary>World</summary>Something</details>';
问题是,当我单击“World”时,会出现“Something”,但“Hello”也会下降,如下所示:
我希望当您单击“World”时,“Hello”保持在原位。
有什么建议吗?提前致谢!
The problem is easily pictured with an example here.
The code goes like this:
HTML:
<div id="example">Hello </div>
JS:
document.getElementById('example').innerHTML += '<details style="display: inline"><summary>World</summary>Something</details>';
The problem is that when I click on "World", "Something" appears but "Hello" also goes down, like this:
I would like that when you click on "World", "Hello" stays in position.
Any suggestions? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为
#example
设置vertical-align: top
似乎得到了我认为你想要的布局。 HTML:和 CSS:
最后,必要的小提琴: http://jsfiddle.net/ambigously/cJPRz /
Setting
vertical-align: top
for#example
seems to get the layout that I think you want. The HTML:And the CSS:
And, finally, the obligatory fiddle: http://jsfiddle.net/ambiguous/cJPRz/