<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Advanced styling: Task 3</title>
</head>
<body>
<form>
<fieldset>
<legend>Feedback form</legend>
<p>Required fields are labelled with "required".</p>
<div>
<label for="fname">First name: </label>
<input id="fname" name="fname" type="text" required placeholder="Tom" minlength="2">
<span></span>
</div>
<div>
<label for="lname">Last name: </label>
<input id="lname" name="lname" type="text" required placeholder="Smith" minlength="2">
<span></span>
</div>
<div>
<label for="email">Email address: </label>
<input id="email" name="email" type="email" placeholder=" ">
<span></span>
</div>
<div><button>Submit</button></div>
</fieldset>
</form>
</body>
</html>
body {
background-color: #fff;
color: #333;
font: 1em / 1.4 Helvetica Neue, Helvetica, Arial, sans-serif;
padding: 1em;
margin: 0;
}
* {
box-sizing: border-box;
}
button,
input,
select {
font-family: inherit;
font-size: 100%;
padding: 0; margin: 0;
}
fieldset {
padding: 10px 30px 0;
width: 400px;
}
legend {
color: white;
background: black;
padding: 5px 10px;
}
fieldset > div {
margin-bottom: 20px;
display: flex;
flex-flow: row wrap;
}
button, label, input {
display: block;
font-family: inherit;
font-size: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
width: 100%;
padding: 5px;
height: 30px;
}
input {
box-shadow: inset 1px 1px 3px #ccc;
border-radius: 5px;
}
input:hover, input:focus {
background-color: #eee;
}
button {
width: 60%;
margin: 0 auto;
}
/* My code from here */
input + span {
position: relative;
}
input:required + span::after {
position: absolute;
font-size: 0.8rem;
border: 2px solid orange;
background-color: rgb(251, 198, 100);
border-radius: 5px;
color: black;
content: "required";
padding: 0.5px 5px;
top: -27px;
left: -62px;
}
input:invalid:not(:placeholder-shown)/*or :not(:blank) <- :blank is not supported by any browser yet*/ {
border: 2px solid red;
}
input:invalid:not(:placeholder-shown) + span::before {
position: absolute;
content: "✕";
color: red;
font-size: 0.8rem;
top: -22px;
left: -215px;
}
input:valid:not(:placeholder-shown) + span::before {
position: absolute;
content: "✓";
color: green;
font-size: 0.8rem;
top: -22px;
left: -215px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.