【问题标题】:How to make the CSS :focus work on my project?如何让 CSS :focus 在我的项目中发挥作用?
【发布时间】:2023-01-23 16:38:09
【问题描述】:

谁能帮我?当用户单击文本字段时,我尝试使用 :focus 在表单输入上添加边框颜色。但它不起作用。非常感谢任何帮助。谢谢!

form.customNewsletter-form {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: flex-start;
  margin: 0;
  padding: 0;
  gap: 16px;
}

form.customNewsletter-form input[type="text"] {
  font-family: "Roboto", sans-serif;
  font-size: 16px;
  font-weight: 300;
  color: #ffffff;
  background-color: #0d0d0d;
  border: 1px solid #404040;
  width: 70%;
  height: 48px;
  padding: 0 16px;
  letter-spacing: 0.8px;
  border-radius: 4px;
  margin: 0;
}

form.customNewsletter-form input[type="text"]:focus {
  border: 1px solid #cd0d0d;
}

form.customNewsletter-form input::placeholder {
  color: #8d8d8d;
}

form.customNewsletter-form input[type="submit"] {
  color: #ffffff;
  font-family: "Roboto Condensed", sans-serif;
  font-size: 16px;
  font-weight: 300;
  background-color: #cd0d0d;
  border: none;
  border-radius: 4px;
  height: 48px !important;
  width: 30%;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin: 0 auto !important;
  transition: 0.3s all ease;
}

form.customNewsletter-form input[type="submit"]:hover {
  background-color: #8e0000;
  color: #ffffff;
  -webkit-transform: scale(0.99);
  transform: scale(0.99) 0.5s ease-in;
}
<form class="customNewsletter-form" action="https://app.getresponse.com/add_subscriber.html" accept-charset="utf-8" method="post">
  <!-- Email field (required) -->
  <input type="text" name="email" placeholder="Enter your email">
  <!-- List token -->
  <!-- Get the token at: https://app.getresponse.com/campaign_list.html -->
  <input type="hidden" name="campaign_token" value="sample">
  <!-- Thank you page (optional) -->
  <input type="hidden" name="thankyou_url" value="https://www.website.com/thankyou">
  <!-- Add subscriber to the follow-up sequence with a specified day (optional) -->
  <input type="hidden" name="start_day" value="0">
  <!-- Subscriber button -->
  <input type="submit" value="Subscribe">
</form>

演示请看here

我希望输入字段的边框颜色在用户单击时变为红色。

【问题讨论】:

  • 问题出在哪儿?当输入聚焦时,边框颜色会发生变化.....
  • 它按预期工作

标签: css focus pseudo-class


【解决方案1】:

在你的CSS中添加这个

form.customNewsletter-form input:focus { 
    outline: none;
    border-color: #719ECE; 
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2019-09-10
    相关资源
    最近更新 更多