Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div class="responsive-container">
    <div class="dummy"></div>
    <div class="img-container">
      <IMG HERE/>
    </div>
</div>
  
<div class="responsive-container">
  <div class="dummy"></div>
    <div class="img-container2">
      <IMG HERE/>
    </div>
</div>
</body>
</html>
 
.responsive-container {
    position: relative;
    width: 100%;
    border: 1px solid black;
}
.dummy {
    padding-top: 100%; /* forces 1:1 aspect ratio */
}
img {
    width:300px;
    height:300px;
    background-color:red;  
}
.img-container {
    position: absolute;
    top: 50%;
    left: 50%;
}
.img-container > img {  
    margin-top:-50%;
    margin-left:-50%;
}
.img-container2 {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%); /* add browser-prefixes */
    transform: translate(-50%, -50%); /* add browser-prefixes */
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Tibospro
0viewers