Float a div in top right corner without overlapping sibling header

Posted by Maxime R. on Stack Overflow See other posts from Stack Overflow or by Maxime R.
Published on 2012-11-12T16:29:52Z Indexed on 2012/11/12 17:00 UTC
Read the original article Hit count: 298

Filed under:
|

Having a div and a h1 inside a section, how do i float the div in the top right corner without overlapping the text of the header ?

The HTML code is the following:

<section>
  <h1>some long long long long header, a whole line, 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6</h1>
  <div><button>button</button></div>
</section>

Using this CSS code:

section { position: relative; }
h1  { display: inline; }
div {
    position: absolute;
    top: 0;
    right: 0;
}

Using this CSS code:

h1  { display: inline; }
div { float: right;    }

?

I know there is a lot of similar questions but I couldn't find one solving this case.

© Stack Overflow or respective owner

Related posts about css

Related posts about html5