Skip to content

Instantly share code, notes, and snippets.

@Allenice
Last active March 9, 2017 06:28
Show Gist options
  • Save Allenice/1fc5a2f54a2f514d6f17 to your computer and use it in GitHub Desktop.
Save Allenice/1fc5a2f54a2f514d6f17 to your computer and use it in GitHub Desktop.
div 宽高等比
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.h-equal-w {
width: 100px;
overflow: hidden;
background: #ccc;
position: relative;
}
.h-equal-w:before {
content: '';
display: block;
padding-top: 100%;
}
.content {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div class="h-equal-w">
<div class="content">height equal width</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment