Answers for "box to center css"

CSS
89

center a div in css

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

center div css

.container {
  display: grid;
  place-items: center;
}
Posted by: Guest on June-01-2021
1

center a div css

/* 2 Ways to center a div in css */
/* Display Flex */
.center {	
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* Display Grid */
.center {	
  display: grid;
  place-items: center;
  min-height: 100vh;
}
Posted by: Guest on September-16-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

Browse Popular Code Answers by Language