YogeshChauhan.com
How to make HTML form interactive and using CSS?
July 2, 2019

CSS is full of wonders and almost all of them are really useful. One of them is, Pseudo-classes, which defines a state of an element. For example, it styles an element when user mouses over it or when the element gets focus. We are going to talk more about the later one.

There are many Pseudo-classes and we are going to discuss about :focus Pseudo-class.

Take a look at the code below.

In the code above, I have a simple form with text inputs elements. In CSS I am adding a condition or an element state in which it’ll change the color of input field to green when it gets focus. So, the CSS is set for “input:focus”.

Also, I’ve added one more field with ID “required” and that will change the color of the text input to red when that gets focus. AS SIMPLE AS THAT.

Moving forward with same topic, have you ever seen the search box in which when you try to enter something, it gets wider? It works on the same concept of :focus pseudo class.

Checkout the code below.

In the example above, in CSS, I am setting the default width of a text input to 100px and then adding a transition to that element. In next line, I am using pseudo class to to increase the width when it gets focus. And that small but powerful interactive feature can make user excited to use your website more because it’s cool!

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 5 How to create flickering text using CSS? Mar 4 How to use data-* Attributes in HTML? Mar 4 The substr() method in JavaScript and how it’s different from substring() Mar 4 A complete guide to add responsive YouTube videos using HTML and CSS Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress?

You might also like these

SQL GROUP BY StatementSQL/MySQLWhat happens when we add Numbers and Strings in JavaScript?JavaScriptSELF JOIN in PostgresPostgresHow to display modal from bottom to top using CSS and JavaScript?CSSClean Form Input With These PHP Functions Before Inserting into DatabasePHPFive common features of Angular template syntax (with examples)Angular