Changing the border color in a CSS pseudo-class does not take effect upon clicking

Is it possible to change the border color of an input field when clicked using CSS? I attempted to use the pseudo-class focus for this purpose, but encountered some issues. It seems to only work on select elements and not on elements like text inputs.

.input-field {
  height: 3em;
  width: 80%;
  padding: .3rem 2rem;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--input-field-color);
  border-radius: 5px;
}

.input-group-append {
  margin-left: -40px !important;
}

.input-group-text {
  background: transparent !important;
  border: 0px !important;
}

.signUpButton {
  height: 3em;
  width: 80%;
  border-radius: 50px;
  outline: none;
  background: linear-gradient(90deg, #EC008C 0%, #FC6767 100%);
  border: 0;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.input-field:focus {
  border-color: var(--input-field-focus-color) !important;
  transition: border-color .20s ease-in;
}

.input-field:active {
  border-color: var(--input-field-focus-color) !important;
  transition: border-color .20s ease-in;
}
<form>
  <div class="form-header">
    <input type="text" class="input-field" placeholder="john">
  </div>
  <div class="form-header">
    <input type="text" class="input-field" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e2e1e0c3e6fbe2eef3efe6ade0ecee">[email protected]</a>">
  </div>
  <div class="form-header">
    <select class="input-field" name="gender">
      <option value="male"> Male</option>
      <option value="female"> Female</option>
    </select>
  </div>
  <div class="form-header">
    <select name="country" class="input-field">
      <option> India </option>
    </select>
  </div>
  <div class="form-header">
    <div class="input-group">
      <input type="password" class="input-field" placeholder="#########" />
      <div class="input-group-append">
        <span class="input-group-text"> <i class="fas fa-lock"> </i> </span>
      </div>
    </div>
  </div>
  <div class="form-header">
    <input type="submit" class="signUpButton" name="submit" />
  </div>

</form>

Answer №1

Enhance your CSS with some vibrant colors using variables

  --input-field-color:#ccc;
  --input-field-focus-color:#00cc00;

Have a look at this example below:

body{
  --input-field-color:#ccc;
  --input-field-focus-color:#00cc00;
}
.input-field {
  height: 3em;
  width: 80%;
  padding: .3rem 2rem;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--input-field-color);
  border-radius: 5px;
}

.input-group-append {
  margin-left: -40px !important;
}

.input-group-text {
  background: transparent !important;
  border: 0px !important;
}

.signUpButton {
  height: 3em;
  width: 80%;
  border-radius: 50px;
  outline: none;
  background: linear-gradient(90deg, #EC008C 0%, #FC6767 100%);
  border: 0;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.input-field:focus,.input-field:active{
  border-color: var(--input-field-focus-color) !important;
  transition: border-color .20s ease-in;
}
<form>
  <div class="form-header">
    <input type="text" class="input-field" placeholder="john">
  </div>
  <div class="form-header">
    <input type="text" class="input-field" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e0e3e2c1e4f9e0ecf1ede4afe2eeec">[email protected]</a>">
  </div>
  <div class="form-header">
    <select class="input-field" name="gender">
      <option value="male"> Male</option>
      <option value="female"> Female</option>
    </select>
  </div>
  <div class="form-header">
    <select name="country" class="input-field">
      <option> India </option>
    </select>
  </div>
  <div class="form-header">
    <div class="input-group">
      <input type="password" class="input-field" placeholder="#########" />
      <div class="input-group-append">
        <span class="input-group-text"> <i class="fas fa-lock"> </i> </span>
      </div>
    </div>
  </div>
  <div class="form-header">
    <input type="submit" class="signUpButton" name="submit" />
  </div>

</form>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP login system that retrieves information from a selected database

Currently, I am in the process of creating a login system using PHP, but I have encountered an error: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/a9356103/public_html/login.php on line 13 The code sni ...

CSS styling for a container element that enables word wrapping on child divs, while also being able to stretch to accommodate the width of its children

Is it feasible to create CSS that allows an element to support word-wrap:break-word, while also adjusting its width to fit the content when breaking is not possible? <html> <style> .outer { background-color:red; word-wrap:break-wor ...

Arranging Content with Bootstrap Columns

I am trying to organize my content into three sections as follows: A - main content of page B - very important content (must be visible without scrolling) C - less important content. The current layout I have is like this: ----- |A|B| |A|C| ----- Howe ...

Social Engine is incapable of analyzing the HTML code

Currently working on a website using Social Engine 4.8.9 version that is still in development mode. Upon inspecting the html code with the chrome inspector, I find it incredibly complex to decipher. For instance, when I click on the login page link http:// ...

When the Chrome Dev Tools are activated, the responsive website malfunctions

As I work on designing a responsive website, I've encountered an issue with media queries. When I set the breakpoint to min-width: 320px in Chrome dev tools, all of my CSS styles disappear. The same problem occurs when I zoom the window size to 150%, ...

Guide on implementing CSS modules in a WordPress plugin built with React

Within one of my tsx files, I included this line: import styles from "../../styles/buyTicket.module.css"; This resulted in the following error message: ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/ ...

How to position a textarea alongside a checkbox using CSS with Bootstrap

I'm having an issue aligning a text area next to a checkbox in my Bootstrap HTML. Here's the code snippet: <div class="form-group row"> <div class="col-12 form-check"> <label class="col-3 col-form-label" for="check15"& ...

Is there a way to align two links side by side, with one on the left and the other on the right?

<a href="example"><p style="text-align:left">Previous Page</a> <a href="example"><p style="text-align:right">Next Page</a> I am trying to figure out how to align these links on the same line. Any suggestions would be a ...

PHP search function malfunctioning

I'm feeling quite confused about the current situation. I am utilizing a form that requires a student code input of "lz." <form action="classgrades.php?id=<?php echo $courseid ?>" method="post"> <input type="text" name="studen ...

What is the process for choosing an element, wrapping it in a <div>, and appending a class to it using only JavaScript?

When constructing a responsive website, all CMS entries are in markdown. It's not feasible to manually code the div into each new entry, so dynamic class addition is necessary. The task at hand involves selecting an <img> within a post and wrap ...

Struggling to fix the excess white space appearing underneath my website

I am new to HTML/CSS and I'm currently working on adding a timeline to my website. However, I've encountered a strange issue with the #timeline class where there is an odd block of space below it whenever I try to adjust the height. So far, I ha ...

Utilize Tailwind CSS to design a triangular shape positioned in the lower right corner of the parent div

Is there a way to position a triangle in the bottom right corner of a parent div without it extending beyond the boundaries? I attempted to use tailwind css for this, but the sides of the triangle are crossing over the parent div. Any suggestions on how to ...

Comparison of the "Proposed Recommendation" versus the "Candidate Recommendation"

In a recent piece about HTML5, it was mentioned that the Proposed Recommendation date is set for 2022, while the Candidate Recommendation date is from 2012. I'm curious to understand the distinction between the "Proposed Recommendation" and the "Cand ...

Identifying CSS div tags in CakePHP with unique class names

After running cake bake, a test installation was created resulting in the Product Controller and its associated views such as index.cpt, add.cpt, edit.ctp, etc. Upon inspecting the CSS file linked to these views, I noticed two specific divisions: action an ...

What is the best way to choose just one value from an option that includes two variables?

I have a list of properties with numbers and names displayed in my form options. <b-col md="3"> <b-form-group :label="$t('departmentNumber')"> <b-form-select vuelidate v-model="$v.consumptionCon ...

Troubleshooting: Django project not functioning properly post transfer from Windows to Mac

Using Django 3.1.7 on a MacBook Pro now, I recently moved the Django project from a Windows 10 machine. Despite setting up the database and superuser again, running pipenv sync didn't result in serving any of my URLs or Admin page CSS styles. The serv ...

Efficient page navigation bar that doesn't clutter the layout

I'm facing an issue with my navbar setup. I want it to stay at the top of the page without being sticky. However, the presence of the navbar is causing a scroll to appear on my page. This happens because: The navbar takes up space I sometimes use tri ...

Unable to trigger a click on the submit button using JavaScript

I'm encountering difficulties in triggering a click using JavaScript on a Mailchimp pop-up subscribe form and I require your assistance. <!-- Title & Description - Holds HTML from CK editor --> <div class="content__titleDescripti ...

Substitute using JQuery

Hello, I am attempting to update some html using Jquery, here is my current progress. $(".old").html($(".new").html()); It's almost working. The problem is that the .new content is being copied instead of replaced. I want to Cut/Paste instead of Co ...

Tips for securely encrypting a PHP file when combining it with an HTML file using the phpB

I am attempting to encrypt a .php file using phpBolt. It works fine when the file contains only PHP code, but it fails when there is a mixture of HTML and PHP. Here is the encryption code: <?php /** * src : source folder * encrypted : Output folde ...