简体   繁体   中英

When appending a <details> element to a div with innerHTML the div goes “down” too

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!

Setting vertical-align: top for #example seems to get the layout that I think you want. The HTML:

<div id="example">Hello <details><summary>World</summary>Something</details></div>

And the CSS:

#example {
    vertical-align: top;
}
details {
    display: inline;
}

And, finally, the obligatory fiddle: http://jsfiddle.net/ambiguous/cJPRz/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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