0

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:

enter image description here

I would like that when you click on "World", "Hello" stays in position.

Any suggestions? Thanks in advance!

Toto
  • 89,455
  • 62
  • 89
  • 125
Trufa
  • 39,971
  • 43
  • 126
  • 190
  • I have tagged this question html5 because of the details element but I'm not 100% certain the tag is appropriate. Feel free to suggest/edit and remove. Thanks! – Trufa Jul 16 '11 at 06:31
  • Which browser are you using? I get it all on one line in both Safari and Firefox. – mu is too short Jul 16 '11 at 06:41
  • @muistooshort: google-chrome I don't think it works in many other browser. Haven't tried out though! – Trufa Jul 16 '11 at 06:48
  • @muistooshort: Do you see something like this? http://i.imgur.com/9bkC7.png – Trufa Jul 16 '11 at 06:51
  • Yes, that image matches what I got in Firefox and Safari. However, I got the "proper" behavior in Chrome. – mu is too short Jul 16 '11 at 06:57

1 Answers1

2

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/

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • That seem to work great! thank you! I'm just trying to figure out how to take it to my actual example a userscript... – Trufa Jul 16 '11 at 07:12
  • sorry for the delay. Thank for the answer! – Trufa Jul 20 '11 at 16:27
  • @Trufa: Sorry I don't have a decent explanation for why it works. The "fiddle with it until it works" technique leaves me feeling a bit uneasy. – mu is too short Jul 20 '11 at 17:20
  • It is very strange indeed!! I had to play with it quite more to fit my implementation but I wouldn't have got it without you leading me in the right direction. Unless I'm mistaken this is a pretty new feature HTML5 blah blah blah so there isn't overabundant reliable information about it and it's implementation. Anyway thanks again! – Trufa Jul 20 '11 at 17:45
  • @Trufa: Whatever works. There might be a pseudo class for `
    ` or ``, or perhaps a `:blah-blah-blah` pseudo class for everything.
    – mu is too short Jul 20 '11 at 18:02