Answers for "center a div css horizontally"

CSS
9

center div horizontally and vertically

.parent {
  position: relative;
}
.child {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
Posted by: Guest on June-22-2020
0

center div horizontally

/* margin auto does the magic, make sure to provide width less than 100% */
.center {
	margin: auto;
    width: 400px;
}

.center {
	margin: auto;
    width: 50%;
}
Posted by: Guest on May-27-2021
4

how to center a div element

/*ADD MARGIN auto to left and right*/
.box1{
    width:80%;
    margin:0 auto;
}
Posted by: Guest on August-27-2020
1

css center horizontally

text-align: center; /*also works for images or anything inside the object (I think)*/
Posted by: Guest on July-12-2021
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

Code answers related to "center a div css horizontally"

Browse Popular Code Answers by Language