×

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 Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

HTML Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute read.

HTML Code

Before jumping into the topic, let’s understand a common scenario where we have a code snippet in our HTML file. By code snippet, we mean computer code, which is written...

5 minutes read.

HTML Background Image

Inserting image in HTML An image (technically digital image) in HTML or even in general technical aspects, is a binary representation of visual information. By visual information we mean, in the...

8 minutes read.

Html &lt;Col> Tag

You can write the col tag inside the table tag after the thead, tbody, foot, and tr tags. You can also apply it after the caption tag (in which the...

4 minutes 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.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.

HTML Paragraphs

In html, there are some elements which starts with new line and one of them is paragraph. Which is said to be a block of text. In html <p> tag...

4 minutes read.

HTML Canvas

HTML Canvas: Using JavaScript, the < canvas > tag in HTML is used for drawing graphics on web page. It can be used to draw routes, boxes, text, gradient, and...

3 minutes read.

HTML <strike> tag

The HTML <strike> tag is used to specifies strikethrough text. The tag is deprecated now and <del> tag is used in HTML files instead of it. All the global and...

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 Code Tag

The code tag in HTML is a phrase tag used to insert a piece of computer programming code. In HTML there is a separate tag named as <code> tag. Sometimes,...

3 minutes read.

How to insert spaces/tabs in text using HTML/CSS

What is HTML? HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The file extension name for HTML file is “.html”. An HTML file...

4 minutes read.

HTML Data Tag

HTML Data Tag: The HTML < data > tag is used to transmit its content to a machine-readable version. The data are presented in a particular format. It is useful...

3 minutes read.

How to create a link with no underline in HTML

In HTML, an anchor tag (<a>) is a Styled Container tag, which means when a hyperlink is created using this, browsers, by default, display the link by applying some styles...

5 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.

How to append HTML code to a div using JavaScript?

In HTML, we have a div tag which is used to create a box where we can put a lot of other tags. So it works like a container. So,...

4 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

Most Commonly used Tags in HTML

In this tutorial, we'll look at the most popular HTML tags. We know HTML is a fundamental requirement for creating a website. As a result, it is essential to remember...

9 minutes read.