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.
float:position_value;
Given below are the examples of HTML Float Left:
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:
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:
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:
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.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!