Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

what is the best way to center a div

.container {
  font-family: arial;
  font-size: 24px;
  margin: 25px;
  width: 350px;
  height: 200px;
  outline: dashed 1px black;
  /* Setup */
  position: relative;
}

.child {
  width: 50px;
  height: 50px;
  background-color: red;
  /* Center vertically and horizontally */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #center #div
ADD COMMENT
Topic
Name
8+3 =