Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Responsive Center Div

I would like to center some div which has background image. There is problem with response of this div, because if I set width on 80% and height on 80% the bg-image is not on center. I tried everything, but the picture can't just stand on center and if the browser is smaller or bigger this is very big problem.

So if you look at the picture

block on center

I want to make this white block responsive.

There is a little of css which I've already written, but for now is non-responsive:

top: 20%;
left: 30%;
display: block;
position: absolute;
background: url(images/background.png) no-repeat;
background-size: 750px 417px;
width: 750px;
height: 417px;
like image 676
user1257255 Avatar asked Sep 28 '12 18:09

user1257255


1 Answers

You could use CSS transform:

position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
like image 57
Steve Glick Avatar answered Nov 27 '22 13:11

Steve Glick