prevent div's from taking 100% width

HtmlCss

Html Problem Overview


<div style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;">

  <div style="
         border: 2px solid black;
         margin: 0 auto;
         text-align: center;
         padding: 3px;">

    Hello<br />Hola

  </div>

  <div style="
         border: 2px solid black;
         margin: 0 auto;
         text-align: center;
         padding: 3px;">

    Another Sentence

  </div>

</div>

I have a problem: the borders of the inner div's reach over the whole width of the page, but i want them to only frame the content inside them. If i use: display: inline the borders frame each line separately and overlap, so that doesn't work - can somebody help?

P.S the style's aren't declared like this in the original document but in a stylesheet

Html Solutions


Solution 1 - Html

Assign a width to the absolutely positioned element? If you're looking for shrink-wrapping, float:left or display:inline-block are perfect for that.

Solution 2 - Html

Try display:inline-block, it always helps me in situations like this.

http://jsfiddle.net/FaYLk/

Solution 3 - Html

Its not as simple to just do:

display: inline-block;

You must do more than that to cross browser this.

display: inline-block;
display: -moz-inline-stack; /* for firefox 2 */
*display: inline; /* for ie 6 and 7 */

Solution 4 - Html

Put a container around all the content. E.g

<div class='container'> <div>I wont be 100%</div> <div>Nor will I :)</div> </div>
.container{ display: inline-block; } 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamuelView Question on Stackoverflow
Solution 1 - Htmlmeder omuralievView Answer on Stackoverflow
Solution 2 - HtmlNikita RybakView Answer on Stackoverflow
Solution 3 - HtmlDavid LawrenceView Answer on Stackoverflow
Solution 4 - HtmlJames111View Answer on Stackoverflow