0

I have a div center-aligned that way:

<div id="container" style="position:absolute; top:0px; left:50%; margin-left:-500px; width:1000px;"></div>

As this solution Trying to center div horizontally and vertically in screen suggest.

The problem is that if the client's window's width (tried in FF 15.0.1) is smaller than 1000px the horizontal scrollbar won't allow to show the left side of the div.

Is there a pure html/css way to solve it?

Community
  • 1
  • 1
Sami
  • 648
  • 8
  • 25

1 Answers1

2

Hmm. You can not resize client window.
1 thing that you can do is avoid the left scroll setting the width of parent div to 1000px

  <div id="parent" style="min-width:1000px;"> 
      <div id="container" style="position:absolute; top:0px; left:50%;
        margin-left:-500px; width:1000px;"></div>
  </div>   

Note:
You might have to set the width of html and body tag to min-width=100%

Updated:

 <html style="min-width: 100%; background-color:Gray;">
 <body style="min-width: 100%; background-color:White;">
 <div id="parent" style="min-width: 1000px; position:relative;">
    <div id="container" style="position: absolute; top: 0px; left: 50%; margin-left: -500px;
        width: 1000px; border: 1px solid red; height: 10px;">
        1 2 3 4 5
    </div>
  </div>
 </body>
 </html>

I missed position:relative to describe. This code is working.

syed mohsin
  • 2,948
  • 2
  • 23
  • 47