lunes, 13 de septiembre de 2021

CSS Walk Pseudo-classes Forms

CSS Walk Pseudo-classes Forms



Basic html file with form and input elements.

html file
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CSS Pseudoclases</title>
    <link
      href="https://fonts.googleapis.com/css2?family=Roboto&display=s/normalize"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="https://necolas.github.io/normalize.css/" />
    <link rel="stylesheet" type="text/css" href="./css/styles.css" />
  </head>
  <body>
    <div class="container"></div>
    <h1>Pseudo-classes Forms</h1>
    <form class="formulary" >
      <div class="group">
        <label>:focus</label>
        <input class="name" type="text" placeholder="Name" />
      </div>
      <div class="group">
        <label>:disabled</label>
        <input class="id" type="text" placeholder="Id: 1" disabled />
      </div>
      <div class="group">
        <label>:valid | :invalid</label>
        <input class="email" type="email" placeholder="email@email.com" value="fulano@email.com" required />
      </div>
      <div class="group">
        <label>:required</label>
        <input class="message" type="text" placeholder="Message" value="data of message" required
        />
      </div>
      <div class="group">
        <label>:checked</label>
        <div class="radio">
          <label><input type="checkbox" id="terms" />Acept conditions and terms</label>
        </div>
      </div>
      <div class="group">
        <label>:default</label>
        <div class="checkbox">
          <label><input type="radio" name="option" id="1" value="1" />Option 1</label>
          <label><input type="radio" name="option" id="2" value="2" checked />Option 2</label>
          <label><input type="radio" name="option" id="3" value="3" />Option 3</label>
        </div>
      </div>
      <div class="group">
        <label>:in range</label>
        <input
          class="age" type="number" placeholder="099" min="1" max="100" value="1"/>
      </div>
      <button type="submit" class="button">Register</button>
    </form>
  </body>
</html>


with a very basic formating of css to start with.
css file
* {
  box-sizingborder-box;
}

:root {
  --backcolor#fcf7f8;
  --grey#494d50;
  --blue#607eeb;
}

body {
  backgroundvar(--backcolor);
  font-family"Roboto"sans-serif;
  displayflex;
  flex-directioncolumn;
  align-itemscenter;
  justify-contentcenter;
  min-height100vh;
}

.container {
  max-width500px;
  width90%;
  padding0 30px;
  border-radius20px;
  
}

.title {
  font-size20px;
  text-aligncenter;
  text-transformuppercase;
  colorvar(--grey);
  margin-bottom20px;
}
 
browser output

 Let´s format the group
.formulary .group {
  margin-bottom60px;  
}
 
 
adjusting the labels and inputs
 
.formulary .group .label {
  displayblock;
  colorvar--darkcolor);
  border-bottom5px;
  font-size14px;
}

.formulary .group > input {
    height50px;
    width100%;
    border-radius5px;
    padding20px;
    bordernone;
    border1px solid rgba(0,0,0,0.2);
}

 
browser output
 
 

Adjust the radio and checkbox
.formulary .group .radio input,
.formulary .group .checkbox input{
    margin-right10px;
}

.formulary .group .checkbox label{
    margin-right20px;
}
 
 

Now adjusting the button and only the first labels

.button {
    width100%;
    backgroundvar(--blue);
    displayinline-block;
    padding25px;
    cursorpointer;
    colorblack;
    text-transformuppercase;
    border-radius5px;
    transition.3s ease all;
    border:none;
}

button:hover {
    backgroundvar(--bluesecond);
}

.formulary > div > label:first-of-type {
    font-weightbolder;
}
 


Pseudo Classes in Action

This pseudo-classes are relative to the actions over the input fields

/* ======= Pseudo Classes ========*/

.formulary .name:focus {
   border5px solid var(--bluesecond);
}

.formulary .id:disabled {
    backgroundvar(--backcolor);
    filteropacity(50%);
}

.formulary .email:valid {
    backgroundlimegreen;
    bordernone;
}

.formulary .email:invalid {
    backgroundrgb(2387272);
    bordernone;
}

.formulary .message:required {
    backgroundrgb(25312417);
    bordernone;
}

.formulary .radio input:checked {
    box-shadow0 0 10px 2px rgb(0110255);
}

.formulary .checkbox input:default {
    box-shadow0 0 10px 2px rgb(117117117);
}

.formulary .age:in-range {
    box-shadow0 0 10px 2px limegreen;
    bordernone;
}

.formulary .age:out-of-range {
    backgroundrgb(2387272);
    bordernone;
}



eot

No hay comentarios:

Publicar un comentario