HTML 中的 iframe 只是用作 HTML 文件的內聯框架,用於向其中添加另一個 HTML 文件。它主要用於網頁或網頁開發過程中,透過另一個來源(例如該網頁上的廣告)包含其他內容。
大多數網頁設計師使用 Iframe 在網站或網頁上呈現互動式應用程式。使用 JavaScript 或 HTML 中的目標屬性可以實現這一點。
Iframe 的主要用途是在另一個網頁中顯示一個網頁。內嵌框架應使用名為
文法
<iframe src ="URL"></iframe>
範例:
<iframe src ="www.educba.com" ></iframe>
<iframe src ="URL" height="value" width="value"></iframe>
範例:
<iframe src ="www.educba.com" height="300" width="300"></iframe>
<iframe src ="URL" style="height: value in pixels; width: value in pixels"></iframe>
範例:
<iframe src ="www.educba.com" style="height:300px; width:300px;"></iframe>
<iframe src ="URL" style="border : none;"></iframe>
可以使用以下語法將 iframe 用作連結的目標:
<iframe src ="URL" name="iframe_a"></iframe>
範例:
<iframe src ="www.educba.com" name="iframe_a"></iframe>
Iframe 中使用了不同的屬性標籤。如下:
以下是 HTML 中 Iframe 的一些範例,解釋如下:
讓我們考慮一個範例,我們將展示如何建立具有特定高度和寬度的 iframe。
代碼:
<!DOCTYPE html> <html> <body> <h2>HTML Iframes Demo</h2> <p>Here, we are showing an example of Iframe which containing specific Height and width in pixels format</p> <iframe src="C:\Users\Sonali\Desktop\HTML block elements.html" height="300" width="300"></iframe> </body> </html>
輸出:
讓我們考慮另一個例子,我們將展示如何建立具有特定高度和寬度的 iframe。但在這個例子中,我們透過 CSS 指定高度和寬度。在這裡我們可以看到滾動條正在根據內容大小進行調整。
代碼:
<!DOCTYPE html> <html> <body> <h2>HTML Iframes Demo</h2> <p>Here, we are showing an example of Iframe which containing specific Height and width in pixels format</p> <iframe src="C:\Users\Sonali\Desktop\HTML block elements.html" style="height:100px;width:300px;"></iframe> </body> </html>
輸出:
Here we are considering one example in which we will add a border to the iframe by adding some extra CSS properties to show a change in the border’s size, change in the border color, etc. So we can add as much style to our iframe.
Code:
<!DOCTYPE html> <html> <body> <h2>HTML Iframes Demo</h2> <p>Here we are showing an example of Iframe which containing a border with some additional CSS proprties</p> <iframe src="C:\Users\Sonali\Desktop\iframe.html" style="border:3px solid Blue; height: 200px;"></iframe> </body> </html>
Output:
Let’s consider another example where we will show how the target attribute opens a webpage link using an iframe.
Code:
<!DOCTYPE html> <html> <body> <h2>Iframe Demo- Target for a Link</h2> <iframe height="200px" width="100%" src="C:\Users\Sonali\Desktop\iframe1.html" name="iframe1_a"></iframe> <p><a href="https://www.educba.com/courses/">EDUCBA</a></p> <p>When the target of a link matches the name of an iframe, the link will open in the iframe.</p> </body> </html>
Output:
Target Output:
As shown above, for example, we can click on the target link EDUCBA so that it will open the following web page shown below.
An iframe is an inline frame that includes another HTML document in itself. It is the most powerful HTML element for web designing. You can add content from another source. It uses different HTML attributes like Global Attributes, Event Attributes, etc.
以上是HTML 中的 iframe的詳細內容。更多資訊請關注PHP中文網其他相關文章!