Is it possible to have CSS rounded corners on an iframe?

后端 未结 5 770
傲寒
傲寒 2020-12-30 07:20

I\'ve looked around, and as far as I can see it\'s not possible, but say you\'re embedding a YouTube iframe, is it possible to round those corners using CSS?

相关标签:
5条回答
  • 2020-12-30 07:45

    You can also add it to the iframe tag if your tag has inline style:

        <iframe 
        width=\"100%\" height=\"100%\"
        frameborder=\"0\" style=\"border:0;border-radius: 25px\";
        src=". $locationlink ." allowfullscreen>
        </iframe>
    
    0 讨论(0)
  • 2020-12-30 07:55

    Wrapping the <iframe> in a <div> should work.

    #wrap {
      width: 320px;
      height: 320px;
      -moz-border-radius: 10px;
      background: red;
      position: relative;
    }
    iframe {
      width: 300px;
      height: 300px;
      position: absolute;
      top: 10px;
      left: 10px;
    }
    <div id="wrap">
      <iframe src="http://google.com" />
    </div>

    I have attached a jsfiddle to demonstrate: http://jsfiddle.net/fxPsC/

    0 讨论(0)
  • 2020-12-30 07:57

    The way to go is wrapping the iframe in a circular div as other users suggested. The only difference being that you have to add an additional style position:relative to the wrapper for it to work in Chrome browser.

    So the code would go like this:

    .circle {
    	width: 320px;
    	height: 320px;
    	-moz-border-radius: 50%;
    	-webkit-border-radius: 50%;
    	border-radius: 50%;
    	overflow:hidden;
    	position:relative;
    }
    <div class="circle">
      <iframe width="640" height="480" src="https://www.youtube.com/embed/_8CP1tT8tdk" frameborder="0" allowfullscreen></iframe>
    </div>

    0 讨论(0)
  • 2020-12-30 08:01

    The div container method described in How to Get Rounded Corners on an iFrame using Border-Radius CSS works for me.

    And to do this you simply wrap the iFrame in div tags and give the div these css properties:

    <div style="border-radius: 10px; width: 300px; overflow: hidden;">

    The border-radius should be set to whatever you want the roundness to be, and the width must be set to the width of the iFrame, else you will get only a few (if any) rounded corners. But the most important thing is the overflow: hidden, as this hides the iFrames real corners.

    0 讨论(0)
  • 2020-12-30 08:10

    Try adding this to your CSS:

    iframe {
        border-radius: 10px;
    }
    
    0 讨论(0)
提交回复
热议问题