How can I replicate Firefox's behavior for HTML5 validation in Chrome by displaying red borders around required or invalid input elements?

Is there a way to add red borders around the input element in Chrome for HTML5 validation similar to Firefox?

I've been searching extensively but have yet to find a definitive answer. Any guidance on how to achieve this using CSS would be highly appreciated.

Thank you.

Answer №1

The :valid pseudo-class is what you should be using.

If you want to borrow some code, head to https://developer.mozilla.org/en-US/docs/Web/CSS/:valid:

input:invalid {
  background-color: #ffdddd;
}
form:invalid {
  border: 5px solid #ffdddd;
}
input:valid {
  background-color: #ddffdd;
}
form:valid {
  border: 5px solid #ddffdd;
}
input:required {
  border-color: #800000;
  border-width: 3px;
}
<form>
  <label>Please input a URL:</label>
  <input type="url" />
  <br />
  <br />
  <label>Enter your email address:</label>
  <input type="email" required/>
</form>

Answer №2

Consider including the 'required' attribute within the DOM element

<input name="title" type="text" class="form-control" placeholder="title" maxlength="35" required />

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

CSS: Inject Text at the End of Input Text's Value

Hey there, I'm facing a minor issue. The user wants to add some funny text to an input field if a specific condition is met. For example: Normal Condition: the input field shows "#{model.user}" Abnormal condition: the input field should display "# ...

Utilizing Cookies in PHP to keep track of site visits

I'm a newbie to PHP and struggling with using Cookies! My goal is to create a cookie that tracks the number of times a page is loaded within a one-minute lifetime. Once the minute is up, the cookie should be unset and the counter reset to 0. Here&apo ...

What could be the reason for CSS3 PIE failing to work on sub pages when an absolute path is used in the CSS file?

I am struggling with CSS styling and have created the following class: a.greenbutton, input.greenbutton { /*background: url("../image/button.png") repeat-x scroll left top transparent;*/ behavior: url("/css3pie/PIE.php"); -webkit-border-radiu ...

The image slider script I've built is functioning perfectly in Codepen, but unfortunately, it's not working as

My image slider called Orbit is functioning properly on Codepen.io, however when I try to run the exact same code on Plunker, it doesn't work at all. <ul class="slider" data-orbit> <li> <img src="http://foundation.zurb.com/docs/a ...

Executing numerous xhttp.send requests within a single webpage

Hey there, I'm facing an issue with xhttp.send(); as it keeps giving me the error message net::ERR_EMPTY_RESPONSE Here is a snippet of my code. Whenever a user clicks too quickly, they get kicked off the page. Is there a way to prevent this? docum ...

Issue with HTML Form Data Not Being Reflected in SQL Database

After creating a form to insert values into the database, there seems to be an issue where the database is not being updated despite no errors. Here is the HTML code for the page: <!DOCTYPE html> <html> <title>css</title> <body ...

The Bootstrap carousel controls now add the carousel ID to the address bar instead of just moving to the next slide

I can't figure out why my carousel isn't working. The id of the carousel is showing up in the webpage's address, which usually happens when the 'bootstrap.js' file is missing, but I have included it. Can anyone help me troubleshoo ...

Creating head tags that are less bouncy

After running my code, I noticed that the headlines didn't transition smoothly - they seemed to jump rather than flow seamlessly. To address this issue, I attempted to incorporate fadeIn and fadeOut functions which did improve the smoothness slightly. ...

Struggling to achieve a fluid design with bootstrap framework

Check out my website live at the following URL, but please note that I am using the latest version of bootstrap. All CSS styles are included in 'master.css'. The issue I am facing is that elements like this box or any other (as you will see when ...

Ensure that the tables are HTML5 compliant by setting the cellpadding attribute for only specific tables, without

Perhaps I'm being a bit fussy. I'm looking to add cell padding to certain tables but not others, without having to manually edit each individual td element. I prefer to keep it HTML5 compliant, which means avoiding the cellpadding property of the ...

Tips for avoiding image overlap in a multi-carousel display

I am facing an issue with a bootstrap4 multi-carousel where the images are overlapping each other, taking up the entire screen width one by one. My implementation includes HTML, CSS, and JS files. <div class="row"> <div class="MultiCarous ...

Troubles with CSS drop down alignment in Internet Explorer 7

I've been racking my brain all morning trying to solve this issue. My current project involves creating a website for a client, and I'm having trouble getting the dropdown menu to position correctly in IE7. It's working fine in all other br ...

How do I send a jQuery table object to a web worker using Javascript?

I have an HTML table with various columns and rows that can be edited by users directly. Whenever a user makes changes to the table, I need to calculate certain sums on the rows of the table. Initially, the function responsible for calculating these sums ...

Developing an if-else statement to showcase a different div depending on the URL

Having trouble with an if/else statement to display one div or another based on the URL: No matter what I try, only "Div 1" keeps showing. Here's my code snippet: <script> if (window.location.href.indexOf("pink") > -1) { document.getElemen ...

Creating a dynamic webpage using Javascript that responds to user clicks on page links

I am interested in the process of inserting JavaScript objects from a JSON file in order to dynamically create a unique page based on a user's clicked link. This concept is similar to having a wildcard page in popular frameworks like Laravel or Django ...

What are the different ways to customize the indicator color of React Material UI Tabs using hex

Just got my hands on this amazing Material UI component <Tabs textColor="primary" indicatorColor="primary" > <Tab label="All Issues"/> </Tabs> The documentation states that indicatorColor and textColor can only be set to ' ...

Why is the official website for the Apache HTTP Server httpd.apache.org when HTTPd is actually a program that can be run?

After conducting thorough research, I discovered that HTTPd (HyperText Transfer Protocol daemon) is a software program that operates in the background of a web server. My amazement and confusion peaked when I came across the webpage 'httpd.apache.org ...

Configuring a specific chrome driver preference

Currently, I am facing the task of disabling the "Ask where to save each file before downloading" Chrome setting using selenium: It is proving to be a challenge as the list of available options on the documentation page seems to be incomplete. Additionall ...

Switching the WordPress dropdown menu from a hover function to a click function

Is it possible to modify the WordPress menu dropdown behavior from hover to onclick? I want the menu to appear when an item is clicked, but WordPress currently requires hovering. Below is what I've tried so far, but it has not been successful. Jquery ...

occupy the full width of the available screen space (from one end of the container to the other

Currently, I am utilizing the Flexbox enabled version of Bootstrap 4 Alpha 3. Check it out on Jsfiddle body { background-color: lightgreen; } [class^="col"] { background: gold; border: 1px solid tomato; } <link href="https://cask.scotch.io/boo ...