目錄
Syntax
Examples of HTML Float Left
Example #3
Conclusion
首頁 web前端 html教學 HTML 左浮動

HTML 左浮動

Sep 04, 2024 pm 04:50 PM
html html5 HTML Tutorial HTML Properties HTML tags

Alignment of the elements for building the HTML webpage is one of the most important tasks. This can be done by using one of the CSS property called float with its position value. Float property can be used with values as Right, Left, none, inline-start, inline-end. Float Left tag in HTML is responsible to show all text or elements into the left side of the included container or in the left position body part of HTML. Whenever this float left element is used its changes the normal flow of contents and moves, it’s towards the left side of the container.

Syntax

  • The syntax for defining position float left in HTML is as follows:
float:position_value;
登入後複製
  • As shown in the above syntax, floated elements are going to show with their position value. It could be left, right or none. Ex: float: left;
  • Some situation comes where we want to change the position of elements below floated elements. So we want to clear elements before putting any other elements by clearing floats.
  • Floating elements help us move contents into the same parent who will be going to move on and wrap all those elements around the floating elements.
  • One of the alternative options for Float based layouts is Flexbox, which is used for designing modern websites layout.
  • While designing any webpage, we are going to use header, navigation menu, sidebar, navbar, main content of the page, and footer. All those are treated as a container element that is stored as HTML content.
  • One can use more than one left floated element in their webpage. So it will be useful for designing the multi-column layout.
  • The best website design is considered the use of 3 nested div blocks, which helps design the layout of the page, including a container block, along with a full-width page for storing all elements and one more block called sidebar content blocks. Those two blocks are aligned with HTML property float left.
  • Float left property can be useful in both inline as well as block-level elements. It’s also useful for displaying an image on the left side of the div.
  • Float elements can be applied only on elements that are placed horizontally in the code structure.

Examples of HTML Float Left

Given below are the examples of HTML Float Left:

Example #1

This is an example showing paragraphs content Left aligned.

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Float Left</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.img {
float: left;
width: 60px;
height: 60px;
margin: 25px;
border-radius: 40px;
background-color: lime;
}
.hd {
margin-top: 30px;
}
.pg {
margin: 10px;
overflow: hidden; /* This is important */
}
</style>
</head>
<body>
<div class='column'>
<div class='img'>
</div>
<h3 class='hd'>Photography</h3>
<p class='pg'>Photography is latest crazy trend going on now a days. People are going to be more passionate about capturing live moments. A perfect Cameraman and perfect camera captures mind-blowing picture. Being professional photographer is one of the best careers now a days which combine passion and money. Photography can be any type of Wedding shoot, Pre wedding shoot, Baby Shower, Birthday, Professional photography and many more. It can suitable to any age group. It does can be art and science. This is the skill to enhance personal hobby in career. A photographer must be able to create a good composition of any subject, a piece of machinery, the beauty of human body, scenery or a child's smile. </p>
</div>
<div class='column'>
<div class='img'></div>
<h3 class='hd'>Architecture</h3>
<p class='pg'>Architecture is all about thoughts and creating something new in given space.
architects has power to change the world. Architecture has all skill to develop personal skills. It is also known as latest trendy career option in the market now a days. It helps to build beautiful structure of houses, buildings, and other entities. A good architecture have creative mind. Those people club their skills to create amazing buildings </p>
</div>
</body>
</html>
登入後複製

Output:

HTML 左浮動

Example #2

This is a small layout of the webpage in which contents are aligned on the left-hand side of the container.

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Float Left</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.header {
padding: 8px;
text-align: center;
background: lightblue;
color:black;
}
.navbar {
overflow: hidden;
background-color: lightcyan;
}
.navbar a {
float: left;
display: block;
color: black;
text-align: center;
padding: 12px 12px;
}
.navbar a.left {
float: left;
}
.navbar a:hover{
background-color: #eee;
color: black;
}
.row {
display: flex;
flex-wrap: wrap;
}
.sidebar {
background-color: #f1f1f1;
padding: 10px;
}
.main {
background-color: white;
padding: 20px;
}
.logoimg {
float:left;
}
</style>
</head>
<body>
<div class="header">
<div class="logoimg" ><img src="C:\Users\Sonali\Desktop\t2.jpg" style="width:70%;"></div>
<h1>Welcome to Crazy Travelers</h1>
</div>
<div class="navbar">
<a href="#">Historical Places</a>
<a href="#">Beaches</a>
<a href="#">Adventoures Tour</a>
<a href="#">Study Tour</a>
</div>
<div class="row">
<div class="sidebar">
<h2>Goa Calling</h2>
<div><img src="C:\Users\Sonali\Desktop\t1.jpg" style="height:100px;"></div>
<h4>Explore Beaches, Enjoy Sea-food</h4>
<h2>Adventurous Trekking</h2>
<div ><img src="C:\Users\Sonali\Desktop\t4.jpg" style="height:100px;"></div>
<h4>Paragliding, Rock climbing and many more</h4>
</div>
<div class="main">
<img src="C:\Users\Sonali\Desktop\travel 1.jpg" style="width:80%;">
<p> Travaling is main part of our life.Every travaling has some eductional value.It gives peaace of mind to everyone.</p>
</div>
</div>
</body>
</html>
登入後複製

Output:

HTML 左浮動

Example #3

Code:

<!DOCTYPE html>
<html>
<head>
<title>CSS float left for multiple elements</title>
<style>
.imgs {
float: left;
width: 140px;
height: 100px;
margin: 10px;
}
</style>
</head>
<body>
<h3>HTML Float Left</h3>
<p>Image demo with Float left. Minimize and Maximize browser will show differences. </p>
<img class="imgs" src="C:\Users\Sonali\Desktop\1.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\2.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\3.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\4.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\5.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\6.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\7.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\8.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\9.jpg"/>
<img class="imgs" src="C:\Users\Sonali\Desktop\10.jpg"/>
</body>
</html>
登入後複製

Output:

  • 1st screen output with left alignment with Float Left attribute, This output with minimizing screen are as follows:

HTML 左浮動

  • 2nd Output with normal screen

HTML 左浮動

  • 3rd output with maximizing screen

HTML 左浮動

Conclusion

HTML float can be used with values left, right, inline-start, inline-end, etc. HTML float left is used to align content at the left alignment of the webpage or HTML document. Whenever Float left is used within code, it is responsible for putting contents on the left side of the container. It is most of the time used within the sidebar and other contents into the webpage layout.

以上是HTML 左浮動的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1663
14
CakePHP 教程
1420
52
Laravel 教程
1315
25
PHP教程
1266
29
C# 教程
1239
24
HTML 中的表格邊框 HTML 中的表格邊框 Sep 04, 2024 pm 04:49 PM

HTML 表格邊框指南。在這裡,我們以 HTML 中的表格邊框為例,討論定義表格邊框的多種方法。

HTML 中的巢狀表 HTML 中的巢狀表 Sep 04, 2024 pm 04:49 PM

這是 HTML 中巢狀表的指南。這裡我們討論如何在表中建立表格以及對應的範例。

HTML 左邊距 HTML 左邊距 Sep 04, 2024 pm 04:48 PM

HTML 左邊距指南。在這裡,我們討論 HTML margin-left 的簡要概述及其範例及其程式碼實作。

HTML 表格佈局 HTML 表格佈局 Sep 04, 2024 pm 04:54 PM

HTML 表格佈局指南。在這裡,我們詳細討論 HTML 表格佈局的值以及範例和輸出。

HTML 輸入佔位符 HTML 輸入佔位符 Sep 04, 2024 pm 04:54 PM

HTML 輸入佔位符指南。在這裡,我們討論 HTML 輸入佔位符的範例以及程式碼和輸出。

您如何在PHP中解析和處理HTML/XML? 您如何在PHP中解析和處理HTML/XML? Feb 07, 2025 am 11:57 AM

本教程演示瞭如何使用PHP有效地處理XML文檔。 XML(可擴展的標記語言)是一種用於人類可讀性和機器解析的多功能文本標記語言。它通常用於數據存儲

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在這裡我們也分別討論了 HTML 有序列表和類型的介紹以及它們的範例

HTML onclick 按鈕 HTML onclick 按鈕 Sep 04, 2024 pm 04:49 PM

HTML onclick 按鈕指南。這裡我們分別討論它們的介紹、工作原理、範例以及各個事件中的onclick事件。

See all articles