Skip to main content

Form Focus Element - CSS

Utilise :focus-within to have more visual emphasis on the part of an element that has a focused element.

DEMO

Step 1
Step 2

HTML

<fieldset>
    <legend>Step 1</legend>
    <div>
      <label for="q_1">Answer 1:</label>
      <input id="q_1" />
    </div>
    <div>
      <label for="q_2">Answer 2:</label>
      <input id="q_2" />
    </div>
  </fieldset>

  <fieldset>
    <legend>Step 2</legend>
    <div>
      <label for="q_3">Answer 3:</label>
      <input id="q_3" />
    </div>
    <div>
      <label for="q_4">Answer 4:</label>
      <input id="q_4" />
    </div>
  </fieldset>

CSS

fieldset{
  margin: 0 20px 20px;
  background: #eee;
  border-radius: 3px;
  border: solid 1px #aaa;
  position: relative;
  transition: all 0.2s;
}

fieldset::before {
  content: '\1F6A9';
  font-size: 24px;
  position: absolute;
  right: 10px;
  top: -5px;
  transition: all 0.2s;
  opacity: 0;
  transform: translateX(-20px);
}

legend {
  margin-left: 8px;
  text-transform: uppercase;
  color: #555;
  font-size: 80%;
  letter-spacing: 0.5px;
}

input {
  margin-left: 1em;
  padding: 0.2em 0.5em;
  border: solid 1px #999;
  width: calc(100% - 130px);
}

input:focus {
  outline: none;
  border-color: Crimson;
  box-shadow: 0 0 1px 1px #1389fd;
}

div {
  margin: 0.5em;
}


fieldset:focus-within {
  background: Cornsilk;
  transform: scale(1.02);
}

fieldset:focus-within::before {
  opacity: 1;
  transform: translateX(0px);
}

Comments

Popular posts from this blog

Input Range with CSS

  Use ::in-range and ::out-of-range pseudo-classes to style input depending on input value. DEMO 1 to 10 are valid. HTML < label > 1 to 10 are valid .</ label > < input type = "number" value = "1" min = "1" max = "10" > CSS input : in - range { background - color: limegreen; } input :out - of - range { background - color: orange; }

Create Vertical Text - CSS

From the old internet, the direction of text is pretty much fixed on left-to-right. In modern CSS has addressed the issue and supports vertical text with ease. Right to Left Vertical Text Right to Left Vertical Text HTML <div class= "v-rl" > <p> Right to Left </p> <p> Vertical Text </p> </div> CSS .v-rl { writing - mode : vertical - rl; } Left to Right Vertical Text Left to Right Vertical Text HTML <div class= "v-lr" > <p> Left to Right </p> <p> Vertical Text </p> </div> CSS .v-lr { writing - mode : vertical - lr; } All Characters Upright All Characters Upright Ultraman ウルトラマン HTML <div class= "t-upright" > <p> All Characters </p> <p> Upright </p> <p> Ultraman ウルトラマン </p> </div> CSS .t-upright { writing - mode : vertical - rl; text - orie...

Distortion Glitch Text Effect - CSS

  Use multiple text-shadow properly in CSS on a text by comma separating the values. DEMO Distortion CSS h2 { color : darkorange ; font-family : sans-serif ; font-size : 3.5em ; text-transform : uppercase ; text-shadow : -3px -3px 0 cyan , 3px 3px 0 pink ; }