1
I have a div
that is 100% and has a background image.
.bannerTotalHome {
background: url("../imagens/bannerTotalHome.jpg") no-repeat center;
width: 100%;
height: 570px;
margin: 0 auto;
}
And inside there will be another div
that will have a background image.
.logoHome {
background: url("../imagens/logoHanka.png") no-repeat center;
width: 285px;
height: 152px;
position: absolute;
left: 50%;
margin-left: -142.5px;
}
What happens is that I centralized the logo using position
, I don’t know if that’s the right way, or if there’s an easier way to do it?
My HTML is like this:
<div class="bannerTotalHome p-relative">
<div class="logoHome margin-top-110"></div>
<div class="margin-top-375 d-block">
<h2>SUA MELHOR ESCOLHA EM</h2>
<h1>COMPONENTES AUTOMOTIVOS</h1>
</div>
</div>
In that case, if I use one margin-top
inside that div bannerTotalHome
He’s going to throw the div right down. So I wonder if the right thing to center that div inside the other is the way I did it.
Already tried with margin: 0 auto; ?
– Rafael Withoeft
You want to center horizontally or vertically?
– André Ribeiro
@Andréribeiro Horizontally
– Felipe Viero Goulart
@Felipestoker So
margin: 0 auto;
is the best alternative.– André Ribeiro
@Rafaelwithoeft I used now
margin: 110px auto 0 auto;
only that he plays the div from top to bottom too, that’s what I didn’t want, right? so I usedposition
– Felipe Viero Goulart
@Rafaelwithoeft Create a Fiddle with your code. I did a test here but without your images I could not visualize the problem.
– André Ribeiro
@Andréribeiro I created an example, using random images of the internet to simulate;
– Rafael Withoeft