sureshalagarsamy / html-div-inside-div-horizontal

Div inside div horizontal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Div inside div horizontally center

Example-1

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Div inside div center</title>
<link rel="Stylesheet" type="text/css" href="style.css">
</head>

<body>
  <div class="parent">
    <div class="child">test</div>
  </div>
</body>

</html>

CSS

.parent {
  width : 200px;
  height: 200px;
  border: 1px solid #DDD;
}

.child {
  width : 50px;
  height: 50px;
  border: 1px solid #DDD;
  margin: 0 auto;
  text-align:center;
  background-color: #F6F6F6;
}

Output

ScreenShot

Example-2

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Div inside div center</title>
</head>
<body>
  <div class="flex-container">
    <div class="item">item 1</div>
  </div>
</body>
</html>

CSS

.flex-container {
    display: -webkit-flex;
    display: flex;
    -webkit-justify-content: center;
    justify-content: center;
    width: 200px;
    height: 100px;
    background-color: #F6F6F6;
    border: 1px solid #BBB;
    border-radius: 6px;
    box-shadow: 0 0 9px #BBB;
}

.item {
    background-color: #DDD;
    text-align:center;
    width: 50px;
    height: 50px;
    margin: 10px;
    border-radius: 3px;
    border: 1px solid #BBB;
}

Output

ScreenShot

Note

These 2 properties only used make inner div as center.. other properties will be used for cosmetic effects only.

display: flex;
justify-content: center;

About

Div inside div horizontal


Languages

Language:HTML 53.8%Language:CSS 46.2%