Loading...

使用CSS讓Youtube自動適應寬度跟高度

Temperature: 0 °C

Mark ChangMark Chang
author_tools


使用CSS讓Youtube自動適應寬度跟高度
在播放Youtube影音的時候,常使用 iframe 的方式崁入網頁裡。

例如:

<iframe src="URL" frameborder="0" data-devanime="fadeIn" data-devanime-delay="0.6s"></iframe>


但往往展開的影音卻無法自動適應高度填滿整個DIV位置。

這時可以透過以下CSS設定來解決這個問題。
.video-div {
position: relative;
width:100%;
height: 100%;
overflow: hidden;
}

.video-div iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}

接著將 iframe 包在DIV裡如下範例:

<div class="video-div">
<iframe src="URL" frameborder="0" data-devanime="fadeIn" data-devanime-delay="0.6s"></iframe>
</div>

https://innstory.com/story-使用CSS讓Youtube自動適應寬度跟高度-1582
CSS

Prev
 使用CSS讓整個網頁由彩色變黑白色!

Next
分享_aha__Take_On_Me_Official_Video 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

PHP無法保存SESSION的問題

PHP無法保存SESSION...

一天,客戶反應系統後台無法登入。 而這問題是發生在客戶電腦更換了IP位置。 而我這邊也只是開放新的I...

想在網頁上預覽PDF可使用的方案

想在網頁上預覽PDF可使用的...

使用pdfobject.js #設定顯示位置 <div id="pdf"></d...

在PHP強制顯示錯誤訊息的方法

在PHP強制顯示錯誤訊息的方...

若是單一檔案,只需要在每個PHP檔案裡添加下列行: iniset(&#;displayerrors&...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format