Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

CSS Forms

CSS can significantly enhance the appearance of an HTML form.

Styling Input Fields

Employ the width property to specify the width of the input field.

Example

input {
  width: 100%;
}

The provided example pertains to all <input> elements. To style specific input types exclusively, attribute selectors can be utilized:

  • input[type=text] – targets text fields solely
  • input[type=password] – targets password fields exclusively
  • input[type=number] – targets number fields only and so forth…
  • etc..

Padded Inputs

Utilize the padding property to insert space within the text field.

Tip: When dealing with multiple inputs placed sequentially, consider adding margin to provide additional space around them.

First Name

 

Last Name

 

Example

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

Please note that we’ve configured the box-sizing property to border-box. This ensures that padding and borders are incorporated into the total width and height of the elements.

For further insights into the box-sizing property, refer to our CSS Box Sizing chapter.

Bordered Inputs

Utilize the border property to adjust the border size and color, and employ the border-radius property to introduce rounded corners.

First Name

 

 

 

Example

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

To exclusively apply a bottom border, utilize the border-bottom property.

First Name

 

Example

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

Colored Inputs

Employ the background-color property to incorporate a background color into the input, and utilize the color property to adjust the text color.

ZEUS

Example

input[type=text] {
  background-color: #3CBC8D;
  color: white;
}

Focused Inputs

By default, certain browsers may add a blue outline around the input when it receives focus (is clicked on). You can eliminate this behavior by appending outline: none; to the input.

Leverage the :focus selector to apply styling to the input field when it receives focus:

Input with icon/image

To include an icon within the input, utilize the background-image property and adjust its position using the background-position property. Additionally, note that we incorporate a significant left padding to allocate space for the icon.

Example

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

Animated Search Input

In this example, we employ the CSS transition property to animate the width of the search input upon receiving focus. Further insights into the transition property will be covered later in our CSS Transitions chapter.

Example

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

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

Styling Textareas

Tip: Utilize the resize property to inhibit resizing of textareas, thereby disabling the “grabber” in the bottom right corner.

Example

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

Styling Select Menus

Example

select {
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-radius: 4px;
  background-color: #f1f1f1;
}

Styling Input Buttons

Example

input[type=button], input[type=submit], input[type=reset] {
  background-color: #04AA6D;
  border: none;
  color: white;
  padding: 16px 32px;
  text-decoration: none;
  margin: 4px 2px;
  cursor: pointer;
}

/* Tip: use width: 100% for full-width buttons */

Responsive Form

Resize the browser window to observe the outcome. If the screen width falls below 600px, reconfigure the layout to stack the two columns vertically instead of horizontally.