how to centre align div in html code example

Example 1: how to align elements horizontally in css

.row {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.block {
  width: 100px;
}

Example 2: css center text

/* To center text, you need to use text-align. */

.centerText {
  text-align: center; /* This puts the text into the center of the 
  screen. */
}

/* There are also other things that you can use in text-align:
left, right, and justify. Left and right make the test align to the
right or left of the screen, while justify makes the text align both
sides by spreading out spaces between some words and squishing others. */

Example 3: css center text in div vertically

<!DOCTYPE html>
<html>
   <head>
      ...
      <style type="text/css">
         div{
         width: 200px;
         height: 200px;
         border: solid green;
         display: table-cell;
         vertical-align: middle;
         }
      </style>
   </head>
   <body>
      <div>Vertikal ausgerichteter Text</div>
   </body>
</html>

Example 4: how to center text in css

.class {
	text-align: center;
}

Example 5: align a div in center of another div

#container {
    width: 640px; /*can be in percentage also.*/
    height: auto;
    margin: 0 auto;
    padding: 10px;
    position: relative;
}

Example 6: how to align elements horizontally in css

<div class="row">
  <div class="block">Lorem</div>
  <div class="block">Ipsum</div>
  <div class="block">Dolor</div>
</div>

Tags:

Misc Example