Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

center div scss

/* With FLEX: */
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* With GRID: */
.container {
	display: grid;
	place-items: center
}

/* With plain CSS: */
.center-div {
	margin: auto;
  	width: 50%;
  	aspect-ratio: 1 / 1;
}

/* With positioning: */
.parent{
	position: relative;
}

.parent .center-div {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) '
}
 
PREVIOUS NEXT
Tagged: #center #div #scss
ADD COMMENT
Topic
Name
7+3 =