Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perfect Responsive Circle iFrame

How would I create an iFrame that is a perfect circle and responsive? I know I can add rounded corners by surrounding the iframe with a div, but I'm not sure how I can make a perfect circle.

like image 771
jporcenaluk Avatar asked Apr 16 '26 18:04

jporcenaluk


1 Answers

You need to wrap your iframe with two divs. The inner one should be position: absolute;, while the outer one should be position: relative. You can use a static and equal height and width in order to make it a perfect circle, as shown in this jsfiddle examples.

HTML

<div class="iframe-outer"><!--position: relative-->
    <div class="iframe-inner"><!--position: absolute-->
        <iframe src="www.google.com" width="600" height="450"></iframe>
    </div>
</div>

However, because we live in a world of varying screen sizes, and because you want a perfect circle, it's useful to add a little more CSS to allow for this to be responsive, based on Nathan Ryan's answer to "Height Equal To Dynamic Width."

Here's a jsfiddle to demonstrate a complete solution.

like image 198
jporcenaluk Avatar answered Apr 18 '26 14:04

jporcenaluk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!