【问题标题】:Input text color differs from idle color输入文本颜色与空闲颜色不同
【发布时间】:2019-03-23 16:58:48
【问题描述】:

好的,所以,我会尽力解释这一点......

我正在设计联系公式的样式。

我已将输入焦点文本设置为白色。

但是当我点击离开我的表单时,输入的文本颜色变为黑色。

我的问题是,当我点击我的表单时如何设置输入文本颜色的样式?

示例如下:

* {
  background: red;
}

.contact-formula {
  height: auto;
  width: 100%;
  padding-left: 32.5%;
}

input {
  width: 50%;
  height: 5vh;
  display: block;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
}

input[type=submit] {
  width: 20%;
  margin-top: 2.5vh;
  text-align: center;
  background: orange;
  color: white;
  font-size: 2.5vh;
  cursor: pointer;
}

textarea {
  width: 50%;
  background: transparent;
  border: none;
  border-bottom: .25vh solid orange;
  resize: none;
  height: 15vh;
}

label {
  color: white;
  font-size: 2.5vh;
}

::placeholder {
  font-size: 3vh;
  color: white;
  text-transform: uppercase;
}

textarea:focus,
input:focus {
  color: white;
  font-size: 3vh;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}
<div class="contact-formula">
  <form name="htmlform" method="post" action="html_form_send.php">
    <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
    <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
    <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
    <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
    <input type="submit" value="Submit">
  </form>
</div>

我希望有人能指出我正在忽略/遗漏的内容。

提前致谢!

【问题讨论】:

    标签: html css contact-form


    【解决方案1】:

    这是因为您使用的是:focus 伪类。 如果你删除:focus,那么它会正常工作。

    * {
      background: red;
    }
    
    .contact-formula {
      height: auto;
      width: 100%;
      padding-left: 32.5%;
    }
    
    input {
      width: 50%;
      height: 5vh;
      display: block;
      background: transparent;
      border: none;
      border-bottom: .25vh solid orange;
    }
    
    input[type=submit] {
      width: 20%;
      margin-top: 2.5vh;
      text-align: center;
      background: orange;
      color: white;
      font-size: 2.5vh;
      cursor: pointer;
    }
    
    textarea {
      width: 50%;
      background: transparent;
      border: none;
      border-bottom: .25vh solid orange;
      resize: none;
      height: 15vh;
    }
    
    label {
      color: white;
      font-size: 2.5vh;
    }
    
    ::placeholder {
      font-size: 3vh;
      color: white;
      text-transform: uppercase;
    }
    
    textarea,
    input {
      color: white;
      font-size: 3vh;
    }
    
    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
      outline: none;
    }
    <div class="contact-formula">
      <form name="htmlform" method="post" action="html_form_send.php">
        <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
        <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
        <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
        <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
        <input type="submit" value="Submit">
      </form>
    </div>

    【讨论】:

    • 你是对的!尽管如此,当我点击离开时,字体大小仍然会发生变化。我错过了什么?
    • @treadwell 嗯,这很奇怪。它对我来说没有改变......我也没有看到代码有任何问题......只要 font-size 规则与 placeholder 类相同,应该没问题。跨度>
    • 我认为是因为我没有将输入定义为输入[type=text],这似乎解决了它!但是无论如何感谢您的帮助,我真的很感激! :)
    【解决方案2】:

    你应该删除 textarea, input 上的 :focus

    * {
      background: red;
    }
    
    .contact-formula {
      height: auto;
      width: 100%;
      padding-left: 32.5%;
    }
    
    input {
      width: 50%;
      height: 5vh;
      display: block;
      background: transparent;
      border: none;
      border-bottom: .25vh solid orange;
    }
    
    input[type=submit] {
      width: 20%;
      margin-top: 2.5vh;
      text-align: center;
      background: orange;
      color: white;
      font-size: 2.5vh;
      cursor: pointer;
    }
    
    textarea {
      width: 50%;
      background: transparent;
      border: none;
      border-bottom: .25vh solid orange;
      resize: none;
      height: 15vh;
    }
    
    label {
      color: white;
      font-size: 2.5vh;
    }
    
    ::placeholder {
      font-size: 3vh;
      color: white;
      text-transform: uppercase;
    }
    
    textarea,
    input {
      color: white;
      font-size: 3vh;
    }
    
    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
      outline: none;
    }
    <div class="contact-formula">
      <form name="htmlform" method="post" action="html_form_send.php">
        <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
        <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
        <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
        <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
        <input type="submit" value="Submit">
      </form>
    </div>

    【讨论】:

      【解决方案3】:

      您只需添加input[type=text] {color: white;}

      * {
        background: red;
      }
      
      .contact-formula {
        height: auto;
        width: 100%;
        padding-left: 32.5%;
      }
      
      input {
        width: 50%;
        height: 5vh;
        display: block;
        background: transparent;
        border: none;
        border-bottom: .25vh solid orange;
      }
      
      input[type=text] {
        color: white;
        font-size: 3vh;
      }
      
      input[type=submit] {
        width: 20%;
        margin-top: 2.5vh;
        text-align: center;
        background: orange;
        font-size: 2.5vh;
        cursor: pointer;
      }
      
      textarea {
        width: 50%;
        background: transparent;
        border: none;
        border-bottom: .25vh solid orange;
        resize: none;
        height: 15vh;
      }
      
      label {
        color: white;
        font-size: 2.5vh;
      }
      
      ::placeholder {
        font-size: 3vh;
        color: white;
        text-transform: uppercase;
      }
      
      
      input:focus,
      select:focus,
      textarea:focus,
      button:focus {
        outline: none;
      }
      <div class="contact-formula">
        <form name="htmlform" method="post" action="html_form_send.php">
          <input type="text" name="first_name" maxlength="50" size="30" placeholder="First Name" autofocus><br>
          <input type="text" name="last_name" maxlength="50" size="30" placeholder="Last Name"><br>
          <input type="text" name="email" maxlength="80" size="30" placeholder="email"><br>
          <textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message"></textarea><br>
          <input type="submit" value="Submit">
        </form>
      </div>

      【讨论】:

      • 字体大小也会随着焦点的变化而改变。
      • 啊,我错过了那个哈哈。我将如何让字体大小保持不变?
      • 只需将这些样式添加到输入中,而不是 input:focus
      • @ksav 感谢您的帮助,我接受了您的分析器作为解决方案。另外,你知道如何增加textarea输入文本的字体大小吗?
      • 寻找textarea并添加font-size: 3vh
      猜你喜欢
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多