How to group an icon and an input element - html

I'm trying to achieve the following:
Create 3 input elements in a row
Each should have a logo to the left of it, centered perfectly.
Each should have a border-bottom that spans the logo as well.
Like the following image:
However with my current code the images can't be centered and the border doesn't span them. Here's my code:
input {
border: none;
width: 250px;
background-color: #393d49;
border-bottom: 1px solid #767D93;
padding: 10px;
}
form img {
width: 24px;
height: 24px;
}
<form>
<img src="assets/images/envelope.png" alt="Envelope icon indicating user's E-Mail.">
<input type="email" placeholder="E-Mail"><br>
<img src="assets/images/locked.png" alt="Lock icon indicating user's Password.">
<input type="password" placeholder="Password"><br>
<img src="assets/images/avatar.png" alt="Avatar icon indicating user's Name.">
<input type="text" placeholder="Username"><br>
</form>

As it was suggested, I would also use the font-awesome library. But if your not comfortable with that idea, here is how you can do without.
form, .form-row, input {
background-color: #051024;
}
.input-icon, label, input {
display: inline-block;
}
form {
padding: 0.8em 1.2em;
}
.form-row {
padding: 0.8em 0;
padding-bottom: 0.2em;
}
.form-row:not(:last-child) {
border-bottom: solid #18273a 1px; /* Only the last row has a border */
}
.input-icon {
width: 15px;
height: 15px;
margin: 0 10px;
}
label {
max-width:4em; /* Or the maximum width you want your lebel to be */
min-width:4em; /* Same */
color:white;
font-weight: 100;
}
input {
border:none;
padding: 0.8em 0.5em;
color: #6691c9;
font-size: 15px;
outline: none; /* No glowing borders on chrome */
}
<form>
<div class="form-row">
<!-- Put your image here, like so -->
<img class="input-icon" src="http://1.bp.blogspot.com/-QTgDeozeWws/VLztRSNkMEI/AAAAAAAAKkQ/mrxdCfxWfvU/s1600/1f499.png" alt="oops"/>
<label for="form-email">Email</label>
<input id="form-email" type="email">
</div>
<div class="form-row">
<img class="input-icon" src="http://1.bp.blogspot.com/-QTgDeozeWws/VLztRSNkMEI/AAAAAAAAKkQ/mrxdCfxWfvU/s1600/1f499.png" alt="oops"/>
<label for="form-password">Password</label>
<input id="form-password"type="password" placeholder="(8 characters min)">
</div>
<div class="form-row">
<img class="input-icon" src="http://1.bp.blogspot.com/-QTgDeozeWws/VLztRSNkMEI/AAAAAAAAKkQ/mrxdCfxWfvU/s1600/1f499.png" alt="oops"/>
<label for="form-user">User</label>
<input id="form-user" type="text"><br>
</div>
</form>
If you're feeling adventurous
Try bootstrap, it has all you need to create cool web sites (it also includes the font-awesome library).

Related

Basic styling in an html page with CSS

I want to preface this by saying that this website comes highly recommended and was recommended by my professor to help "learn on our own." My question is probably incredibly simple and I apologize if it seems as a "waste of space". I am doing an assignment that requires creating a submittable proper functioning form in vim using HTML and CSS for styling on the course's server.
I have it all laid out as is, however, I have multiple labels in the body ("First Name"/"Last Name" "Class year selection box"/ "address"/"City"/ and "email". The First Name, Last Name, and Email are all what I am trying to style as "red text" to denote that these are the required fields.
I have the code set up to where these are required in order to submit the form, but I cannot figure out how to style it in the header to where I can differentiate which labels need to be in "red". As it is now, when I insert " Label { color:red; } in the header, it turns all of the text into red. Is there a way to denote specific labels to be red and the non-required labels to remain in black text color? I have tried to insert numbers into the label inputs to denote the different labels in need of a red text color but it applies it to all of the text on the form.
Is there anyway to properly add an identifying feature into a label to allow only the chosen labels as being red?
I appreciate any feedback and I apologize again if this is a waste of time for seasoned coders/developers to have to answer this question. Any input is appreciated.
How my form looks now online
The header (that has it all red)
The (this is where I am lost with inserting class properly)
At your HTML file add a class to each label you want to target individually, e.g.
<span class="label firstName">Joe</span>
At your CSS target this class and format the way you want, e.g.
.firstName {color: #f44336;}
This will target your label with the class of firstName and color the text RED.
There are multiple ways to approach this. If you are allowed to use only HTML and CSS, you can try to create multiple div's in the HTML file and create a CSS property in the CSS file that "styles" the required fields.
HTML
<div class="forms-box">
<h2>My Forms</h2>
<form>
<div class="user-box">
<input type="text" name="" required="" />
<label>First Name</label>
</div>
<div class="user-box">
<input type="password" name="" required="" />
<label>Last Name</label>
</div>
<div class="user-box">
<input type="password" name="" required="" />
<label>Last Name</label>
</div>
<div class="user-box3">
<label>Class year</label>
<select type="checked" required="" name="class-year">
<option value="2021">2021</option>
</select>
</div>
<div class="user-box">
<input type="password" name="" required="" />
<label>Address</label>
</div>
<div class="user-box">
<input type="password" name="" required="" />
<label>City</label>
</div>
<div class="user-box">
<input type="password" name="" required="" />
<label>Email</label>
</div>
</form>
</div>
CSS
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background: linear-gradient(#141e30, #243b55);
}
.forms-box {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
padding: 40px;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.5);
box-sizing: border-box;
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.6);
border-radius: 10px;
}
.forms-box h2 {
margin: 0 0 30px;
padding: 0;
color: #fff;
text-align: center;
}
.forms-box .user-box {
position: relative;
}
.forms-box .user-box input {
width: 100%;
padding: 10px 0;
font-size: 16px;
color: #fff;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
}
.forms-box .user-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: 0.5s;
}
.forms-box .user-box3 label {
color: #fff;
font-size: 16px;
margin-bottom: 10px;
margin-right: 40px;
}
.forms-box .user-box3 select {
color: #000;
margin-bottom: 20px;
}
.forms-box .user-box input:focus ~ label,
.forms-box .user-box input:valid ~ label {
top: -20px;
left: 0;
color: #ff0000;
font-size: 12px;
}
I have created a mock up which lists all the required fields that need to be filled before submitting.
Here is the link to my mockup

Media query not working on HTML form

I would like the font size for my form label and input fields to scale down from 18px to 10px when the browser width reaches 1460px or less.
I read that it is not possible to get fonts to automatically 'scale down' as such when the browser width decreases, and that I would need to use media queries instead.
Therefore I have put a media query at the top of my style tags asking the font size for my label and input to display at 10px when the screen size is 1460px, but it doesn't seem to work. The rest of my code is working fine however, so it must be something to do with the way I am coding my media query.
If someone could offer some help that would be much appreciated.. my code is pasted below.
#media only screen and (max-width: 1460px) {
label input {
font-size: 10px;
}
}
* {
box-sizing: border-box;
}
input[type=text],
select {
width: 95%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 3px;
resize: vertical;
transition: 0.3s;
outline: none;
font-family: Typ1451-Medium;
font-size: 18px;
margin: 7px;
}
input[type=text]:focus {
border: 1.25px solid #ea0088;
}
label {
padding: 21px 12px 12px 12px;
margin-left: 5px;
display: inline-block;
font-family: Typ1451-Medium;
font-size: 18px;
color: #999;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
margin: 2.5% 20% 0 20%;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
.left,
.right {
width: 50%;
}
form {
display: flex;
}
<div class="container">
<form action="signin.php" method="post">
<div class="left">
<div class="row">
<div class="col-25">
<label for="fname">First Name</label>
</div>
<div class="col-75">
<input type="text" id="fname" name="firstname" placeholder="* Please complete">
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="col-25">
<label for="lname">Last Name</label>
</div>
<div class="col-75">
<input type="text" id="lname" name="lastname" placeholder="* Please complete">
</div>
</div>
</div>
</form>
</div>
Your selector — label input — doesn't match any elements in your HTML.
None of your input elements are descendants of your label elements.
Perhaps you meant label, input to select label elements and input elements. If so, then it still wouldn't work because you define the input font-size with a more specific selector later on (and the most specific selector wins the cascade) and the label in a similar way (it doesn't have a more specific selector, but when selectors are equal, the last one wins the cascade).
Actually, you CAN scale fonts up or down with the viewport size. There is a method with calc() and vw units:
Basically you do something like font-size: 3vw and then set max and min font sizes.
Here is a link to the calculation on Smashing Magazine. The rest of the article is pretty interesting, too.
You can extend this even further and optimize the font size with media queries.
Have fun! :)

Align input on current line at specific position in CSS [duplicate]

This question already has answers here:
Align labels in form next to input
(8 answers)
Closed 5 years ago.
I am trying to create a settings page in HTML/CSS. I have a rounded corner div with some text and an input box inside.
I want to align the input boxes as seen in the image below with the red line. Is there a way in CSS to push the input boxes over and have them line up in each div?
CSS
.mainItem {
background-color: white;
color: #38434e;
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
border: 1px solid #d6d9e5;
}
.pageInput {
position: absolute:
left: 200px;
}
HTML
<div class="mainItem">Business Name<input type="text" class="pageInput"></div>
<div class="mainItem">Address<input type="text" class="pageInput"></div>
Bhuwan's solution doesn't work and looks like this:
I would put your text in a label and give that a width:
.mainItem {
background-color: white;
color: #38434e;
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
border: 1px solid #d6d9e5;
}
.mainItem>label {
display: inline-block;
width: 150px;
}
<div class="mainItem"><label for="input1">Business Name</label><input type="text" id="input1" class="pageInput"></div>
<div class="mainItem"><label for="input2">Address</label><input type="text" id="input2" class="pageInput"></div>
Labels make your form more accessible too as you can now click on the label to focus your input
Firstly, you don't need position absolute for this. Second, use labels for your input fields and give them the same width:
<div class="mainItem">
<label for="input1">Name </label>
<input type="text" class="pageInput" id="input1">
</div>
<div class="mainItem">
<label for="input2">Address</label>
<input type="text" class="pageInput" id="input2">
</div>
In the CSS:
.mainItem label {
width: 20%;
display: inline-block;
}

css - align label & textbox at right side of page

I have created 4 column grid in my html form. i want to have last label and textbox field to be align right side of the page.
I have tried using float:right property but it doesn't seem to work
In fiddle example it is not in single line.
.row {
margin: 10px;
}
.elements {
padding: 10px;
margin-left: 50px;
margin-top: 10px;
border-bottom: ridge;
border-bottom-color: #1f6a9a;
padding-left: 0;
}
.field {
font-size: 15px;
color: #b6d6ed;
}
label {
display: inline-block;
}
input {
background-color: transparent;
border: 0px solid;
height: 25px;
width: 60px;
color: #b6d6ed;
text-align: center;
}
/* I Tried Below Line to Right Align */
.row > .elements:nth-child(2) {
float:right;
}
<div class="row">
<span class="elements">
<label class="field" for="Title">Title</label>
<input id="Title" name="Title" type="text">
</span>
<span class="elements">
<label class="field" for="DateOfBirth">Date of Birth</label>
<input id="DateOfBirth" name="DateOfBirth" type="text" value="" class="hasDatepicker">
</span>
</div>
jsfiddle
Float the first span to the left:
.row > .elements:first-child {
float: left;
}
See it here: http://jsfiddle.net/3DtqB/2/
You have to put the elements class into a <div class=".."></div> and add an CSS command
.elements {
float: right;
margin-top: -[x]px
}
Also you should use two id's instead of a class elements like left_box and right_box and add the commands to the right box.
Simple fix, just add white-space:nowrap; to the .elements class.

Remove weird border from input text field

I am trying to remove a border from a input text field for my contact form.
Basically, everytime when I enter any data into the input text field (Name field) and then move on to the next field which is email, the input text field sort of has a border around it that might be invisible of some sort.
I tried my best to mess around with the CSS to make it work, but somehow its not working.
HTML
<section id="contact">
<div class="container">
<h3 class="contact-section-title">Need advice?</h3>
<p class="contact-section-sub-title-form">Drop me an email below.</p
<div class="grid-row col-2">
<div class="grid-unit3">
<form name="form1" method="post" action="contact.php" >
<input name="cf_name" placeholder="What is your name? (Eg: John Doe)" type="text" required />
<input name="cf_email" placeholder="What is your email? (Eg: johndoe#johndoe.com)" type="email" required />
<textarea rows="4" cols="50" name="cf_message" placeholder="Please enter your message" class="message" required></textarea>
<button class="submit" type="submit">Send email</button>
<br><Br><br><Br>
</form>
</div><!--class="email" type="email"-->
</div>
</div>
</section>
JSFiddle
Would appreciate some solid help on this. Don't know where to go from here.
Thank you.
Changes I made ->
border:0px solid #58B9FA;
line 105.
The reason is because you add border:1px solid #58B9FA; to all input element. Fix it by replacing it with:
input {
border: 0
}
Updated Fiddle
Changed the border property in css from following
input {
color: #3498db;
display: block;
font-family: Lato-Regular, sans-serif;
font-size: 17px;
margin-bottom: 0.8em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
width: 100%;
border:1px solid #58B9FA; }
to
input {
color: #3498db;
display: block;
font-family: Lato-Regular, sans-serif;
font-size: 17px;
margin-bottom: 0.8em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
width: 100%;
border:0px solid #58B9FA; }
set border: none; or border:0 in your input css
FIDDLE