Divs with Aspect Ratio

Developer
Size
2,803 Kb
Views
56,672

How do I make an divs with aspect ratio?

Here's a little demo for creating divs that resize proportionately. In other words, as you shrink the window width, the div height will maintain its aspect ratio. Square divs for example will always remain perfectly square.. What is a divs with aspect ratio? How do you make a divs with aspect ratio? This script and codes were developed by Tcmulder on 05 August 2022, Friday.

Divs with Aspect Ratio Previews

Divs with Aspect Ratio - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Divs with Aspect Ratio</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="wide"> <h1>Wide</h1> <p>This div will maintain its aspect ratio.</p>
</div>
<div class="square"> <h1>Square</h1> <p>This div will maintain its aspect ratio.</p>
</div>
<div class="tall"> <h1>Tall</h1> <p>This div will maintain its aspect ratio.</p>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>

Divs with Aspect Ratio - Script Codes CSS Codes

.square { width: 100%;
}
.square:before { content: ""; float: left; padding-bottom: 100%;
}
.square:after { content: ""; display: table; clear: both;
}
.wide { width: 100%;
}
.wide:before { content: ""; float: left; padding-bottom: 50%;
}
.wide:after { content: ""; display: table; clear: both;
}
.tall { width: 50%;
}
.tall:before { content: ""; float: left; padding-bottom: 200%;
}
.tall:after { content: ""; display: table; clear: both;
}
*, *:before, *:after { box-sizing: border-box;
}
html,
body { height: 100%;
}
body { background-color: #20748e;
}
.square,
.tall,
.wide { padding: 1em; background: rgba(33, 64, 80, 0.5); box-shadow: 0 0 0 1px rgba(33, 64, 80, 0.2) inset; text-align: center; font-family: "Century Gothic", sans-serif;
}
.square h1,
.tall h1,
.wide h1 { margin-bottom: 0; color: #fbfbcd;
}
.square p,
.tall p,
.wide p { margin: 0; color: #b9b097; font-style: italic;
}
Divs with Aspect Ratio - Script Codes
Divs with Aspect Ratio - Script Codes
Home Page Home
Developer Tcmulder
Username tcmulder
Uploaded August 05, 2022
Rating 4.5
Size 2,803 Kb
Views 56,672
Do you need developer help for Divs with Aspect Ratio?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tcmulder (tcmulder) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!