problem using with valid/invalid pseudoclass - html

I am trying to make a form using HTML and CSS only. The problem is i am using valid pseudo-class to just give animation, but when it is invalid it mixes up with the label. the code will be at https://codepen.io/hardik-g1/pen/mdVzMyL and if you don't get please try this type number in name field you will see the problem.
code:
<div id="fle">
<div class="container">
<h2 id="aa">HACKATHON REGISTRATION</h2>
<form action="">
<div class="group">
<input type="text" value="" pattern="[a-zA-z]+" required title="No numbers or special characters allowed">
<label class="set">First Name</label>
</div>
<div class="group">
<input type="text" value="" pattern="[a-zA-z]+" required title="No numbers or special characters allowed">
<label class="set">Last Name</label></p>
</div>
<div class="group">
<input type="email" value="" required>
<label class="set">Email</label>
</div>
<div class="group">
<input type="number" value="" required pattern="[0-9].{10}" title="Enter correct mobile number">
<label class="set">Mobile number</label>
</div>
<div class="group">
<p>Branch</p>
<select name="branch" id="" required><option value=" ">Please select your branch</option><option value="cs">Computer Science</option>
<option value="it">Information Technology</option>
</select>
</div>
<div class="group"><p>Do you have participated before?</p>
Yes<input id="a" type="radio" name="hosting" value="yes">
No<input type="radio" id="a" name="hosting" value="no">
</div>
<div class="group" id="c">
<p>Project Description</p>
<textarea name="comment" placeholder="Write Here" rows="4" cols="40" required></textarea>
</div>
<input id="b" type="checkbox" id="Agree" name="agree" value="yes" required> Click here to agree to all the information above is true.
<p><button class="button" type="submit"><span>Register</span></button></p>
</form>
</div>
<div>
<video id="video" width="860" onclick="play();">
<source type="video/webm" src="https://res.cloudinary.com/iatneh/video/upload/v1594920650/Virtual_Hackathon_copy_-_Biteable_kmyhcp.mp4"/>
</video>
<h1>Click on it to play</h1>
<p>All validations show when submitted</p>
</div>
</div>
CSS
#fle{
display:flex;
}
body{
color:#999;
}
#aa{
color:black;
}
#b{
width: 12.5px;
margin:0;
}
#c{
margin:10px 0;
}
#a{
width:30px;
color:#999;
}
select{
width: 300px;
height: 30px;
}
.container {
font-family:'Roboto';
width:600px;
background:#FFF;
padding:10px 50px 50px;
}
.group {
position:relative;
margin-bottom:30px;
}
input {
font-size:18px;
padding:10px 10px 10px 5px;
width:300px;
border:none;
border-bottom:1px solid #757575;
}
input:focus{ outline:none; }
label {
color:#999;
font-size:18px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:10px;
transition:0.2s ease all;
}
input:focus ~ label, input:valid ~ label {
top:-20px;
font-size:14px;
color:#5264AE;
}
input:invalid ~ label{
opacity:0.4;
}
.button {
border-radius: 4px;
background-color: #f4511e;
border:None;
color: #FFFFFF;
text-align: center;
font-size: 14px;
padding: 10px;
width: 100px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}

You can listen to input changes and if it has a value inside add a class to keep the label floating.
Here is a sample you can modify and use it in your code (it will keep the .floating class on label as long has the input has content in it):
function checkForInput(element) {
const $label = $(element).siblings('label');
if ($(element).val().length > 0) {
$label.addClass('floating');
} else {
$label.removeClass('floating');
}
}
$('input.input').on('change keyup', function() {
checkForInput(this);
});
label.floating {
color:#5264AE;
/* use styles for floating your labels here */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<input type="text" name="some-name" class="input" />
<label class="input-label" for="textdemo">label</label>
</div>

Related

How to style a checkbox after it is checked?

react.js
<div className='check'>
<input
type='checkbox'
className='checkbox'
id='termschkbx'
// style={{backgroundColor: "#DE1F48", color: "#30333F"}}
checked={this.state.isChecked}
// onClick={this.isClicked}
onChange= {this.isChecked}
>
</input>
<span>I agree to Terms & Conditions.<a href="" className='readme'>Read here</a> </span>
</div>
style.css
.checkbox{
top: -2px;
left:-45px;
width: 21px;
height: 21px;
opacity: 1;
display: inline-block;
margin-left:12px;
position: absolute;
}
.checkbox::after{
background: #DE1F48;
color: #30333F;
}
.checkbox:checked{
background: #DE1F48;
color: #30333F;
}
.checkbox input[type=checkbox]:checked {
background: #DE1F48;
color: #30333F;
}
nothing reflects on my checkbox after it is clicked. what can be done?
I even tried inline styling. That didn't work as well.
i did research about this, there were a lot of similar questions about this but nothing worked for me. I'm a new coder so excuseme if this is silly
Use input[type="checkbox"]:checked. This selects checkboxes that are checked.
Here's how to use it:
If the snippet is unavailable, use this JSFiddle link.
input[type=checkbox] {
height:0px;
width:0px;
}
input[type=checkbox]::after {
height:12px;
width:12px;
content:"\00a0\00a0\00a0\00a0";
border:1px solid black;
}
/* The magic below */
input[type=checkbox]:checked::after {
height:12px;
width:12px;
background-color:cyan;
content:"✓";
border:1px solid black;
}
<input type="checkbox" id="first" />
<label for="first" id="first">Here! A Checkbox!</label>
It also works for radio buttons:
input[type="radio"] {
width:0px;
height:0px;
}
input[type="radio"]::after {
content:"\00a0\00a0\00a0\00a0";
border-radius:5px;
height:10px;
width:10px;
position:absolute;
border:1px solid black;
display:inline;
}
input[type="radio"]:checked::after {
content:"✓";
background-color:#00ffff;
}
<div>
<input type="radio" name="radio" id="one" />
<label for="one">Option 1</label>
</div>
<hr>
<div>
<input type="radio" name="radio" id="two" />
<label for="two">Option 2</label>
</div>
<hr>
<div>
<input type="radio" name="radio" id="three" />
<label for="three">Option 3</label>
</div>

HTML buttons not appearing/elements stacked on each others

I followed a tutorial for a form(to make it look more professional) and I've followed each and every step carefully(I f#cked up something tho, I can't find it) and now all of my "fields" are stacked on each other. I have a php page that I make a form on and then if all the info is filled in and the user presses the "submit" button then it should send it to my and their email. It worked but when I started to follow this tutorial/guide the button disappeared, when I tried to find it on the page I couldn't see it/click it or anything. With some tricks I could see the outline of the button but not the actual button(there is a function in opera and I think many other browsers that while browsing through the elements on the page if you click on one of them in the source it highlights it on the page). The following is the source code, the only thing I want is the button to appear under the text fields and the text fields not to be stacked on top of each other, I'll only be including the html and not the php code for the smtp.
<!DOCTYPE html>
<html>
<head>
<title>Enroll</title>
<link rel="icon" href="mail.png">
</head>
<style>
body{
background-color: white;
font-family: sans-serif;
justify-content:space-around;
align-items:center;
flex-direction:column;
height:100%;;
}
.form{
overflow:hidden;
width:75%;
position:absolute;
left:10%;
transition: all 0.3 ease;
height:50px;
}
.form label{
position:absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 100%;
pointer-events: none;
border-bottom: 1px solid black;
transition: 0.3 ease;
}
.form label::after{
content: "";
position:absolute;
left:0px;
buttom:0px;
height:100%;
width:100%;
border-bottom: 3px solid #5fa8d3;
transform translateX(-100%);
}
.button{
width:400px;
height:30px;
background-color:blue;
}
.form input{
width:100%;
height:100%;
color: #595f6e;
padding-top: 20px;
border: none;
transition: 0.3s ease;
}
.content-name {
position:absolute;
bottom:5px;
left:0px;
transition: all 0.3 ease;
}
.form input:focus + .label-name .content-name,
.form input:valid + .label-name .content-name {
transform: translateY(-150%);
font-size: 14px;
color: #5fa8d3;
}
.form input:focus{
}
</style>
<body>
<div align="center">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form class="form" action="" method="post">
<input type="text" name="email" required />
<label for="email" class="label-name">
<span class="content-name">Email</span>
</label>
<br>
<input type="text" name="first_name" required />
<label for="first_name" class="label-name">
<span class="content-name">First Name</span>
</label>
<br>
<input type="text" name="last_name">
<label for="last_name" class="label-name">
<span class="content-name">Last Name</span>
</label>
<br>
<br>
<input style="color:blue;" onClick="return empty()" type="submit" name="submit" value="Submit"></br>
</form>
</div>
</body>
</html>
They are all stacking because you use position:absolute on <label> without proper parent reference on where they should be positioned. Try wrapping them with <div> like the example below, and add position:relative to that div
<!DOCTYPE html>
<html>
<head>
<title>Enroll</title>
<link rel="icon" href="mail.png">
</head>
<style>
body{
background-color: white;
font-family: sans-serif;
justify-content:space-around;
align-items:center;
flex-direction:column;
height:100%;;
}
.form{
overflow:hidden;
width:75%;
position:absolute;
left:10%;
transition: all 0.3 ease;
height:50px;
display: flex;
}
.form .field {
position: relative;
}
.form label{
position:absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 100%;
pointer-events: none;
border-bottom: 1px solid black;
transition: 0.3 ease;
}
.form label::after{
content: "";
position:absolute;
left:0px;
buttom:0px;
height:100%;
width:100%;
border-bottom: 3px solid #5fa8d3;
transform translateX(-100%);
}
.button{
width:400px;
height:30px;
background-color:blue;
}
.form input{
width:100%;
height:100%;
color: #595f6e;
padding-top: 20px;
border: none;
transition: 0.3s ease;
}
.content-name {
position:absolute;
bottom:5px;
left:0px;
transition: all 0.3 ease;
}
.form input:focus + .label-name .content-name,
.form input:valid + .label-name .content-name {
transform: translateY(-150%);
font-size: 14px;
color: #5fa8d3;
}
.form input:focus{
}
</style>
<body>
<div align="center">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form class="form" action="" method="post">
<div class="field">
<input type="text" name="email" required />
<label for="email" class="label-name">
<span class="content-name">Email</span>
</label>
</div>
<br>
<div class="field">
<input type="text" name="first_name" required />
<label for="first_name" class="label-name">
<span class="content-name">First Name</span>
</label>
</div>
<br>
<div class="field">
<input type="text" name="last_name" />
<label for="last_name" class="label-name">
<span class="content-name">Last Name</span>
</label>
</div>
<br>
<br>
<input style="color:blue;" onClick="return empty()" type="submit" name="submit" value="Submit"></br>
</form>
</div>
</body>
</html>

Unwanted white space in html to the right of search bar

I am trying to make a search bar, with an anchor containing an icon. I'm trying to directly connect the two (button fixed to the right of searchbar) but there is white space not wanting to leave.
.search input [type="search"] {
margin-right: 0;
white-space: nowrap;
}
.search a {
padding: 5px;
border-top-right-radius: 7px;
border-bottom-right-radius: 7px;
margin-left: 0;
}
.search i {
padding: 5px;
}
<div class="search">
<form action="" method="post">
<b>Search by</b>
<input type="checkbox" value="">Male</input>
<input type="checkbox" value="">Female</input>
<input type="search" placeholder="Searchtext">
<i>placeholder</i>
</form>
</div>
The duplicate does apply to your question as inputs are inline-block.
One thing to consider is that your "search" and "button" could be considered a single element. You could group them as such and then apply a float to the elements.
.searchBox {
/*Floats will be relative to this*/
position: relative;
display: inline-block;
}
.searchBox input {
/*Float the input*/
float: left;
}
.search input[type="search"] {
margin-right: 0;
white-space: nowrap;
}
.search a {
padding: 5px;
border-top-right-radius: 7px;
border-bottom-right-radius: 7px;
margin-left: 0;
/*Purely to demonstrate*/
border: solid 1px black;
}
.search i {
padding: 5px;
}
<div class="search">
<form action="" method="post">
<b>Search by</b>
<input type="checkbox" value="" />Male
<input type="checkbox" value="" />Female
<div class="searchBox">
<input type="search" placeholder="Searchtext">
<i>placeholder</i>
</div>
</form>
</div>
You also have a couple of other issues with your code:
input is self closing and shouldn't have a closing tag, note Permitted Content in the docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
You have an unwanted space between input and [type="search"]. This would attempt to match an element with an attribute of search that is a descendant of an input element.
I have addressed these in my code.
I think below code might serve your purpose.
.blockTitle{
padding-right:1em;
font-weight:bold;
}
.search{
display:block;
width:auto;
}
.search form{
display:block;
width:100%;
margin:0;
padding:0;
}
.checkbox + label{
display:inline-block;
padding:0 0.25em;
line-height:1.4em;
}
.searchBoxContainer{
display:block;
width:80%;
position:relative;
padding:0.2em;
}
.searchBoxContainer input[type="search"]{
width:100%;
display:block;
position:relative;
z-index:0;
padding:0 2.5em 0 0;
line-height:inherit;
margin:0;
}
.searchCustomBtn{
position:absolute;
top:0.75em;
right:-2em;
z-index:1;
line-height: 1.5em;
}
<div class="search">
<form action="" method="post">
<span class="blockTitle">Search by</span>
<input type="checkbox" value="" class="checkbox" id="maleChkBx" /><label for="maleChkBx">Male</label>
<input type="checkbox" value="" class="checkbox" id="femaleChkBx" /><label for="femaleChkBx">Female</label>
<div class="searchBoxContainer">
<input type="search" id="searchBox" placeholder="Searchtext">
Search-Icon
</div>
</form>
</div>

Input field change it's position while on focus

I am trying to create a form with material design. While not focus it looks good but when the field is focused, it's position towards left.
You can check the image for more details, and you can also see the distance between two field.
Here is HTML:
form.login-form {
display:block;
position:relative;
margin: 40px auto;
}
label{
display: inline-block;
position: relative;
top:0px;
left:-184px;
color:#999;
font-family:'Helvetica', sans-serif;
font-size:16px;
z-index:1;
transition: all 0.2s ease-in;
}
input{
display:inline-block;
position: relative;
background:none;
border:none;
border-bottom: 1px solid #aaa;
font-family: 'Helvetica', sans-serif;
font-weight: lighter;
font-size: 16px;
z-index:2;
}
input:focus , input:valid{
outline:none;
border-bottom: 1px solid #830303;
position: relative;
}
input:focus + label,input:valid + label{
top:-17px;
font-size:11px;
color:#830303;
background-position: 0 0;
}
<form action="#" method="" class="login-form">
<div class="loginformgrid">
<div>
<input type="text" name="username" required autocomplete="off">
<label for="username">Username</label>
<input type="password" name="password" required autocomplete="off" >
<label for="password">Password</label>
<button class="login-button" type="submit" value="submit">Login</button>
</div>
<div class="belowloginformgrid">
<div>
<input type="checkbox" name="remeberme"> Remember me
Forgot password?
</div>
</div>
</div>
</form>
edit your css code:
label {
position: absolute;
left: 0;
}
and add id : id="password" to label.
and add this css code:
#password{
left: 182px !important;
}
JSFiddle
The issue your having is due to the label resizing on focus. As you have the transition:all on label which applies it to all the properties and as your font size is getting smaller so the label takes in less space and hence the default inline spacing of your controls shrinks. Set the width of your label to a default size to fix it so that it does not change with the transition and remains the same for it to not shrink the space in between.
label{
display: inline-block;
position: relative;
top:0px;
left:-184px;
color:#999;
font-family:'Helvetica', sans-serif;
font-size:16px;
z-index:1;
transition: all 0.2s ease-in;
width:100px; /* Add this to keep it same when transitioning*/
}
I've rearranged the label and input, and added an additional span tag.
form.login-form {
display: block;
position: relative;
margin: 40px auto;
}
label {
display: inline-block;
position: relative;
}
label span {
color: #999;
display: block;
position: absolute;
font-family: 'Helvetica', sans-serif;
font-size: 16px;
z-index: 1;
margin-top: -1.5em;
transition: all 0.2s ease-in;}
input {
display: inline-block;
position: relative;
background: none;
border: none;
border-bottom: 1px solid #aaa;
font-family: 'Helvetica', sans-serif;
font-weight: lighter;
font-size: 16px;
z-index: 2;
}
input:focus,
input:valid {
outline: none;
border-bottom: 1px solid #830303;
}
input:focus+span,
input:valid+span {
margin-top: -3.5em;
font-size: 11px;
color: #830303;
background-position: 0 0;
}
<form action="#" method="" class="login-form">
<div class="loginformgrid">
<div>
<label for="username">
<input type="text" name="username" required autocomplete="off">
<span>Username</span>
</label>
<label for="password">
<input type="password" name="password" required autocomplete="off">
<span>Password</span>
</label>
<button class="login-button" type="submit" value="submit">Login</button>
</div>
<div class="belowloginformgrid">
<div>
<input type="checkbox" name="remeberme"> Remember me
Forgot password?
</div>
</div>
</div>
</form>

When I call another HTML page in a blank <div> it is shown in a small window instead of the full page

I have the home.html page where I have a menu. On clicking the link I want the addnew.html page to load into the part of the code. I get the page but it is shown in an small section.....
Home.html
<!DOCTYPE html>
<head>
<title>Contact Manager</title>
<link rel="stylesheet" type="text/css" href="Style1.css" />
<script>
function Load_addnew()
{
document.getElementById("load_here").innerHTML='<object type="text/html" data="Addnew.html"></object>'
}
</script>
</head>
<body>
<div id="main">
<div id="logo">
<h1><center>Contact Manager</center></h1>
</div>
<div id="menu">
<ul>
<li>ADD NEW CONTACT</li>
<li>EDIT A CONTACT</li>
<li>DELETE CONTACT</li>
<li>SEARCH CONTACTS</li>
<li>LIST OF CONTACTS</li>
</div>
<div id="load_here"></div>
</div>
</body>
</html>
Style1.css
#main
{
background-repeat: repeat;
}
#logo a, #menu a
{
text-decoration: none;
}
#menu ul
{
line-height: 1.5em;
font-size: x-large;
float: left;
list-style: none;
}
#load_here
{
}
#logo
{
background-color:
}
#menu
{
margin: 0px auto;
left: 0px;
right: 0px;
}
AddNew.html
<!DOCTYPE HTML>
<html>
<head>
<title>Add Contact</title>
<link rel="stylesheet" type="text/css" href="addnew.css"></link>
</head>
<body>
<div id="main">
<ul id="errors">
<li id="info">Please recheck your form and Submit again: </li>
</ul>
<p id="success">Details Saved Successfully!!</p>
<div id="form1">
<form action="" method="" id="add_new">
<label for="Fname">First Name <span class="required">*</span>:</label>
<input type="text" id="First_Name" name="FirstName" value="" pattern="[A-Z a-z]" required="required" autofocus="autofocus"/>
<label for="Mname">Middle Name :</label>
<input type="text" id="Middle_Name" name="MiddleName" pattern="[A-Z a-z]" value=""/>
<label for="Lname">Last Name <span class="required">*</span>:</label>
<input type="text" id="Last_Name" name="LastName" value="" pattern="[A-Z a-z]" required="required"/>
<label for="dob">Date of Birth <span class="required">*</span>:</label>
<input type="date" id="DOB" name="dob" value="" required="required"/>
<label for="Phone1">Phone 1 <span class="required">*</span>:</label>
<input type="text" id="contactHome" name="Phone1" value="" required="required"/>
<label for="Phone2">Phone 2:</label>
<input type="text" id="contactOffice" name="Phone2" value=""/>
<label for="email">Email <span class="required">*</span>:</label>
<input type="email" id="email" name="Email" value="" placeholder="username#example.com" required="required"/>
<label for="Address">Address Line 1 <span class="required">*</span>:</label>
<input type="text" id="address" name="Address" required="required"/>
<label for="Address">Address Line 2:</label>
<input type="text" id="address1" name="Address1"/>
<label for="city">City <span class="required">*</span>:</label>
<input id="city" name="City" required="required" value=""/>
<label for="state">State <span class="required">*</span>:</label>
<input id="state" name="State" required="required" value=""/>
<label for="country">Country<span class="required">*</span>:</label>
<input id="country" name="Country" required="required" value=""/>
<label for="zip">PIN<span class="required">*</span>:</label>
<input id="zip" name="Zip" required="required" value=""/>
<input type="Submit" value="Submit" id="submit-button"/>
<input type="Reset" value="Reset" id="reset_button"/>
<p id="required-desc"><span class="required">*</span> indicates a required field</p>
</form>
</div>
</div>
</body>
</html>
addnew.css
#main
{
width: 465px;
padding: 20px;
margin: 0px auto;
border: 6px solid #8fb5c1;
border-radius: 15px;
position: absolute;
background-repeat: repeat;
left: 0px;
right: 0px;
}
#main input, #main select, #main textarea, #main label
{
font-size: 15px;
margin-bottom: 2px;
}
#main input, #main select, #main textarea
{
width: 450px;
border: 1px solid #cee1e8;
margin-bottom: 20px;
padding: 4px;
}
#main input:focus, #main select:focus, #main textarea:focus
{
border: 1px solid #afcdd8;
background-color: #ebf2f4;
}
#main textarea
{
height: 80px;
resize: none;
}
#main label
{
display: block;
}
#main .required
{
font-weight: bold;
color: #f00;
}
#main #submit-button, #main #reset_button
{
width: 100px;
background-color:#333;
color:#FFF;
border:none;
display:block;
float:right;
margin-bottom:0px;
margin-right:6px;
background-color:#8FB5C1;
}
#main #submit-button:hover, #main #reset_button :hover
{
background-color: #A6CFDD;
}
#main #submit-button:active, #main #reset_button:active
{
position:relative;
top:1px;
}
#main #loading
{
width:32px;
height:32px;
display:block;
position:absolute;
right:130px;
bottom:16px;
display:none;
}
#errors
{
border: solid 1px #e58e8e;
padding: 10px;
margin: block;
width: 437px;
border-radius: 8px;
background: #ffe6e6 no-repeat 405px center;
display: none;
}
#errors li
{
padding: 2px;
list-style: none;
}
#errors li:before
{
content: '-';
}
#errors #info
{
font-weight: bold;
}
#errors #info:before
{
content: '';
}
#success
{
border: solid 1px #83d186;
padding: 25px 10px;
margin: 25px 0px;
display: block;
width: 437px;
border-radius: 8px;
background: #d3edd3 no-repeat 405px center;
font-weight: bold;
display: none;
}
#errors.visible, #success.visible
{
display: block;
}
#form1 #req-field-desc
{
font-style: italic;
}
Easy enough if you set a width and height.
#load_here object
{
width: 100%;
height: 500px;
}
The problem you'll run into is that there is proportional sizing for this. You'd have to specify both a width and a height, or it will default width: 300px; and height: 150px;. So, if you set width: 100%; but don't set height, it'll render the height at 150px, and vice versa.
I hope this helps. ^^