There are two ways to achieve this; with and without javascript.
JavaScript Method
Here is a simple demo: a small link .
HTML:
<div class = "circle"></div>
CSS
html, body { height: 100%; } .circle { border-radius: 1000px; background-color: rgb(0, 162, 232); }
JavaScript (uses jQuery, but this is optional):
function upd() { var h = $("body").height(); $(".circle").height(h / 5); $(".circle").width(h / 5); } upd(); window.onresize = upd;
JavaScript-free method (CSS)
For a CSS-only solution, you need to use the fact that all padding values ββare calculated relative to the parent element width , not height ( link ). Small demo: small link .
HTML:
<div class = "wrapper"> <div class = "main"> </div> </div>
CSS
html, body { height: 100%; width: 100%; } .wrapper { width: 20%; display: inline-block; position: relative; } .wrapper:after { padding-top: 100%; display: block; content: ''; } .main { position: absolute; top: 0; bottom: 0; right: 0; left: 0; border-radius: 1000px; background-color: rgb(0, 162, 232); font-family: 'Arial', Helvetica, Sans-Serif; color: white; }
Chris source share