Search code examples
csshtmlcentercss-position

Centering a fixed div,div same size as image


So i want to position a fixed div in a center of a screen. This div should also be a container for child divs. Also i want it to display an image (as background). This is the code for image:

.centerdiv > img{
height: 100%;
width: auto;
}

I would like to keep it that way, so that browser would always display a full image. Currently Im trying to with this html code:

<div class="centerdiv "><img src="bgstatic.png">
        </div>

I did tried to do it with css (adding image in css code). I don't mind about this part really much. The basic idea is to have a centered image and menus with fixed position (so they don't scroll) and the rest of page should be on top of it and should be able to scroll.

I have tried with margins:auto, left/right 0/50%,etc... I did get a result i almost want. But the problem was that my container div was bigger then fixed background div, thus I had much trouble to position rest of the page with it...


Solution

  • <div style="text-align:center;">
       <div class="centerdiv "><img src="bgstatic.png"></div>
    </div>
    

    Css

     .centerdiv{
                   height: 100%;
                   width: auto;
                   display:inline-block;
                   position:fixed;}