Form - Form in CSS

Forms - forms are an integral part of any kind of website. Let's see how to build the display interface part of a basic form.

Forms - forms are an integral part of any kind of website. In this article, TipsMake.com will show you how to build the display interface of a basic form. This interface can be done quite nicely with CSS, like this:

Picture 1 of Form - Form in CSS

Format sections in the form

School entered

Use width attribute to determine the width of the input field:

 input { 
width: 100%;
}

Picture 2 of Form - Form in CSS

This code will apply to all elements. If you want to style a specific input type, you can use Attribute Selector:

  1. input [type = text]: specifies the type for all fields with the type attribute, the text value.
  2. input [type = password]: specifies the type for all fields with the type attribute, the password value.
  3. input [type = number]: specifies the type for all fields with the type attribute, the number value.

Add padding and margin for the input field

 input[type=text] { 
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}

Use the padding attribute to make space inside the text field more extensive. You should also use margin to have space outside the school, helping schools to be separated by a certain distance.

Form does not have padding and margin:

Picture 3 of Form - Form in CSS

The form has both padding and margin:

Picture 4 of Form - Form in CSS

Add a box-sizing attribute : border-box to allow the padding and the border of the box to fit within the predefined element size.

Simple code like this for you to see more, try changing the values ​​to see the difference:









 

 



Format Border

Use the border attribute to resize and border colors, combine with border-radius properties to format rounded corners.

 input[type=text] { 
border: 2px solid purple;
border-radius: 4px;
}

Picture 5 of Form - Form in CSS

For example:










 

 



If you only want the frame to have only the lower border, use the border-bottom attribute :

Picture 6 of Form - Form in CSS

 input[type=text] { 
border: none;
border-bottom: 2px solid purple;
}

Color format

Use background-color attribute to add background color to input field and color attribute to change text color:

 input[type=text] { 
background-color: #58257b;
color: white
}

Picture 7 of Form - Form in CSS

For example:










 

 



Impress the entry field

By default, some browsers will add a blue border around the input field when users click to fill in the information. You can remove this by adding outline: none attribute .

Should use selector : focus to make an impression for the input field, drawing attention to users when they click on the box:

Use another colored background Emphasize with border border
 input[type=text]:focus { 
background-color: lightblue;
}
 input[type=text]:focus { 
border: 3px solid #555;
}
Picture 8 of Form - Form in CSS
Picture 9 of Form - Form in CSS
 input[type=text] { 
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #58257b;
outline: none;
}

input[type=text]:focus {
background-color: #e9d8f4;
}

Add the transition CSS attribute to animate the border color (take 0.5 seconds to change the color when clicking).

 input[type=text] { 
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 3px solid #e9d8f4;
-webkit-transition: 0.5s;
transition: 0.5s;
outline: none;
}

input[type=text]:focus {
border: 3px solid #58257b;
}

Input field has icon / image

You can add an icon or image to the input field, usually at the top to express the purpose of the field, use the background-image attribute and locate it with the background-position attribute . Note, setting the left padding size is wide enough to have space for the icon. The most obvious example is the magnifying glass icon before each search bar on websites:

 input[type=text] { 
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding-left: 40px;
}

Picture 10 of Form - Form in CSS

For example:









 



Effects for search box

To make a point here, use the CSS transition attribute to create the effect, making the search box stretch out after the user clicks on it, which looks pretty nice.

 input[type=text] { 
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}

input[type=text]:focus {
width: 100%;
}

Picture 11 of Form - Form in CSS

For example:










 



Textarea box format

Use the resize attribute to fix the textarea box size.

 textarea { 
width: 100%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
resize: none;
}

Picture 12 of Form - Form in CSS

For example :









Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile