HTML Element Style How to - Center 2 different images








Question

We would like to know how to center 2 different images.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
img {<!-- w ww . j a v a2  s  .co  m-->
  position: absolute;
  margin-top: 100px;
  right: 25%;
  width: 50%;
}

#leftdiv {
  position: relative;
  float: left;
  background: #EEE;
  height: 500px;
  width: 50%;
}

#rightdiv {
  position: relative;
  float: right;
  height: 500px;
  width: 50%;
  background: #AAA;
}
</style>
</head>
<body>
  <div id='leftdiv'>
    <img src='http://www.java2s.com/style/download.png' />
  </div>
  <div id='rightdiv'>
    <img src='http://www.java2s.com/style/download.png' />
  </div>
</body>
</html>

The code above is rendered as follows: