How to change background of a input textbox after focus? - html

Here, I am trying to change the background color of the input after I write something in the textbox. Whenever I focus, then it will change the background color to white and it will remain white for the rest of time.
<input type="text" class="
.contact-form input,
.contact-form textarea {
width: 100%;
height: 50px;
margin: 10px 0;
background-color: #353b48;
border: none;
outline: none;
padding: 20px;
border-radius: 4px;
color: #fff;
}
.contact-form input:focus {
width: 100%;
height: 50px;
margin: 10px 0;
background-color: #353b48;
border: none;
outline: none;
padding: 20px;
border-radius: 4px;
color: #fff;
background-color: white;
border: 2px solid;
border-color: #207398;
}
<input type="text" class="nameZone" name="name" placeholder="Your Full Name" style="color: black;">
<input type="email" class="emailZone" name="email" placeholder="Your Email" style="color: black;">
<input type="text" class="subjectZone" name="subject" placeholder="Subject" style="color: black;">
<textarea class="messageZone" name="message" placeholder="Message" style="color: black;"></textarea>

Remark: The top part of code is broken?
However, I've assumed you want to kept the gray-ish background while typing in data. I think you could use !important. The :focus part shall be redundant.
.contact-form input, .contact-form textarea {
background-color: #353b48 !important;
}
Snippet is the part of updated code. Btw, your inline css color:black has overrule the internal css color:white.
.contact-form input, .contact-form textarea {
width: 100%;
height: 50px;
margin: 10px 0;
background-color: #353b48 !important;
border: none;
outline: none;
padding: 20px;
border-radius: 4px;
color: #fff;
}
<div class="contact-form">
<input type="text" class="nameZone contact-form" name="name" placeholder="Your Full Name" style="color: black;">
<textarea class="messageZone" name="message" placeholder="Message" style="color: black;"></textarea>
</div>

Related

How to get rid of the black line on the border of the inputs and textarea [duplicate]

This question already has answers here:
How to remove the border highlight on an input text element
(21 answers)
Closed 7 months ago.
I have been struggling to get rid of this line when I click on a specific input. Here is an example:
HTML:
<form class="form appear appear-hidden" method="post">
<h1>Contact Me</h1>
<div class="name-section">
<input name="name" type="name" placeholder="Name" required />
<input name="name" type="surname" placeholder="Surname" required />
</div>
<input name="email" type="email" placeholder="Email" required />
<textarea
name = "message"
type="message"
placeholder="Message"
row="4"
required
></textarea>
<input class="submit" type="submit" placeholder="submit" />
</form>
CSS:
form input {
width: 98%;
margin: 5px;
border: 2px solid white;
padding: 10px;
/* background-color: #000; */
background-color: transparent;
font-weight: 600;
color: white;
font-family: 'Poppins', sans-serif;
}
form input:focus {
border: none;
}
textarea {
min-height: 100px;
background-color: transparent;
color: white;
font-family: 'Poppins', sans-serif;
width: 98%;
margin: 5px;
border: 2px solid white;
resize: none;
font-weight: 600;
padding: 10px;
}
I'm just looking for a solution that will help me to get rid of the black border when the input is focused on. This Black border doesn't appear when an input is not focused on.
Thanks in advance for the help.
form input {
width: 98%;
margin: 5px;
border: 2px solid white;
padding: 10px;
/* background-color: #000; */
background-color: transparent;
font-weight: 600;
color: white;
font-family: 'Poppins', sans-serif;
}
form input:focus {
border: none;
outline: none;
}
textarea {
min-height: 100px;
background-color: transparent;
color: white;
font-family: 'Poppins', sans-serif;
width: 98%;
margin: 5px;
border: 2px solid white;
resize: none;
font-weight: 600;
padding: 10px;
outline: none;
}
<form class="form appear appear-hidden" method="post">
<h1>Contact Me</h1>
<div class="name-section">
<input name="name" type="name" placeholder="Name" required />
<input name="name" type="surname" placeholder="Surname" required />
</div>
<input name="email" type="email" placeholder="Email" required />
<textarea name="message" type="message" placeholder="Message" row="4" required></textarea>
<input class="submit" type="submit" placeholder="submit" />
</form>
It is outline.
Just use outline:none.
form input:focus {
border: none;
outline:none;
}
textarea {
outline:none;
}

Why the textarea doesn't have the same font size with input text?

Can someone tell me why "message" which is a textarea has different font size than "full name" and "email" which are input, however they have the same class name? how can i make it have the same font size? thank you in advance!
body {
background: grey;
}
.form-control {
width: 40%;
padding: 10px;
margin: 10px;
border-radius: 1.5em;
font-size: 1.1em;
background-color: $white;
border: none;
color: black;
resize: none;
&:focus {
outline: 0;
}
}
button {
padding: .5em .75em;
margin: 10px;
font-size: 1.1em;
border-radius: 1.5em;
background-color: $white;
border: none;
outline: 0;
color: black;
&:hover {
color: $purple;
}
}
<form action="https://formspree.io/f/" method="POST">
<input
name="name"
type="text"
class="form-control"
placeholder="Full name"
required
/>
<br />
<input
name="_replyto"
type="email"
class="form-control"
placeholder="Email"
required
/>
<br />
<textarea name="message" class="form-control" placeholder="Message" rows="5" required></textarea>
<br />
<button type="submit">Send</button>
</form>
The font family is differnt make it same
add this
textarea{
font-family:'Tahoma';
}
body {
background: grey;
}
.form-control {
width: 40%;
padding: 10px;
margin: 10px;
border-radius: 1.5em;
font-size: 1.1em;
background-color: $white;
border: none;
color: black;
resize: none;
&:focus {
outline: 0;
}
}
button {
padding: .5em .75em;
margin: 10px;
font-size: 1.1em;
border-radius: 1.5em;
background-color: $white;
border: none;
outline: 0;
color: black;
&:hover {
color: $purple;
}
}
textarea{
font-family:'Tahoma';
}
<form action="https://formspree.io/f/" method="POST">
<input
name="name"
type="text"
class="form-control"
placeholder="Full name"
required
/>
<br />
<input
name="_replyto"
type="email"
class="form-control"
placeholder="Email"
required
/>
<br />
<textarea name="message" class="form-control" placeholder="Message" rows="5" required></textarea>
<br />
<button type="submit">Send</button>
</form>
You need to style the placeholder
body {
background: grey;
}
textarea::placeholder {
font-size: 1.1em;
}
.form-control {
width: 40%;
padding: 10px;
margin: 10px;
border-radius: 1.5em;
font-size: 1.1em;
background-color: $white;
border: none;
color: black;
resize: none;
&:focus {
outline: 0;
}
}
button {
padding: .5em .75em;
margin: 10px;
font-size: 1.1em;
border-radius: 1.5em;
background-color: $white;
border: none;
outline: 0;
color: black;
&:hover {
color: $purple;
}
}
<form action="https://formspree.io/f/" method="POST">
<input
name="name"
type="text"
class="form-control"
placeholder="Full name"
required
/>
<br />
<input
name="_replyto"
type="email"
class="form-control"
placeholder="Email"
required
/>
<br />
<textarea name="message" class="form-control" placeholder="Message" rows="5" required></textarea>
<br />
<button type="submit">Send</button>
</form>
the setting is for the whole form when you do .form-control{}
try setting the width of the text area separetly. Give it an id and a separate property/value from the form
Add the font family to the textarea
font-family:'Tahoma';
As explained by this answer, the default font-family for inputs and textareas are different in some browsers.
The trick is to define a font-family in .form-control.
.form-control {
font-family: Arial;
// Other styles
}
Or if you want to use the same font for body text and form controls.
body {
font-family: Arial;
}
.form-control {
font-family: inherit;
}
Note: inherit might give unexpected results if you defined another font-family in one of the parent elements.
To be absolutely sure, define the font-family in a (s)css variable and set it specifically.
$font-family-base: Arial;
body {
font-family: $font-family-base;
}
.form-control {
font-family: $font-family-base;
}
You need to set font-family or inherit it. Input and textarea have different font families in different browsers.
Set the font-family in the body and then inherit it in the class
body {
background: grey;
font-family:"Tahoma";
}
.form-control {
width: 40%;
padding: 10px;
margin: 10px;
border-radius: 1.5em;
font-size: 1.1em;
background-color: $white;
border: none;
color: black;
resize: none;
font-family: inherit;
&:focus {
outline: 0;
}
}
button {
padding: .5em .75em;
margin: 10px;
font-size: 1.1em;
border-radius: 1.5em;
background-color: $white;
border: none;
outline: 0;
color: black;
&:hover {
color: $purple;
}
}
<form action="https://formspree.io/f/" method="POST">
<input
name="name"
type="text"
class="form-control"
placeholder="Full name"
required
/>
<br />
<input
name="_replyto"
type="email"
class="form-control"
placeholder="Email"
required
/>
<br />
<textarea name="message" class="form-control" placeholder="Message" rows="5" required></textarea>
<br />
<button type="submit">Send</button>
</form>

How to move form to center of page

I am creating a registration form and am wondering how can I move the whole form to the center of the page? right now its all on the left side of the container, I want it to look a bit something like this: https://id2.s.nfl.com/fans/register?returnTo=http%3A%2F%2Fweeklypickem.fantasy.nfl.com%2F
#Regcontainer {
width: 1200px;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> </h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label>FIRST NAME</label>
<input type="text" name="FName" />
<label>LAST NAME</label>
<input type="text" name="SNAME" />
<br/>
<label>EMAIL ADDRESS</label> <input id="email" name="email" type="text" />
<BR/>
<label>CREATE YOUR USERNAME</label> <input name="uname" type="text" /> <br/>
<label>CREATE PASSWORD</label> <input name="pass" type="password" />
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Here is the solution I came up with... but what does it do?
#Registercontainer needs to be on the center of the page. Meaning, your fixed with of 1200px is not going to work too well. I took the approach of reducing the size of your from container to give a better look and feel like this:
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
/* ... your other properties here ... */
}
Another note, your <label> needs the for attribute as specified in this article.
Let me know if you have any questions, FYI there are many ways to make this work for you.
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
padding: 15px;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> Register With NackStack</h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label for="fname">FIRST NAME</label>
<input type="text" name="FName" id="fname" />
<br/>
<label for="sname">LAST NAME</label>
<input type="text" name="SNAME" id="sname" />
<br/>
<label for="email">EMAIL ADDRESS</label>
<input id="email" name="email" type="text" />
<br/>
<label for="uname">CREATE YOUR USERNAME</label>
<input name="uname" type="text" id="uname" />
<br/>
<label for="password">CREATE PASSWORD</label>
<input name="pass" type="password" id="password"/>
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Add margin:auto and a fixed width to the parent <div>. Example:
<div id="Registercontainer" style="margin-left:auto;margin-right:auto;width:250px">
Fiddle:
https://jsfiddle.net/mwatz122/g9ay26x3/
#Registercontainer {
text-align: center;
}
Please try this. It might help.
Put your form within a <div> like this:
<div align="center">
<!-- insert code here -->
</div>
Then in the CSS, add
form {
text-align: left;
}

CSS style wont apply in text input boxes

I am having trouble with applying a style in my input box.
I have header.css here
#charset "utf-8";
body, h1, h2, h3, h4, h5, h6, p, div, ul, li {
margin:0;
padding:0;
}
body { font family: Verdana; background-color: #FFFFFF }
#Wrapper {
width: auto;
height:2000px;
margin: 0 auto;
}
#divHeader {
position:0px;
width: 100%;
height: 180px;
background:url(thisheader/header_1.png)
}
#divHeader2 {
position: 180px;
width: 100%;
height: 200px;
background: url(thisheader/SMCFIbanner.png);
}
#box {
background: white;
border: 1px solid #DDD;
border-radius: 1px;
box-shadow: 0 0 3px #DDD inset;
color: #666;
padding: 5px 10px;
width: 185px;
outline: none;
}
when I try to apply the style to the textbox for the password and username using the header.css, it wont apply. I created a new css file just to check, yes.css:
input#box {
background: white;
border: 1px solid #DDD;
border-radius: 1px;
box-shadow: 0 0 3px #DDD inset;
color: #666;
padding: 5px 10px;
width: 165px;
outline: none;
}
log.php
<div>
<form method="post" action="checkLogin.php">
<label>Username</label>
<input type="text" value="" name="myusername" size="20%" class="input_field" title="username" id="box" />
<br>
<br>
<label>Password</label>
<input type="password" value="" name="mypassword" class="input_field" title="password" id="box" />
<br>
<br>
<input type="submit" name="login" value="Login" alt="login" id="submit_btn" title="Login" />
</form>
</div>
and when i try to link this one in my log.php, it worked.
what might be the problem ?
First off, you should not have multiple elements on page with the same id. In this case, both your login and password fields have an ID of "box". Use class instead. You may be better off doing:
<div id='box'>
<form method="post" action="checkLogin.php">
<label>Username</label>
<input type="text" value="" name="myusername" size="20%" class="input_field" title="username" />
<br>
<br>
<label>Password</label>
<input type="password" value="" name="mypassword" class="input_field" title="password"/>
<br>
<br>
<input type="submit" name="login" value="Login" alt="login" id="submit_btn" title="Login" />
</form>
</div>
Then, in the css, do
#box input[type='text']{
blah,blah,blah...
}
The problem could be that you have two elements with the same id.
By the way, you can select to apply the style to all input textfields with this selector.
form input[type=text] {
background: white;
border: 1px solid #DDD;
border-radius: 1px;
box-shadow: 0 0 3px #DDD inset;
color: #666;
padding: 5px 10px;
width: 165px;
outline: none;
}
Try styling the input box like this:
input[type=text] {
background: white;
border: 1px solid #DDD;
border-radius: 1px;
box-shadow: 0 0 3px #DDD inset;
color: #666;
padding: 5px 10px;
width: 185px;
outline: none;
}

Align checkbox and label

I have a form which code looks like this:
<div id="right_sidebar">
<form id="your_name" name="your_name" action="#" method="post" style="display: block; ">
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="">
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname">
<label for="msg">Comment <span class="sp"></span></label>
<textarea name="msg" id="msg" rows="7"></textarea>
<input type="checkbox" name="agree">
<label for="agree">Accept the terms</label>
<button class="blue_button" type="submit">Send</button>
</fieldset>
</form>
</div>​
And which is styled with the following CSS:
body {
color: #333;
font: 12px Arial,Helvetica Neue,Helvetica,sans-serif;
}
#right_sidebar {
padding-top: 12px;
width: 190px;
position:relative;
}
form {
background: #EEF4F7;
border: solid red;
border-width: 1px 0;
display: block;
margin-top: 10px;
padding: 10px;
}
form label {
color: #435E66;
display:block;
font-size: 12px;
}
form textarea {
border: 1px solid #ABBBBE;
margin-bottom: 10px;
padding: 4px 3px;
width: 160px;
-moz-border-radius: 3px;
border-radius: 3px;
}
form label a {
display: block;
padding-left: 10px;
position: relative;
text-decoration: underline;
}
form label a .sp {
background: #EEF4F7;
height: 0;
left: 0;
position: absolute;
top: 2px;
width: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 4px solid #333;
}
form button.blue_button {
margin-top: 10px;
vertical-align: top;
}
button.blue_button{
color: white;
font-size: 12px;
height: 22px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
button.blue_button {
background-color: #76C8C6;
border: 1px solid #7798B7;
text-shadow: 1px 1px 0px #567C9E;
}
​As you can see the checkbox is on top of the label. I would like both to be "on the same line". So, it would look like "[ ] Accept the terms". And how would I make that the text is vertically aligned to the checkbox.
How could I do both?
You can see it live here: form, checkbox failing
One option is to amend the style of the label element that follows the checkbox:
​input[type=checkbox] + label {
display: inline-block;
margin-left: 0.5em;
margin-right: 2em;
line-height: 1em;
}
JS Fiddle demo.
This is, however, somewhat fragile as the margins are a little arbitrary (and the margin-right is purely to force the following button to the next line). Also the attribute-equals selector may cause problems in older browsers.
As implied, in comments, by Mr. Alien it is actually easier to target the checkbox itself with this selector-notation:
input[type=checkbox] {
float: left;
margin-right: 0.4em;
}
JS Fiddle demo.
It is because the label has display: block on it. It means that (without a float or hack) it will claim it's own line.
Change it to display: inline-block or leave the display rule away and you're done.
Seeing you did this intentionally for the first two labels, you should give the accept the terms label an id and use form #accepttermslabel {display: inline-block}. This will override the other rules et because it is more specific.
Wrap your checkbox and text within the <label> tag. Works with your current CSS as seen here in this jsFiddle Demo.
<label for="checkbox">
​<input id="checkbox" type="checkbox"> My Label
</label>​​​​​​​​​​​​​​​​​​​​​​​​​​
Forked your fiddle here with one small change. I nested the checkbox inside the label.
<label for="agree"><input type="checkbox" name="agree">Accept the terms</label>
Hope it helps.
All you need to do is add display: inline to the label. Like this:
label[for="agree"] {
display: inline;
}
You may also have to add the following to get the Send button to stay on its own line:
button[type="submit"] {
display: block;
}
That is enough to make it work, but you could also nest the input inside the label, like this:
<label for="agree">
<input type="checkbox" name="agree" />
Accept the terms
</label>
However, most people avoid doing this because it is semantically constricting. I would go with the first method.
Set a class on the checkbox list as follows:
<asp:CheckBoxList ID="chkProject" runat="server" RepeatLayout="Table" RepeatColumns="3" CssClass="FilterCheck"></asp:CheckBoxList>
Then add the following CSS:
.FilterCheck td {
white-space:nowrap !important;
}
This ensures the label stays on the same line as the checkbox.
I had the same problem with bootstrap 3 horizontal-form, and finally found a try-error solution and works with plain html-css too.
Check my Js Fiddle Demo
.remember {
display: inline-block;
}
.remember input {
position: relative;
top: 2px;
}
<div>
<label class="remember" for="remember_check">
<input type="checkbox" id="remember_check" /> Remember me
</label>
</div>
Tried the flex attribute?
Here's your example with flex added:
HTML
<div id="right_sidebar">
<form id="send_friend" name="send_friend" action="#" method="post" style="display: block; ">
<fieldset>
<label for="from">From</label>
<input type="text" name="from" id="from" value="">
<label for="to">To</label>
<input type="text" name="to" id="to">
<label for="msg">Comment <span class="sp"></span>
</label>
<textarea name="msg" id="msg" rows="7"></textarea>
<div class="row">
<div class="cell" float="left">
<input type="checkbox" name="agree">
</div>
<div class="cell" float="right" text-align="left">
<label for="agree">Accept the terms</label>
</div>
</div>
<button class="blue_button" type="submit">Send</button>
</fieldset>
</form>
</div>
CSS
body {
color: #333;
font: 12px Arial, Helvetica Neue, Helvetica, sans-serif;
}
[class="row"] {
display: flex;
flex-flow: row wrap;
margin: 2 auto;
}
[class="cell"] {
padding: 0 2px;
}
#right_sidebar {
padding-top: 12px;
width: 190px;
position:relative;
}
form {
background: #EEF4F7;
border: solid red;
border-width: 1px 0;
display: block;
margin-top: 10px;
padding: 10px;
}
form label {
color: #435E66;
display:block;
font-size: 12px;
}
form textarea {
border: 1px solid #ABBBBE;
margin-bottom: 10px;
padding: 4px 3px;
width: 160px;
-moz-border-radius: 3px;
border-radius: 3px;
}
form label a {
display: block;
padding-left: 10px;
position: relative;
text-decoration: underline;
}
form label a .sp {
background: #EEF4F7;
height: 0;
left: 0;
position: absolute;
top: 2px;
width: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 4px solid #333;
}
form button.blue_button {
margin-top: 10px;
vertical-align: top;
}
button.blue_button {
color: white;
font-size: 12px;
height: 22px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
button.blue_button {
background-color: #76C8C6;
border: 1px solid #7798B7;
text-shadow: 1px 1px 0px #567C9E;
}
Flex allows for table style control with the use of divs for example.
The simplest way I found to have the checkbox and the label aligned is :
.aligned {
vertical-align: middle;
}
<div>
<label for="check">
<input class="aligned" type="checkbox" id="check" /> align me
</label>
</div>
<div>
<input class="aligned" type="checkbox" />
<label>align me too</label>
</div>
<div>
<input type="checkbox" />
<label>dont align me</label>
</div>
I know this post is old, but I'd like to help those who will see this in the future. The answer is pretty simple.
<input type="checkbox" name="accept_terms_and_conditions" value="true" />
<label id="margin-bottom:8px;vertical-align:middle;">I Agree</label>