I'm 15 days into learning to code. I did the HTML modules on Freecodecamp, and I've started a mini project on CodePen. I've found I've already forgotten a ton, but I want to crack on with the project as that's what's helping me learn stuff.
My mini-project is a sign up form. Currently only email, but later I want to add first/last name plus other data points. However I want to know how to style the box of the email so it can be a bit bigger, plus I want to be able to make the text next to my checkbox smaller. But I've gotten stuck on both parts. I used a basic template for the form and adjusted it from there, but I'm really stuck on the styling.
My code is below. Am I along the right lines?
HTML
<!--- These are my sign up form elements --->
<div class="myForm"><b>Below is a form</b></div></br>
<label for="email">
<input type="text" placeholder="Enter Email" name="email" required>
</br></br>
</label>
<label>
<button type="submit" class="signupbtn">Sign me up!</button>
</br>
</br>
</label>
<label>
<input type="checkbox"> I agree to the terms and conditions here</input>
</label>
CSS
body {
font-family: Verdana,Arial,sans-serif;
font-size: 18px;
}
p {
font-size: 14px;
}
.myForm{
font-family: Verdana,Arial,sans-serif;
width: 200px;
}
button {
background-color: #4CAF50;
color: white;
border-radius: 10px;
font-size: 16px;
padding: 8px;
}
label[for=email] {
font-size: 20px;
}
body {
font-family: Verdana, Arial, sans-serif;
font-size: 18px;
}
.myForm {
width: 200px;
}
.enter-email {
width: 300px;
/* what ever width you want */
height: 20px;
/* change the height if you want like this */
}
button {
background-color: #4CAF50;
color: white;
border-radius: 10px;
font-size: 16px;
padding: 8px;
}
.terms-conditions {
font-size: 16px;
/* change the size of the font */
}
<!--- These are my sign up form elements --->
<div class="myForm"><b>Below is a form</b></div>
</br>
<label for="email"> Enter E-mail:</label>
<input class="enter-email" type="text" placeholder="Enter Email" name="email" required>
</br>
</br>
<button type="submit" class="signupbtn">Sign me up!</button>
</br>
</br>
<input type="checkbox">
<span class="terms-conditions"> I agree to the terms and conditions
here
</span>
</input>
This will help you. To change the input box for the text use a class on it and change its properties(search for more other than the two I showed) or you could have done input[type=text] to select that text input but classes are better if you have more text inputs and want them styled differently.
As for the changing text of terms and conditons, you could have wrapped it in paragraph tags, heading tags and also as I used span tags. Then again give them a class and change the font-size.
Also as pointed out in the comment you don't need to specify the font-family everytime unless you want a different font applied there. Everything text property applied in body will be given to all the text in the body unless you specify something for that text otherwise.
Related
I'm trying to replace that old input file with something modern that i designed in the fiddle. However since i'm using WP contact form 7 is integrated into theme and the only way i can edit it is via this code -
<label>
[text* your-name placeholder "Your Name (required)"] </label>
<label>
[email* your-email placeholder "Your email (required)"] </label>
<label>
[text your-subject placeholder "Subject"] </label>
<label>
[textarea your-message placeholder "Your Message"] </label>
[file file-442 limit:10485760 filetypes:doc|pdf|csv class:cv]
[submit "AHOI!"]
So is there a way to replace this last input where the file is with my input and hide original input? This is my input
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 1px solid currentColor;
color: #083a50;
cursor: pointer;
display: inline-block;
font-weight: bold;
line-height: 1;
padding: 0.5em 2em 0.25em 1em;
user-select: none;
}
.upload {
height: 1.75em;
margin-right: 0.5em;
padding-bottom: 0.25em;
width: auto;
vertical-align: middle;
}
<label for="file-upload" class="custom-file-upload">
<img class="upload"src="http://www.plaforma.me/wp-content/uploads/2018/04/SEND-FILE-IKONICA.png" width="300" height="53" alt=""> Select File
</label>
<input id="file-upload" type="file" />
Don't know why here doesn't load icon next to text but there is icon, so anyone got idea how could i replace original in contact form 7?
For styling, file input type the http://markusslima.github.io/jquery-filestyle library is very good.
$(":file").jfilestyle({input: false, text: "Select File"});
Also, see the options here. http://markusslima.github.io/jquery-filestyle/options.html
I've narrowed this down to the following HTML, which causes strange effects in Chrome:
<style type="text/css">
#btn1, .text1 {
font-family: courier;
font-size: 42px;
background: pink; /* BUG?? Removing this line breaks btn1's font */
}
#btn2, .text2 {
font-family: arial;
font-size: 42px;
background: cyan;
}
</style>
<input type='button' id='btn1' onclick='alert("btn1")' value='Button1'>
<input type='button' id='btn2' onclick='alert("btn2")' value='Button2'> <p>
<input type='text' class='text1' value='Text1'> <p>
<input type='text' class='text2' value='Text2'>
When the declaration line containing background: pink; is removed, it breaks the font-family and font-size for the button with the ID btn1, but the input with class text1 is fine, and only in Chrome (I've only tested Chrome and Firefox).
It doesn't seem to matter if I change classes to IDs or vice versa; it's always the button that loses its font characteristics. Furthermore, it doesn't seem to make a difference where background: pink; appears within the block; as long it's there, the font seems to be as expected.
It is working fine as per your styles given. font-size: 42 which is not going to apply anything because it is not a valid syntax. It should be like font-size:42px as its in #btn2. After that if you remove/add the background, that's not changing any of the styles. Look at the following snippet(I didn't apply font-size:42px, and running as it is your code).
#btn1, .text1 {
font-family: courier;
font-size: 42;
background: pink; /* BUG?? Removing this line breaks btn1's font */
}
#btn2, .text2 {
font-family: arial;
font-size: 42px;
background: cyan;
}
<input type='button' id='btn1' onclick='alert("btn1")' value='Button1'>
<input type='button' id='btn2' onclick='alert("btn2")' value='Button2'> <p>
<input type='text' class='text1' value='Text1'> <p>
<input type='text' class='text2' value='Text2'>
Now I will remove the background: pink from your code. Look at the snippet below.
#btn1, .text1 {
font-family: courier;
font-size: 42;
}
#btn2, .text2 {
font-family: arial;
font-size: 42px;
background: cyan;
}
<input type='button' id='btn1' onclick='alert("btn1")' value='Button1'>
<input type='button' id='btn2' onclick='alert("btn2")' value='Button2'> <p>
<input type='text' class='text1' value='Text1'> <p>
<input type='text' class='text2' value='Text2'>
Look at the above snippet. There is no difference between the two snippet button1 font family. Both the places it applied courier font only. Only the background is getting different because it is applying the default styles for the button.
Now let us know, Still any specific issue you have???
I have been using this code in Boostrap 4 beta and everything was ok.
<label for="username" th:text="#{login.user">User</label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span> <input
type="text" id="username" name="username" class="form-control"
placeholder="Usuario" th:placeholder="#{login.user}"
th:required="true" />
</div>
Now, I've updated my Bootstrap 4 to current v4.0.0., but with that, the code is not working. The input-group-addon class is not present in the Bootstrap css file.
If I add this to my css style file everything works ok:
.input-group-addon {
padding: .375rem .75rem;
margin-bottom: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
text-align: center;
background-color: #e9ecef;
border: 1px solid #ced4da;
}
Am I'm doing somenthing wrong?
Thanks
It looks like you need mandatory wrap icon with <span class="input-group-text"><i class="icon-user"></i></span> to display it correctly
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="icon-user"></i></span>
<input ...>
</div>
</div>
Here is a link to official Bootstrap 4 migration guide for Input Groups were they say that
We’ve dropped .input-group-addon and .input-group-btn for two new classes, .input-group-prepend and .input-group-append. You must explicitly use an append or a prepend now, simplifying much of our CSS. Within an append or prepend, place your buttons as they would exist anywhere else, but wrap text in .input-group-text.
Is there a way to use CSS to update input fields without changing HTML code?
I have a form like this:
// HTML
<div id="LoginFormContainer">
<div class="formInputLine">
<div class="inputContainer">
<input name="txtUserID$Textbox1" type="text" maxlength="15" id="txtUserID_Textbox1" placeholder="Username" title="Username">
</div>
</div>
<div class="formInputLine">
<div class="inputContainer">
<input name="txtPassword$Textbox1" type="password" maxlength="15" id="txtPassword_Textbox1" placeholder="Password" title="Password">
</div>
</div>
<div class="formInputLine">
<input type="submit" name="btnLogin" value="Login" id="btnLogin"><input name="builderID" type="hidden" id="builderID" value="abc">
</div>
</div>
//CSS
#FormLoginPage #LoginFormContainer .formInputLine .inputContainer input {
text-transform: uppercase!important;
}
#FormLoginPage #LoginFormContainer .formInputLine .inputContainer input {
border: none;
font-size: 12px;
width: 100%;
color: #333;
outline: 0;
-webkit-appearance: caret;
}
// TRYING CSS - able to use this code to add a label but it applies to all input. Not sure how to target only the individual class with a specific id within it.
.formInputLine::before {
content: "Username";
}
And would like to change it to the following using only CSS:
Please note that the above code is actually part of this code I got from a 3rd party. So I am not sure if I can control it via the iframe tag.
Thanks for the help, I greatly appreciate it.
If the input fields have wrapper elements you can use pseudo elements (before or after) on that wrapper to create what you want with pure css, otherwise you'll have to use javascript to manipulate the html structure / add elements etc.
So, for an example, if we have the following HTML structure:
<div class="input-wrapper">
<input type="text" placeholder="some text">
</div>
We can do the following in CSS:
.input-wrapper {
position: relative;
}
.input-wrapper:before {
position: absolute;
left: 0;
bottom: calc( 100% + 10px );
content: "some text";
}
::-webkit-input-placeholder {
color: transparent !important;
}
(This one is used if we have a placeholder and we want to hide it. On production should also use the -moz- and -ms- prefixes).
You could have something like this:
I've included my own font, due to lack of context.
body {font-family: "Droid Sans"}
.Input-Element {padding: .3em;margin: .5em 0}
.Input-Element label {display: block;text-transform: uppercase;padding: .2em 0;font-size: .8em}
.Input-Element input {border:1px solid rgba(0, 0, 0, 0.34);padding:.5em;outline:none;transition: border .25s}
.Input-Element input:focus {border-color: rgba(0, 0, 0, 0.73)}
<link href="https://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet">
<div class='Input-Element'>
<label>Username</label>
<input name='user'>
</div>
<div class='Input-Element'>
<label>Password</label>
<input name='psw'>
</div>
Note: Click Run Code Snippet to see the form!
I was playing with the ideas provided by a few solutions here. After some researching on my own with :nth-child, here is the solution I have for my question. I am sure there is an other way to do the CSS selection. But this is what I have for now.
Using the CSS below can target the two fields individually and add the specific labels
/* add labels */
.formInputLine:nth-child(1)::before {
content: "Username";
}
.formInputLine:nth-child(2)::before {
content: "Password";
}
/* remove place holder */
::-webkit-input-placeholder {
color: transparent;
}
:-moz-placeholder {
/* Firefox 18- */
color: transparent;
}
::-moz-placeholder {
/* Firefox 19+ */
color: transparent;
}
:-ms-input-placeholder {
color: transparent;
}
You can use some jquery and css
$("input").wrap("<div class='custom-input'></div>");
$('.custom-input').eq(0).before("<label>USER NAME</label>");
$('.custom-input').eq(1).before("<label>PASSWORD</label>");
::-webkit-input-placeholder, ::-moz-placeholder, :-ms-input-placeholder {
color: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" valu "USER NAME" placeholder="USER NAME"><br>
<input type="passsword" placeholder="PASSWORD">
I am trying to create tableless Form using and tags, im stuck.
I want the form look like this:
I should be able to set the width of textbox, text area and select in CSS.
Make each row a <p> containing a <label> and an <input>, both display: inline-block with preset width. (The <label> should be text-align: right)
The buttons can be float: right.
This is a good walk through: http://woork.blogspot.com/2008/06/clean-and-pure-css-form-design.html
check out working example here:
http://jsfiddle.net/bRm3P/2/
<form>
<label>To: <input type="text" /></label>
<label>Subject: <input type="text" /></label>
<label>Message: <textarea></textarea></label>
<div class="submit-container">
<input type="submit" value="submit"/><input type="submit" value="submit"/>
</div>
</form>
<style>
form {
width: 500px;
}
label {
display: block;
text-align: right;
margin-bottom: 4px;
}
label input,label textarea {
border: 1px solid #DEDEDE;
width: 80%;
vertical-align: top;
}
.submit-container {
padding-top: 4px;
text-align: right;
}
</style>
A nice semantic layout would be one of the following:
<ul>
<li><label>To <input></label></li>
...
</ul>
Or with a dl (more common):
<dl>
<dt><label>To</label></dt><dd><input></dd>
...
</dl>
You will find lots of ways to layout the latter if you google for: definition list layout form