如何裁剪 HTML IFrame?
內聯框架被稱為 HTML 中的 iframe。 <iframe> 標籤 指定內容中一個矩形區域,瀏覽器可以在其中顯示另一個文件,包括捲軸和邊框。要將另一個文件嵌入到當前 HTML 文件中,請使用內聯框架。
可以使用 HTML iframe 的 name 屬性來指定 <Iframe> 元素的引用。在 JavaScript 中,也使用 name 屬性來引用元素。Iframe 主要用於在當前顯示的網頁內顯示另一個網頁。包含 iframe 的文件的 URL 使用 src 屬性指定。
語法
以下是 HTML <iframe> 的語法。
<iframe src="URL" title="description"></iframe>
為了更好地理解如何裁剪 HTML iframe,讓我們看看以下示例。
示例
在下面,我們使用 div 元素,使我們的 iframe 被裁剪,並且 iframe 的捲軸不顯示其輸出。
<!DOCTYPE html>
<html>
<body>
<div style="position: absolute; left: 0px; top: 0px; border: solid 2px #555; width:594px; height:332px;">
<div style="overflow: hidden; margin-top: -100px; margin-left: -25px;">
</div>
<iframe src="https://tutorialspoint.tw/index.htm" scrolling="no" style="height: 490px; border: 0px none; width: 619px; margin-top: -60px; margin-left: -24px; ">
</iframe>
</div>
</body>
</html>
當指令碼執行時,它將生成一個輸出,其中包含一個被裁剪的 iframe,並且該 iframe 嵌入到網頁中,沒有可滾動選項。
示例
考慮以下示例,我們使用 div 元素 和 CSS 來裁剪 iframe 並顯示其輸出。
<!DOCTYPE html>
<html>
<body>
<style>
iframe {
position: fixed;
top: -40px;
left: 0;
bottom: 0;
right: 0;
width: 65%;
height: 70%;
border: none;
margin: 0;
padding: 0;
overflow: hidden;
z-index: 999999;
}
</style>
<div class="iframe">
<iframe src="https://tutorialspoint.tw/index.htm"></iframe>
</div>
</body>
</html>
執行上述指令碼後,將彈出輸出視窗,顯示被裁剪並顯示在網頁上的 iframe,並帶有捲軸。
示例
執行以下程式碼,並觀察我們如何透過執行指令碼並將 scrollable 設定為 no 來裁剪 iframe。
<!DOCTYPE html>
<html>
<body>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
}
h1 {
font-family: Impact, sans-serif;
color: #8E44AD;
}
iframe {
width: 1024px;
height: calc(100vh - 300px);
overflow: hidden;
margin: 0 auto;
border: none;
}
</style>
<h1 id="tutorial">TutorialsPoint</h1>
<p>The Best E-Way Learning</p>
<iframe id="booking-content" title="booking-content" src="https://tutorialspoint.tw/index.htm" scrolling="no" allowfullscreen="allowfullscreen">
</iframe>
<script>
let tutorial = 0;
let element = document.getElementById('tutorial');
while (element.nodeName !== 'IFRAME') {
tutorial += element.offsetHeight;
element = element.nextElementSibling;
}
tutorial = window.innerHeight - tutorial - 100;
document.querySelector('iframe').style.height = tutorial + 'px';
</script>
</body>
</html>
輸出
當指令碼執行時,它將生成一個輸出,其中包含文字以及一個已被裁剪的 iframe,將可滾動選項減少為 no。
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP