开发者

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

开发者 https://www.devze.com 2023-03-20 13:42 出处:网络
The problem is easily pictured with an example here. The code goes like this: HTML: <div id=\"example\">Hello </div>

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>开发者_Python百科;';

The problem is that when I click on "World", "Something" appears but "Hello" also goes down, like this:

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

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号