Как сосредоточиться
.center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Puzzled Penguin
.center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container{
margin: 0 auto;
display: flex;
align-items: center;
}
/*ADD MARGIN auto to left and right*/
.box1{
width:80%;
margin:0 auto;
}
.center {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
.div {
width: 80%;
margin: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
.center {
margin: auto;
width: 80%;
border: 3px solid #73AD21;
padding: 10px; # deals with margins within the element itself
margin: 20px; # deals with area around outside of element
}
</style>
</head>
<body>
<h2>Center Align Elements</h2>
<p>To horizontally center a block element (like div), use margin: auto;</p>
<div class="center">
<p><b>Note: </b>Using margin:auto will not work in IE8, unless a !DOCTYPE is declared.</p>
</div>
</body>
</html>