I'm new to world of forms! I had made divs and css for the exact layout I want for the forms. Is there anyway to maybe just turn that div tag into button or a text field while still using the same css rules so the layout doesn't change?
Here is some code and demo to just check what I have going on.
HTML
<div id="loginContainer">
<div id="loginForm">
<div id="login"></div>
<div id="loginUsername"></div>
<div id="loginPassword"></div>
<div id="loginSubmit"></div>
</div>
<div id="registerForm">
<div id="register"></div>
<div id="registerName"></div>
<div id="registerEmail"></div>
<div id="registerPassword"></div>
<div id="registerPasswordConfirm"></div>
<div id="registerSubmit"></div>
</div>
</div>
CSS
#loginContainer {
width: 50%;
height: 50%;
position: absolute;
left: 21.8%;
top: 40%;
z-index:-9999;
}
#loginForm {
width:47.5%;
height: 100%;
float:left;
top: 0%;
position:relative;
}
#login {
width: 100%;
height: 10%;
top: 0;
background-image:url(../_images/_login/login.png);
background-size: 100% 100%;
position: absolute;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#loginUsername {
width: 100%;
height: 10%;
top: 15%;
background-color: #383d3f;
position: absolute;
border-radius: 5px;
}
#loginPassword {
width: 100%;
height: 10%;
top:30%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#loginSubmit {
width: 100%;
height: 10%;
top: 45%;
background-color:#76c2bb;
position:absolute;
border-radius: 5px;
}
#registerForm {
width:47.5%;
height: 100%;
float:right;
top: 0%;
position:relative;
}
#register {
width: 100%;
height: 10%;
top:0%;
background-image:url(../_images/_register/register.png);
background-size: 100% 100%;
position:absolute;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#registerName {
width: 100%;
height: 10%;
top:15%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerEmail {
width: 100%;
height: 10%;
top: 30%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerPassword {
width: 100%;
height: 10%;
top: 45%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerPasswordConfirm {
width: 100%;
height: 10%;
top: 60%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerSubmit {
width: 100%;
height: 10%;
top: 75%;
background-color:#76c2bb;
position:absolute;
border-radius: 5px;
}
CLICK FOR DEMO
Sure you can, just replace the right elements with input with proper markup, add an opening and closing form tag, remove the borders, and you're good to go:
<div id="loginContainer">
<div id="loginForm">
<div id="login"></div>
<form method="post" name="loginForm">
<input id="loginUsername" type="text" name="loginUsername" />
<input id="loginPassword" type="text" name="loginPassword" />
<input id="loginSubmit" type="submit" name="loginSubmit" value="" />
</form>
</div>
<div id="registerForm">
<div id="register"></div>
<form method="post" name="loginForm">
<input id="registerName" type="text" name="registerName" />
<input id="registerEmail" type="text" name="registerEmail" />
<input id="registerPassword" type="text" name="registerPassword" />
<input id="registerPasswordConfirm" type="text" name="registerPasswordConfirm" />
<input id="registerSubmit" type="submit" name="registerSubmit" value="" />
</form>
</div>
</div>
#loginContainer input {
border:0
}
Here is your updated demo: http://jsfiddle.net/7w1adgko/2/
EDIT: Note that you may want to fill out the value property of the submit buttons so that users will actually know it's the submit button.
<input id="loginSubmit" type="submit" name="loginSubmit" value="Login" />
or...
<input id="registerSubmit" type="submit" name="registerSubmit" value="Register" />
Also, in order users to know what field is what, you may want to use the placeholder property.
<input id="loginUsername" type="text" name="loginUsername" placeholder="Username" />
<input id="loginPassword" type="text" name="loginPassword" placeholder="Password" />
or...
<input id="registerName" type="text" name="registerName" placeholder="Name" />
<input id="registerEmail" type="text" name="registerEmail" placeholder="Email" />
<input id="registerPassword" type="text" name="registerPassword" placeholder="Password" />
<input id="registerPasswordConfirm" type="text" name="registerPasswordConfirm" placeholder="Confirm Password" />
And to make it prettier, you could add some colour and padding to the inputs.
#loginContainer input {
border:0;
padding: 0 10px;
color:white
}
Here is your most recent fiddle with these changes: http://jsfiddle.net/7w1adgko/3/
EDIT 2: To make all the boxes have the same width, you could specify the same box model for type="text" and type="submit" inputs (source: CSS: Submit button looks smaller than text input and textarea)
#loginContainer input {
border:0;
padding: 0 10px;
color:white;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
Here is the updated fiddle: http://jsfiddle.net/7w1adgko/4/
It would be better to start from the proper functional markup and then consider styling. For the functionality of a form, you need elements like input to set up the controls, label to have labels (captions) associated with controls, and form to contain the entire form. (And you probably should not have two forms side by side, it can be confusing.)
However, if you have designed a layout in a “DIVistic” way and you wish to turn it to a functional form element with working controls, you need to take into account that form-related elements have default rendering that you may need to override. A form element has top and bottom margin by default, label elements are inline elements (display: inline) as opposite to div elements that are blocks (display: block), and input elements are inline blocks that have borders and padding.
On the other hand, most (if not all) of your div elements are just containers, instead of being direct counterparts to controls. For example, the element <div id="loginUsername"></div> really needs some content, such as
<div id="loginUsername"><label for="uname">User name:</label>
<input id="uname" name="uname" required size="8" maxlength="8"></div>
Assuming that the content fits inside the div element as formatted in your current design, no change in the layout styling is then needed. (However, from the jsfiddle, it seems that you intend to use form controls without any labels. This would be a major usability and accessibility problem, and fixing it probably requires a redesign of the layout.)
Related
I'm looking to create the desired styling in the photo shown. Having trouble getting the custom SVGs I created to be inline with the text field. How would I go about creating this effect?
Here's a snippet of the code I'm using at the minute, where am I going wrong?
I'm mostly using the JQM library if that is of any help.
<div class="box2" style="display: inline-block; position:relative; width: 40vw;">
<img src="img/icon/regicons/usernumber.svg">
<input type="text" name="userNo" id="userNo" placeholder="Number" required><br>
</div>
Ensure that the <input/> has the same height as your <image/> and position it at top of it's parent element.
height: 32px; box-sizing: border-box;
absolute; top: 0;
Snippet:
input {
height: 32px;
box-sizing: border-box;
position: absolute;
top: 0;
}
.box2 {
display: inline-block;
position:relative;
width: 40vw;
}
<div class="box2" style="">
<img width="32" height="32" src="https://lh4.googleusercontent.com/-HhNoCFJ803s/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbAXJpr-jDsvmXVw0tx4PHId84zrlw/mo/photo.jpg?sz=32">
<input type="text" name="userNo" id="userNo" placeholder="Number" required>
</div>
I would use a flexbox, which is responsive by nature.
.box2 {
display: flex;
background-color: lightgrey;
align-items: center; /* Vertical alignment */
}
<div class="box2" style="position:relative; width: 40vw;">
<img src="https://via.placeholder.com/50x50/00ff00">
<input type="text" name="userNo" id="userNo" placeholder="Number" required><br>
</div>
first off i'd like to say that I am god awful at designing and using CSS, so I was wondering if I could get some help with making my div responsive. It is currently sitting at the middle of the screen which is working, however, it gets all squished in (width wise and height wise) when used on different screens. The text does also not change. Even when used on a 1080p monitor, it has scroll bars on, so i'm really stuck on how to style it. I have pasted the HTML and CSS below.
<div id="mainForm">
<form id="userForm" method="post">
<p id="userP">Username: <br>
<input id="Username" type="text" name="Username" placeholder="Username" onfocus="this.placeholder='';" onblur="this.placeholder='Username';">
<p id="passP">Password: <br>
<input id="Password" type="password" name="Password" placeholder="Password" onfocus="this.placeholder='';" onblur="this.placeholder='Password';">
<p id="emailP">Email: <br>
<input id="Email" type="text" name="Email" placeholder="Email Address" onfocus="this.placeholder='';" onblur="this.placeholder='Email Address';">
<p id="authP">Auth Code: <br>
<input id="auth2" type="text" name="Auth" placeholder="Auth Code" onfocus="this.placeholder='';" onblur="this.placeholder='Auth Code';"><br>
<input type="submit" id="submit" name="submit" value="Login"/>
<h4>Don't have an account? <a href="register.php" >Register!</a></h4>
</form>
</div>
CSS for the main DIV:
#mainForm{
width: 20vw;
height: 40vh;
background-color: white;
margin:auto;
font-family: Montserrat;
text-align: center;
align-items: center;
margin-top: 2%;
position: absolute;
overflow: auto;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
CSS for form elements:
#Username, #Password, #Email, #Auth, #auth2 {
border: none; border-bottom: 2px solid;
padding: 0.5%;
margin-left: 1%;
width:40%;
transition: width 1s;
-webkit-transition: width 0.8s;
text-align: center;
font-size: 16px;
}
#Username:focus, #Password:focus, #Email:focus, #auth2:focus {
width: 60%;
}
#userP, #passP, #emailP, #authP{
font-size: 20px;
}
#userP{
margin-top:15%;
}
Thanks.
first of all set the meta viewport tag in your head of HTML
<meta name="viewport" content="width=device-width, initial-scale=1">
second of all use bootstrap framework which is totally responsive, then wrap your div in columns
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<!-- your form goes here -->
</div>
</div>
</div>
inside <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> you can add more classes and alter their CSS property like max-width, min-width, margin-top etc.
You might want to just stick to using pixels instead of vw and vh with such a small window to work with. I would suggest a height and width of 300px (I checked and it looks alright concerning the content.)
As #Friday Ameh pointed out, usually you would want to work with media-queries, but in this case the size of the width isn't going to leave the screen because the smallest screensize (mobile) is usually around 350px anyway.
You might want to use a media-query for larger screens so it doesn't stay as small as 300px, but that's up to you and dependent on your design.
Can I help you any further?
you need to add height in pixel
#mainForm {
width: 320px;
height: 340px;
background-color: white;
font-family: Montserrat;
text-align: center;
align-items: center;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
#Username, #Password, #Email, #Auth, #auth2 {
border: none; border-bottom: 2px solid;
padding: 0.5%;
margin-left: 1%;
width:40%;
transition: width 1s;
-webkit-transition: width 0.8s;
text-align: center;
font-size: 16px;
}
#Username:focus, #Password:focus, #Email:focus, #auth2:focus {
width: 60%;
}
#userP, #passP, #emailP, #authP{
font-size: 20px;
}
#userP{
margin-top:15%;
}
<div id="mainForm">
<form id="userForm" method="post">
<p id="userP">Username: <br>
<input id="Username" type="text" name="Username" placeholder="Username" onfocus="this.placeholder='';" onblur="this.placeholder='Username';">
<p id="passP">Password: <br>
<input id="Password" type="password" name="Password" placeholder="Password" onfocus="this.placeholder='';" onblur="this.placeholder='Password';">
<p id="emailP">Email: <br>
<input id="Email" type="text" name="Email" placeholder="Email Address" onfocus="this.placeholder='';" onblur="this.placeholder='Email Address';">
<p id="authP">Auth Code: <br>
<input id="auth2" type="text" name="Auth" placeholder="Auth Code" onfocus="this.placeholder='';" onblur="this.placeholder='Auth Code';"><br>
<input type="submit" id="submit" name="submit" value="Login"/>
<h4>Don't have an account? <a href="register.php" >Register!</a></h4>
</form>
</div>
I am trying to have the input field and the submit button stretch across the screen in the same row. Basically so the submit button does not ever go below the input field. Not even sure if I need to add an extra or not. I know that I have seen a way to have a responsive input field and submit button using display:table-cell, but I have not been able to find it lately. Any help would be appreciated.
**EDIT
I added: margin-left: -8px; to the submit button and that did the trick. Not sure if there is a better way but this works. Any other ways would be appreciated as well.
#div1{
display:table;
width:100%;
}
#div2{
display:table-cell;
}
input[type="email"].form-control {
width: 80%;
padding: 0px;
margin: 0px;
}
input[type="submit"].btn.btn-primary {
width: 20%;
padding: 0px;
margin: 0px;
margin-left: -8px;
}
<div id="div1">
<div id="div2">
<input type="email" name="EMAIL" class="form-control"
placeholder="Enter your E-mail Address">
<input type="submit" value="Subscribe" class="btn btn-primary">
</div>
</div>
Are you Trying to achieve something like this using display:table-cell ?
<div id="div2">
<input type="email" name="EMAIL" class="form-control"
placeholder="Enter your E-mail Address">
<input type="submit" value="Subscribe" class="btn btn-primary">
* {
box-sizing: border-box;
}
#div2 {
display: table;
width: 100%;
}
#div2 > * {
display: table-cell;
}
#div2 > input[type='email'] {
width: 80%;
}
#div2 > input[type='submit'] {
width: 20%;
}
the key is box-sizing: border-box; you can write it just for your desired elements
https://jsfiddle.net/uw4u6ta5/3/
The line feed between the two s creates a space between them on the page. You have to remove the line feed, or use this trick :
<input type="email" name="EMAIL" class="form-control" placeholder="Enter your E-mail Address"><!--
--><input type="submit" value="Subscribe" class="btn btn-primary">
Also you have to remove border because it has 2px border so it's width is 20%+80%+ 2px+2px+2px+2px(left and right for two inputs)
use
border:0;
check this updates jsfiddle please
Check this post remove spaces between inputs
You really don't need two divs wrapping your inputs for this. You need to set the div to white-space: nowrap; to keep your inputs on one line. Simply set your inputs to width: 50%; or you may choose any other combination targeting each input specifically.
#div2 {
display: block;
margin: 0 auto;
width: 100%;
white-space: nowrap;
}
input {
display: inline-block;
width: 50%;
}
If you want the input to be 80% and the button to be 20% you need to target them individually with your classes.
.form-control {
display: inline-block;
width: 80%;
margin: 0;
padding: 0;
}
.btn-primary {
width: 20%;
margin: 0 auto;
padding: 0;
}
(JSFiddle) Updated
I have a little problem with a HTML form and its submit button:
<form action="login/login.php" method="post" style="margin-top: 10px;">
<input id="login" name="username" type="text" placeholder="Nutzername" />
<input id="login" type="password" name="passwort" placeholder="Passwort" />
<input id="login" type="submit" value="Anmelden" />
</form>
CSS:
input[type=text]#login, input[type=password]#login {
border: 1px solid #ccc;
display: block;
height: 20px;
text-align: center;
width: 100%; }
input[type=submit]#login {
display: block;
height: 20px;
text-align: center;
width: 100%;
}
Result: http://jsfiddle.net/jMTT3/72/
As you can see, the button is slighty smaller than those text boxes.. What am I doing wrong?
The default setting is for width to apply to the content box (excluding padding and border). As the padding is different, the outer width is different.
You want to add:
-moz-box-sizing: border-box;
box-sizing: border-box;
to at least both of them.
Alternatively, you can set the same padding and border to achieve the same effect.
EDIT: Working Fiddle
I want to have one label that is associated with the input field. Some of the labels need to go on more than one line. However, I am not able to view the text. What I am trying to achieve is shown below:
Label 1 <input />
sub text for label 1
The code I currently have is as follows:
<div class="row">
<label for="height">Height (help text here)</label>
<input name="height" id="height" ... />
</div>
CSS:
form { width: 100%; overflow: hidden; margin-top: -20px;}
form .row { height: 100%; overflow: hidden; padding-left: 140px; width: 295px; line-height: 30px; position: relative; margin-bottom: 6px; }
form label { position: absolute; top: 0; left: 0; line-height: 32px; text-align: left; width: 110px; font-size: 14px; display: inline-block}
There are a few rows that need to be formatted like this. Thank you for any help you can provide.
<div class="row">
<label for="height">Height <br /><span>(help text here)</span></label>
<input name="height" id="height" ... />
</div>
label {
display: block;
float: left;
}
make the label a block element so you can put a br. not a good solution also but it works :P
Try this :
<div class="row">
<label for="height">Height (help text here)</label><input name="height" id="height" ... /><br/>
<label for="height">Sub text</label>
</div>
It may be a workaround to your issue, but not a perfect solution
How about:
<div class="row">
<label for="height">Height</label>
<input name="height" id="height" ... />
<label for="height" class="help">help text here</label>
</div>
And CSS:
.row label {
display: inline-block;
width: 40%;
}
.row input {
display: inline-block;
width: 50%;
margin: 0 0 0 5%;
}
.row label.help {
display: block;
}
JS Fiddle demo.