Answers for "how to centre a div"

CSS
1

how to centre a div

.class-name {
	display:flex;
    justify-content:centre;
    align-items:centre;
}
Posted by: Guest on October-12-2021
1

align a div in center of another div

#container {
    width: 640px; /*can be in percentage also.*/
    height: auto;
    margin: 0 auto;
    padding: 10px;
    position: relative;
}
Posted by: Guest on April-30-2020
8

css center div

<!-- 
	 Simple CSS CENTER DIV Example
 	 
	 * See Fiddle in link for PoC *
-->

<div class="parent">
  <div class="child">
    <p>
      Eh Up Me Duck!
    </p>
  </div>
</div>

<style>
.parent {
  /* Just for aesthetics: see fiddle */
  border: 1px solid black;
  padding: 2px;
}

.child {
  border: 1px solid red;
  width: 50%;
  
  /* This is where the magic happens */
  margin-left: auto;
  margin-right: auto;
  /**********************************/
}

p {
  /* As you do */
  text-align: center;
}
</style>
Posted by: Guest on February-23-2020

Browse Popular Code Answers by Language