Consider the following example: (live demo)
HTML:
<div>div</div>
<iframe></iframe>
CSS:
div, iframe {
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #777;
}
Result:
Why the iframe
is not centrally aligned like the div
? How could I centrally align it?
This question is related to
html
css
iframe
alignment
center-align
HTML:
<div id="all">
<div class="sub">div</div>
<iframe>ss</iframe>
</div>
CSS:
#all{
width:100%;
float:left;
text-align:center;
}
div.sub, iframe {
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #777;
}
Here I have put snippet for all of you who are suffering to make iframe or image in center of the screen horizontally. Give me THUMBS UP VOTE if you like.?.
style > img & iframe > this is your tag name so change that if you're want any other tag in center
<html >_x000D_
<head> _x000D_
<style type=text/css>_x000D_
div{}_x000D_
img{_x000D_
margin: 0 auto;_x000D_
display:block;_x000D_
}_x000D_
iframe{ _x000D_
margin: 0 auto;_x000D_
display:block;_x000D_
}_x000D_
_x000D_
</style>_x000D_
</head>_x000D_
<body >_x000D_
_x000D_
<iframe src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4" width="320" height="180" frameborder="0" allowfullscreen="allowfullscreen"></iframe> _x000D_
_x000D_
<img src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg" width="320" height="180" />_x000D_
</body> _x000D_
</html>
_x000D_
The simplest code to align the iframe element:
<div align="center"><iframe width="560" height="315" src="www.youtube.com" frameborder="1px"></iframe></div>
If you are putting a video in the iframe and you want your layout to be fluid, you should look at this webpage: Fluid Width Video
Depending on the video source and if you want to have old videos become responsive your tactics will need to change.
If this is your first video, here is a simple solution:
<div class="videoWrapper">_x000D_
<!-- Copy & Pasted from YouTube -->_x000D_
<iframe width="560" height="349" src="http://www.youtube.com/embed/n_dZNLr2cME?rel=0&hd=1" frameborder="0" allowfullscreen></iframe>_x000D_
</div>
_x000D_
And add this css:
.videoWrapper {_x000D_
position: relative;_x000D_
padding-bottom: 56.25%; /* 16:9 */_x000D_
padding-top: 25px;_x000D_
height: 0;_x000D_
}_x000D_
.videoWrapper iframe {_x000D_
position: absolute;_x000D_
top: 0;_x000D_
left: 0;_x000D_
width: 100%;_x000D_
height: 100%;_x000D_
}
_x000D_
Disclaimer: none of this is my code, but I've tested it and was happy with the results.
You can try
<h3 style="text-align:center;"><iframe src=""></iframe></h3>
I hope its useful for you
best way and more simple to center an iframe on your webpage is :
<p align="center"><iframe src="http://www.google.com/" width=500 height="500"></iframe></p>
where width and height will be the size of your iframe in your html page.
You can put iframe inside a <div>
<div>
<iframe></iframe>
</div>
It works because it is now inside a block element.
My simplest solution to this.
iframe {
margin:auto;
display:block;
}
In my case solution was on iframe class adding:
display: block;
margin-right: auto;
margin-left: auto;
According to http://www.w3schools.com/css/css_align.asp, setting the left and right margins to auto specifies that they should split the available margin equally. The result is a centered element:
margin-left: auto;margin-right: auto;
If you can't access the iFrame class then add below css to wrapper div.
<div style="display: flex; justify-content: center;">
<iframe></iframe>
</div>
Source: Stackoverflow.com