×

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear float determines the bug, which appears when two or more floated components are loaded after each other.

Assume if we set any sidebar’s position towards the left side of primary content blocks. Though, we can take the component overlap and collapse to each other. Also, we can assume it as if any child component is taller as compared with its parent component and floated; it will get started to overflow outer to its container.

 To overcome the above problem, we can apply overflow: auto; attribute to a containing component.

Let’s take an example to understand it:

Example:

In the following example, the image is taller as compared with the containing component and floated, so it overflows outer to its container.

We are making a flo class and overflow: auto; attribute to a corresponding component as follows:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
div
{ 
  border: 3px solid black; 
  padding: 5px; 
  background-color: lightblue; 
  font-size:20px; 
} 
img
{ 
  float: right; 
  border: 3px solid navy; 
} 
p
{ 
 font-size:20px; 
 clear:right; 
} 
.flo
{ 
  overflow: auto; 
} 
</style> 
</head> 
<body> 
<h1> Without Clearfix </h1> 
<div> 
  <img class="img1" src="Flower1.jpg"> 
   Welcome to this Page. It is the example to clear the concept of 'Clearfix' property. Here, clearfix is not used.
</div> 
<p> Use the overflow:auto; CSS attribute </p> 
<h1> With Clearfix </h1> 
<div class="flo"> 
  <img class="img2" src="Flower1.jpg"> 
   Welcome to this Page. It is the example to clear the concept of 'Clearfix' property. Here, clearfix is used.
</div> 
</body> 
</html> 

The above mentioned clear float method implements well if we handle the margins and paddings. Although a new practice to clear float is safer for use.

Output:

CSS Clearfix

Let’s take another example to understand this concept more clearly:

Example:

In the following example, we have applied the clear attribute on ‘both’, i.e. floating components will not permit for both the right and left sides. Also, we apply the display attribute on ‘table’, which creates the component behave like the <table> component of HTML. Then we have to let the content blank. 

<!DOCTYPE html> 
<html> 
<head> 
<style> 
div
{ 
  border: 3px solid black; 
  padding: 5px; 
  background-color: lightblue; 
  font-size: 20px; 
} 
img
{ 
  float: right; 
  border: 3px solid navy; 
} 
p
{ 
 font-size: 20px; 
 clear: right; 
} 
.flo:after
{ 
  content:'.';
  clear: both;
  display: table;
} 
</style> 
</head> 
<body> 
<h1> Without Clearfix </h1> 
<div> 
  <img src="Flower1.jpg"> 
   Welcome to this Page. It is the example to clear the concept of 'Clearfix' property. Here, clearfix is not used.
</div> 
<p> Another clearfix technique </p> 
<h1> With Clearfix </h1> 
<div class="flo"> 
  <img src="Flower1.jpg"> 
   Welcome to this Page. It is the example to clear the concept of 'Clearfix' property. Here, clearfix is used.
</div> 
</body> 
</html> 

Output:

CSS Clearfix

CSS Icons  

CSS icons are specified like a symbol or image used inside a computer interface assign to any element. CSS icons are the graphical depiction of any program or file that supports users to recognize the file type quickly.

It is a most comfortable way of inserting icons to any HTML page by using an icon library. It is feasible to format an icon library with the use of CSS. We may customize any icon based on their size, shadow, and color.

Here we are mentioning some of the essential icon libraries like Google icons, Font Awesome icons, and Bootstrap icons that may be used efficiently inside the CSS. We don’t need to download or install these icon libraries.

Description of the above libraries is as follows:

Font Awesome icons

We have to insert a link to use font awesome icons library. This link will be defined in the <head> section, which is mentioned below:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">  

Related Topics

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

HTML Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

HTML &lt;blink> Tag

In HTML, the blink tag is used to create the text which flashes. The blink tag is an inline element in HTML. It is observed that the blink tag used...

2 minutes read.

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear...

4 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML <source> tag

For media attributes, such as <video> tag, <audio> tag, and <picture> tag, we use the <source> tag in html for adding such type of multiple media html elements in our...

4 minutes read.

How to change text color in HTML

Changing the text colour of a web page is essential because it enhances readability. There are several ways to change the colour of the text in HTML, which are as follows: Text...

7 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

HTML <video> Tag

The Video tag in HTML is used to play video on a media player on the web page. We can also insert an audio by the video tag, but audio...

6 minutes read.

HTML <summary> tag

When we simply want to show the primary heading or topic name of hidden detailed material to users, then we can achieved this by using the summary tag. This makes it...

2 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 minutes read.

HTML Reset Button

The HTML reset button is used to reset all values in the form. It clears all input fields. Reset is the value of the type attribute of the button element. The...

6 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML Lists

HTML List HTML lists are used to specify data sets. All lists can include one or more elements from the list. HTML lists are available in three different types: Ordered List or...

4 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute read.

HTML 5 Tutorial

What is HTML5? HTML5 is a programming language which stands for the acronym Hyper Text Markup Language 5. It is program that enables the appearance of web pages to be changed, as well as changes...

5 minutes read.