centering code example

Example 1: css centering

// grid

.parent { 
  display: flex;
  align-items: center;
  justify-content: center;
}

//flex box

.parent { 
  display: flex;
  align-items: center;
  justify-content: center;
}

// position

.parent { 
  position: relative;
}

.child {
  position: absolute;
  left: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
}

Example 2: centering in html

<style>
  element
  {
    text-align: center;
  }
</style>
-------------------------------------------------------------------------------
style.css
element
{
	text-align: center;
}

Example 3: centering horizontally

div.center{display:block;margin:auto;width:50%;}
p.center{text-align:center;}

Tags:

Html Example