我正在开发一个网页,我试图在另一个div上放置一个div精确中心,为此,我使用margin:0 auto;
但它在代码中不起作用。请帮助我如何将LogoDiv完全置于backgroundDiv的中心。
/*css file */
body
{
margin:0;
padding:0;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
position:relative;
overflow-x:hidden;
}
*
{
margin:0;
padding:0;
}
.container
{
max-width:100%;
border:1px solid rgba(6,0,0,1.00);
margin:auto;
}
.backgrounddiv
{
background:url('../images/bg_page_01.png');
background-size:100%;
background-repeat:no-repeat;
height:800px;
}
.LogoDiv
{
clear:both;
position:absolute;
background:url('../images/logo_fianl.png');
background-size:100%;
background-repeat:no-repeat;
height:250px;
}

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/>
<head>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="CSS/bootstrap.min.css">
<!-- style CSS-->
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 .col-sm-12 .col-md-12 .col-lg-12 backgrounddiv">
<div class="col-xs-5 .col-sm-5 .col-md-5 .col-lg-5 LogoDiv">
</div>
</div>
</div> <!-- End of row -->
</div> <!-- End of Container -->
</body>
</html>
&#13;
答案 0 :(得分:1)
您可以尝试以下代码:
.LogoDiv
{
clear:both;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
background:#fff;
width:500px;
height:250px;
}
答案 1 :(得分:0)