I have a validation message under the field, but I want it to be on the same line.
( Please don't judjge my Front-End skills, specially css and html =) )
now
what I want
CSS
#CHARSET "UTF-8";
#reg-form {
display: block;
width: 600px;
}
#reg-form li {
width: 250px;
display: block;
padding: 5px 5px;
}
#reg-form li label {
width: 150px;
float: left;
}
.status {
font-size: 14px;
color: red;
}
#register-user {
float: left;
margin-left: 7px;
padding: 5px 5px 5px 5px;
}
HTML
{% block main-menu %}
<div class="contentarea">
<form method="post" action="">{% csrf_token %}
<ul id="reg-form">
<li>
<label for="id_username">Username:</label>
<input id="id_username" type="text" name="username" maxlength="30" />
</li>
<div class="status"></div>
<li>
<label for="id_email">Email:</label>
<input type="text" name="email" id="id_email" />
</li>
<div class="status"></div>
<li>
<label for="id_password">Password:</label>
<input type="password" name="password" id="id_password" />
</li>
<div class="status"></div>
<li>
<label for="id_password2">Password (Again):</label>
<input type="password" name="password2" id="id_password2" />
</li>
<div class="status"></div>
</ul>
<input type="button" value="register" id="register-user"/>
</form>
</div>
{% endblock %}
You shouldn't put <div>s inside a <ul> -- it's bad syntax. (Javascript errors come with bad syntax.) Tip: check your source code with W3 validator.
Try using <span>--which is an inline element--instead of <div> (but put the spans inside the corresponding <li>s).
For example:
http://jsfiddle.net/Q7R4k/3/
Your <li>s have display: block; on them. Try changing it to display: inline or display: inline-block on .status and #reg-form li. See http://jsfiddle.net/Q7R4k/. Inline elements will by default stack to the right, while block takes up the whole horizontal line.
You'll need to have line breaks between the lis, though, to get the lis on separate lines. See http://jsfiddle.net/Q7R4k/1/.
EDIT:
See http://jsfiddle.net/Q7R4k/2/ for a version with div's directly after the inputs. Here, the labels are given display:block;, the inputs display:inline-block; (inline would work too) and .status display:inline;. Also, the width of the ul is taken out.
Related
so I am working to create this really simple website, but the problem that I keep facing is that when i put to things inside one div, I cant make them fit the container and when I zoom they keep going vertical, for example:
Here is the html:
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<div class="Form">
<form action="/action_page.php" method="post">
<fieldset class="Member">
<legend>Sign In</legend>
Sign in today for more experience <br><br>
<b>Email:</b> <br>
<input type="text" name="email" placeholder="Enter Email">
<br><br>
<b>Password:</b> <br>
<input type="password" name="password" placeholder="Password">
<br><br>
<input type="checkbox" name="remember" value="yes">remember me
<input type="submit" value="Log in">
</fieldset>
</form>
<fieldset class="Not_member">
<legend>Not a member ?</legend>
You can create an account:<br>
<i class="fa fa-sign-in" style="font-size:500%;color: grey;"></i>
</fieldset>
</div>
and here is my Css:
.Form{
border: 2px solid black;
background-color: white;
margin: 1px;
float: left;
width: 50%;
white-space: nowrap;
padding:0;
}
.Member {
width: 40%;
}
.Not_member {
width: 50%;
text-align: center;
}
fieldset {
margin:0;
float: left;
}
what i want to do is:
make each one fit half the container vertically and horizontally
make them stay horizontal and shrink with the container, so what i mean that when the window becomes smaller they become vertical, how can I stop that?
Edit: I want it like this: https://i.imgur.com/j27PQq4.jpg, and I want it to stop going down like this: https://i.imgur.com/DPwTwkD.jpg
thanks in advance
As long as your "Not a member?" is inside of its own div, you can use:
width: 100%;
and/or
height: 100%;
I think i might be missing something basic. Have been on it for few hours now and cannot make it work.
http://jsfiddle.net/x4bLtt7b/
<div class="customerInfo">
<form class="form-style">
<ul>
<li>
<label for="field1">field1</label>
<input type="text" name="field1" maxlength="100"> <span>field1 info</span>
</li>
<li>
<label for="field2">field2</label>
<input type="text" name="field2" maxlength="100"> <span>field2 info</span>
</li>
<li>
<label for="field3">field3</label>
<input type="text" name="field3" maxlength="100"> <span>field3 info</span>
</li>
<li>
<label for="field4">field4</label>
<input type="text" name="field4" maxlength="100"> <span>field4 info</span>
</li>
<li>
<label for="field5">field5</label>
<input type="text" name="field5" maxlength="100"> <span>field5 info</span>
</li>
</ul>
</form>
I just need the layout to be two columned, i.e. The field1/field2 pair should be on the same row (adjacent to each other). Same for field3/field4 pair and so on.
It seemed pretty simple to start with but i just couldn't get it to work yet. Any feedback is welcome.
Thanks
Regular CSS method:
Use this method if you need full browser support or else switch to flexbox.
Set a width for the list and display to inline-block
.form-style li {
border: 1px solid #dddddd;
border-radius: 3px;
display: inline-block;
margin-bottom: 30px;
margin-right: 5px;
padding: 9px;
width: 40%;
}
JSFiddle
Flexbox Method:
This is better but supported only by modern browsers.
.form-style ul {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
JSFiddle
Output
You can do it with this:
.form-style li {
display: inline-block;
width: 40%;
}
Adjust the width setting want you want.
FIDDLE: https://jsfiddle.net/lmgonzalves/x4bLtt7b/3/
I want to create a form so there is text on the left side and the inputs on the right, currently I am doing
<div id="labels">
<ul>
<li>The Label</li>
</ul>
</div>
<div id="inputs">
<ul>
<li><input type="text /></li>
</ul>
</div>
And the CSS
input[type=text] {
height: 14px;
}
#labels {
float: left;
}
#inputs {
float: right;
}
li {
padding-top: 4px;
padding-left: 10px;
}
// Text size is 14px
What happens is that the text and fields are not aligned perfectly (the inputs get progressively lower as I add items). I am thinking this is because not all the inputs can be 14px (I use drop downs, checkboxes, radios, etc.).
What would be the correct way to create this? I know a table would fix the problem but is that semantic?
This sort of question has been asked multiple times here in SO, you can do a simple search and find many solutions.
But here is a simple form to get you started:
HTML
<form>
<div class="line">
<label for="input">Full Name</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Company</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="nselect">Dropdown Menu</label>
<div class="input">
<select name="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="line">
<label for="input">Text 1</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Text 2</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Text 3</label>
<div class="input">
<input type="text" size="15" name="input">
</div>
</div>
</form>
CSS
form {
margin:10px 0;
}
label {
color: #404040;
float: left;
font-size: 13px;
line-height: 18px;
padding-top: 6px;
text-align: right;
width: 130px;
}
label, input, select, textarea {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 13px;
font-weight: normal;
line-height: normal;
}
input, textarea, select {
-moz-border-radius: 3px 3px 3px 3px;
border: 1px solid #CCCCCC;
color: #808080;
display: inline-block;
font-size: 13px;
height: 18px;
line-height: 18px;
padding: 4px;
width: 210px;
}
select {
height: 27px;
line-height: 27px;
}
form .input {
margin-left: 150px;
}
form .line {
margin-bottom: 18px;
}
Here is a demo: http://jsfiddle.net/5aduZ/1/
A lot of people will not agree with my use of divs to separate the form elements but through testing i found this format to be the safest and surefire way to go about it as it separates the fields cleanly, and it works just fine under IE. Plus, it is the format used by the big boys (facebook, twitter, google).
It makes sense for the label to be next to the input in the HTML - it's easier to read and more maintainable. Typical HTML for this would be:
<div class="fieldWrapper">
<label for="something">Something</label>
<input type="text" id="something" name="something">
</div>
<div class="fieldWrapper">
<label for="something">Something</label>
<input type="text" id="something" name="something">
</div>
And CSS would be:
label, input {
float:left;
}
input {
font-size:14px;
padding: 2px; // instead of using fixed height
}
label {
width: 100px; // can use JavaScript if it needs to be dynamic
padding-top: 3px; // to make the label vertically inline with the input element
}
.fieldWrapper {
clear:left;
}
If you really can't change your HTML, you could set a CSS height on the <li> tag to fix the alignment problem. But I strongly recommend you to choose one of other proposed solutions, because your HTML is very hard to read in its current state. And you should use the <label> tag.
Write this <input type="text" name="firstname" /> and set the height width and padding
At my company, way back when we first started our first web application back in 2001, we used a table.
<table class="formTable">
<tbody>
<tr>
<td><label>Name:</label></td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td><label>E-mail:/label></td>
<td><input type="text" name="email" /></td>
</tr>
</tbody>
</table>
And while this works, philosophically I don't like the approach, because as far as I am concerned, a table should hold table-ized data.
You could use CSS and DIV's, as well:
<style>
.formLabel, .formInput {
display:inline-block;
}
</style>
<div class="formField">
<div class="formLabel"><label>Name:</label></div>
<div class="formInput"><input type="text" name="name" /></div>
</div>
<div class="formField">
<div class="formLabel"><label>E-Mail:</label></div>
<div class="formInput"><input type="text" name="email" /></div>
</div>
See here: http://jsfiddle.net/9P7pg/
Or, you could avoid the use of div's all together, and just apply the display: inline-block for each label and input (or use classes). But then you will also have to remember to use a breaking space for carriage returns in between the label-field combination.
there is a special list for this actually! it's called definition list (dl) and is comprised of definition terms and definition definitions (dt/dd). i usually put the text in the dt and the input box in the dd. like this:
<form action="bla">
<dl>
<dt>Name*</dt>
<dd><input type="text" name="name" />
<dt>Email</dt>
<dd><input type="text" name="email" />
</dl>
<p><input type="submit" /></p>
</form>
I want to have my submit button to the right of my search form. But I also want to keep my label above the form field. So it's Label, then on a new line the field with the search button on the same line.
<div class="searchForm">
<form id="UserDisplayForm" method="post" action="/sponster/users/display" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
<div class="input text"><label for="UserSearchForAFriend'sPage">Search For A Friend's Page</label><input name="data[User][Search for a friend's page]" type="text" id="UserSearchForAFriend'sPage" /></div>
<div class="submit"><input type="submit" value="Search" /></div></form>
</div>
Without changing any of your markup:
#UserDisplayForm label { display: block; }
#UserDisplayForm div { display: inline-block; }
Here's a working example. I've assumed you want the styles to apply only within your form, hence I've prefixed the rules with #UserDisplayForm.
Put your <label...> and <input...> tags inside <span...> instead of <div...>
I'd do something simple like:
<... previous elements ...>
<div class="row"> <!-- this is semantically a "form row" -->
<label style="display: block" ...></label>
<input type="text"...>
<input type="submit" ...>
</div>
The simplest ting to do is to change the inner div tags to span tags and add a br break to get to the next line.. :)
<div class="searchForm">
<form id="UserDisplayForm" method="post" action="/sponster/users/display"
accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST" />
</div>
<span class="input text">
<label for="UserSearchForAFriend'sPage">Search For A Friend's Page
</label>
<br>
<input name="data[User][Search for a friend's page]" type="text"
id="UserSearchForAFriend'sPage" />
</span>
<span class="submit"><input type="submit" value="Search" /></span>
</form>
</div>
Or else you could make the label reside in a separate div tag and the textbox and button in separate span tags as shown below.
Search For A Friend's Page
Try this stylesheet:
.searchForm {
clear: both;
display: block;
width: 150px; /* whatever width you want it to be */
}
.searchForm .input {
display: block;
float: left;
margin: 0 10px 0 0;
width: 100px; /* whatever width you want it to be */
}
.searchForm .input label { display: none; /* generally people don't want their label showing when making a search field */
.searchForm .input input { display: block; ... and any other styles ... */
.searchForm .submit {
display: block;
float: right;
margin: 0 0 0 10px;
width: 30px; /* again, whatever width you want it */;
}
This is making the <div>'s float properly. You do not have to put them in <span>'s to make it work, that's just lazy coding.
Chuck in your widths in the styles to whatever you want them to be, and it should work. It really depends on the rest of your code/css.
Good luck!
I am just trying to float an unordered list left, and a set of textboxes to the right so that they are adjacent to each other and have a uniform look within a div tag. The issue is that the text boxes are to the right ... but are positioned below the ul items
.PersonLI
{
float: left;
clear: both;
width: 100px;
margin-bottom: 10px;
}
.PersonBox
{
float: right;
clear: both;
width: 99px;
margin-bottom: 10px;
}
.FirstObj
{
border: 1px solid black;
margin-left: 100px;
width: 300px;
height: 200px;
}
<div class="FirstObj">
<ul style="list-style: none;">
<li class="PersonLI">First Name:</li>
<li class="PersonLI">Last Name:</li>
<li class="PersonLI">Address:</li>
<li class="PersonLI">City:</li>
<li class="PersonLI">State:</li>
<li class="PersonLI">Zip Code:</li>
</ul>
<input id="txtFname" type="text" value="" class="PersonBox"/>
<input id="txtLname" type="text" value="" class="PersonBox"/>
<input id="txtAddr" type="text" value="" class="PersonBox"/>
<input id="txtCity" type="text" value="" class="PersonBox"/>
<input id="txtState" type="text" value="" class="PersonBox"/>
<input id="txtZip" type="text" value="" class="PersonBox"/>
</div>
Could it be that I need to NOT clear the float on the last list item?
Your markup is kind of weird. A semantic form adapting your styles would look like this:
.FirstObj ul {
list-style: none;
}
.FirstObj li {
margin-bottom: 10px;
clear: both;
}
.FirstObj label {
width: 100px;
float: left;
}
.FirstObj input {
float: right;
width: 99px
}
<div class="FirstObj">
<ul>
<li>
<label for="txtFname">First Name:</label>
<input id="txtFname" type="text" value="" />
</li><li>
<label for="txtLname">Last Name:</label>
<input id="txtLname" type="text" value="" />
</li><li>
<label for="txtAddr">Address:</label>
<input id="txtAddr" type="text" value="" />
</li><li>
<label for="txtCity">City:</label>
<input id="txtCity" type="text" value="" />
</li><li>
<label for="txtState">State:</label>
<input id="txtState" type="text" value="" />
</li><li>
<label for="txtZip">Zip Code:</label>
<input id="txtZip" type="text" value="" />
</li>
</ul>
</div>
It's alway a good idea to use labels. Here's the working version: http://jsfiddle.net/Fmzbm/
Is there any specific reason why you are not using <label> tags for these fields?
To answer your CSS question, clear:both is not needed on either of the elements if you want them side by side.
Consider changing your markup:
HTML:
First Name:
CSS:
.FirstObj label { float:left; }
.FirstObj input { float:right; }
The code hinting is jacked up, need to try some more formatting.
Demo http://jsfiddle.net/qnev2/
You may want to change the fixed width of the li CSS rule to suit your needs but also change the markup and use the more semantically correct label tag. This also avoids the float property which in my experience can lead to undesirable behaviour if the HTML is re-flowed.