Answers for "center of the div"

CSS
89

center a div in css

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
Posted by: Guest on September-09-2020
1

css center div

.my-div{
  width: 80%;
  margin: 10px auto;
  /*
    margin-left and right right has 'auto' value
    meaning that the browser will automatically calculate the remaining space
    and give it to the margin.
    From the example. 20% remained from 80%
    so that our div will have 
    margin-right: 10%
    margin-left: 10%
    and it will be centered.
  */
}
Posted by: Guest on June-12-2021
0

how to center div

<!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>
Posted by: Guest on June-21-2020

Code answers related to "center of the div"

Browse Popular Code Answers by Language