Center element on a page

1

I have a page and login to develop and there is a logo right in the center of the page. Ok, I centralized it as follows:

bg{
    background-image: url("../imagens/bg.jpg");
    background-repeat: no-repeat;
    background-position: center;
    width: 100%;
    height: 1138px;
}
   .logo {
    background-image: url("../imagens/logo.png");
    width: 140px;
    height: 101px;
    margin-left: -70px;
    left: 50%;
    position: absolute;
}

I put a position:absolute and I would like to know if there is another way, otherwise, everything that comes below that% div will have to put position and I do not want it.

HTML:

<div class="bg">        
<div class="logo"></div>
</div>

Demo Image:

    
asked by anonymous 04.11.2014 / 00:40

1 answer

3

Without touching markup and without touching CSS, you only need to change position:absolute; to position:relative; in the element with class .logo .

Absolutely positioned: JSFiddle

04.11.2014 / 01:44