How can I place form fields inline with text? - css

I'm trying to put the mailing list button on the right side of the address. I am just starting out and this has frustrated me for many days. I have been learning using the W3 school but can't quite work out how to move it. At first I was using divs but then learned more about the span element. I thought that would fix it but alas, I need help.
Just to make sure I understood, I am trying to have the mailing list button and input to the right hand of the "Visit our warehouse" text rather than have it below.
<span>
Visit our wholesale warehouse<br>
7507 Kingspointe Parkway<br>
Suite 101<br>
Orlando, FL. 32819<br>
US<br>
Phone: 407-420-<br>Directions
</span>
<!--START: FRAME_MAILLIST-->
<span class='container'>
<span class='fieldName'>
<form method="post" name="mailing" action="mailing_list.asp?action=add" onsubmit=" mailing_list();">
<label style="font—size:160%;">[frame_mailinglist]</label></span>
<span class="mailist-box">
</span>
<span class='data'>
<input type="text" name="email" value="" placeholder="Email Address" />
<input type="submit" name="www" value="[mailinglist_button]" />
<input class="clear"></span>
</span >
<input type="radio" name="subscribe" value="1" checked="checked" />
<span class="menu-text">[mailinglist_subscribe]</span>
<input type="radio" name="subscribe" value="0" />
<span class="menu-text">[mailinglist_unsubscribe]</span>
<span class="clear"></span>
</form>
</span>
</span>
</span>
<span class="clear"></span>

Best is to use div elements here. But what you are really looking for is a CSS property called flexbox.
First, here's how I would structure your HTML:
<div class="overall-container">
<div class="address-container">
/* address html goes here /*
</div>
<div class="mailing-list-container">
/* mailing list html goes here /*
</div>
</div>
Now, in your CSS you can write the following:
.overall-container {
width: 100vw; // You can adjust the width of the whole container here
display: flex;
flex-direction: row; // This is the most important part for you
justify-content: center; // Look up other options if this doesn't fit
align-items: center; // Again look up for other options
}
This will put your address container div and your mailing-list container div side by side with each other. The flex-direction property of row controls this. If you wanted them on top of each other, then set flex-direction: column.
Hope this helps. If you need more information, look up CSS flexbox on MDN.

Related

inline form parts using CSS (inline attribute)?

I want to create a simple form. The final design should be the one above, but with a responsive positioning.
So I tried to use the inline attribute of css:
<!--Name...-->
<div style="display: inline;">
<label for="vorname_patient">Vorname: </label> <br> <input type="text" name="vorname_patient" id="vorname_patient" required="" size="20" autofocus=""> <br>
<label for="nachname_patient">Nachname: </label> <br> <input type="text" name="nachname_patient" id="nachname_patient" required="" size="20">
</div>
<!--Anrede...-->
<div style="display: inline;">
<label for=anrede_patient">Anrede: </label> <br> <input type="text" name="anrede_patient" id="anrede_patient" size="20">
</div>
If i run that i will not get any inlineme parts anywhere.
i want to get this (without a table):
https://jsfiddle.net/kcd1qr1r/
What did I do wrong here? Thank you!
Inline elements must flow within their nearest block parent. So, because you changed the div containers to be inline, your label and input elements are just flowing within the body (nearest block parent). Use inline-block instead or, due to possible margin issues with that approach, you may want to try flexboxes.

Bootstrap - form elements auto layout

I have the following form, I want to have 3 items in a row.
Since it is auto generated I cant really change to much the html.
I cant have dynamic span for each column.
With the limitations I have here, is it possible to break the code bellow so Ill have 3 fields in a row?
http://fiddle.jshell.net/52VtD/446/
<div class="row-fluid">
<input id="Id" name="Id" type="hidden">
<div class="span1">
<label>
Email Address
</label>
<input class="form-control" id="Email" name="Email" type="text">
</div>
<div class="span1">
<label>
Full Name
</label>
<input class="form-control" id="FullName" name="FullName" type="text">
</div>
<div class="span1">
<label>
Active?
</label>
<input class="form-control" id="IsActive" name="IsActive" type="text">
</div>
<div class="span1">
<label>
Password
</label>
<input class="form-control" id="Password" name="Password" type="password">
</div>
<input name="Avatar.Id" type="hidden">
<div class="span1">
<label>
Upload image
</label>
<input class="form-control" id="Avatar.FileContent" name="Avatar.FileContent" placeholder="Select an image" type="file">
</div>
</div>
Sometimes, it helps not over thinking Bootstrap. Also note, this is Bootstrap 3 I'm using.
If you're looking to have "three items" in a row, including the labels, that can be created with 6 columns. 3 per label and 3 per input.
http://fiddle.jshell.net/pLSD9/1/
In this case, you don't use any of the built in form layouts like .form-inline. You use the Bootstrap grid and place your elements in it accordingly. Since Bootstrap gives it's form input elements 100% width, they'll fill the grid space.
I used the "sm" size grid so when the form gets to what Bootstrap considers a "small" size, it will stack the elements. Since JSFiddle brings the page down into windows,you might have to adjust the window size to see the grid layout.
I hope that helps!
Cheers!
You're going to break Bootstrap a lot, but if you could give the container an id and style it this way:
#form-container {
width: 700px;
}
#form-container .row-fluid .span1 {
float: left;
margin-right: 10px;
}
To get this result: http://fiddle.jshell.net/52VtD/448/

Why is my email form field too tall, and the text is centered?

From what I can tell, my form field is completely standard. The page is at http://worldcastmovie.com/login.php
The email field on the right is two lines tall, and input is centered. My code doesn't seem to reflect this, so is there another place within my site I should be looking?
Thanks in advance!
Ryan
Here's the code in question:
<div>
<label>Name:</label>
<input type='text' name='name'/>
</div>
<div>
<label>Email:</label>
<input type='text' name='email' id = 'email'/>
<div class='error'>
Please enter your email.
</div>
</div>
<div>
<label>City:</label>
<input type='text' name='city'/>
</div>
<div style='position:relative'>
<label>Desired Username:</label>
<input type='text' name='username' id='username'/>
<div class='error'>
Please choose different username.
</div>
</div>
<div>
<label>Desired Password:</label>
<input class='input' type='password' name='password' id='password'/>
<div class='error'>
Please specify different password.
</div>
</div>
<div>
<label>Confirm Password:</label>
<input class='input' type='password' name='cpassword' id='cpassword'/>
<div class='error'>
Please confirm your password.
</div>
</div>
<!--<div>
<label>Video:</label>
<input type='file' name='video' />
</div>
<div>
<input type='checkbox' name='terms' style='margin-left:12px;margin-top:20px;' id='terms' /><span style='margin-left:10px;'>I have read and agree to the <a href='terms.php'>terms and conditions</a></span>
<div class='error'>
You have to read and agree to the terms and conditions.
</div>
</div>-->
<input type='image' src='/images/register.png' id='submit'/>
</form>
It's matching the rule on #email on line 62 of style.css:
#email {
text-align: center;
color: black;
padding-top: 30px;
}
In other words: the element ID email is not used uniquely as it should, this rule is probably meant for some other element requiring the padding-top and the horizontal centering.
A simple right click and 'inspect element' would've shown you this as well.
you should make the email field left aligned currently it is centered and make the padding top to 0
#email {
text-align: left;
color: black;
padding-top: 0px;
}
You are using padding-top to make the email field look larger, I would play around with height not padding if you want it to the text to be vertical aligned to the middle and not padding-top..
#email {
text-align: left;
color: black;
height: 100px;
}

jQuery Mobile layout customization

I'm taking my first steps in jQuery Mobile and I'm getting a bit disappointed with the lack of customization it provides...
As an example, I have a simple form and I'd like to customize the layout of the form components.
This is my code:
<form id="loginForm" action="#" method="post">
<input id="rememberMe" name="rememberMe" type="checkbox"/>
<label for="rememberMe">Remember me in this computer</label>
<a id="info" href="#" data-role="button" data-icon="info" data-iconpos="notext">Info</a>
<input id="submit" type="submit" value="log in" data-inline="true"/>
</form>
See the fiddle.
Concretely I'd like:
The rememberMe checkbox to be as wide as the text inside, and the info button to be inline with the checkbox.
The "group" containing the previous checkbox and button to be aligned to the right.
The submit button to be to the right as well.
Please provide an example of how such things can be achieved...
EDIT: I'd like something like this:
Customization you require will not come from jQM but from custom css.
Usually this could be easily done with jQuery Mobile grids but they are not that flexible. So you need a custom solution.
A div around every element is needed because jQM recreates every element with new style and unless we have a parent div everything will go to hell.
Working example: http://jsfiddle.net/Gajotres/8NB22/
HTML :
<form id="loginForm" action="..." method="post">
<div class="row">
<div class="inline-mid">
<a id="info" href="..." data-role="button" data-icon="info" data-iconpos="notext" class="middle-button">Info</a>
</div>
<div class="inline-left">
<input id="rememberMe" name="rememberMe" type="checkbox"/>
<label for="rememberMe">Remember me in this computer</label>
</div>
</div>
<div class="row">
<div class="inline-left">
<input id="submit" type="submit" value="log in" data-inline="true"/>
</div>
</div>
</form>
CSS :
.row {
min-width: 400px;
width: 400px;
}
.inline-left, .inline-mid , .row {
position: relative;
float: right;
}
.inline-mid {
margin-left: 10px;
padding-top: 5px;
}
This can be achieved using ui-grid classes.
Working Demo
Markup
<form id="loginForm" action="..." method="post">
<div class=ui-grid-a>
<div class=ui-block-a>
<input id="rememberMe" name="rememberMe" type="checkbox"/>
<label for="rememberMe" data-inline="true">Remember me in this computer</label>
</div>
<div class=ui-block-b>
<a id="info" href="..." data-role="button" data-icon="info" data-iconpos="notext">Info</a>
</div>
</div>
<div class=ui-grid-solo>
<input id="submit" type="submit" value="log in" data-inline="true"/>
</div>
</form>
Override CSS
.ui-block-a { width: 95% !important; text-align: right !important; }
.ui-block-b { width: 5% !important; padding-top: 5px !important; }
.ui-grid-solo { text-align: right !important; }
Layout should never be primarily the responsibility of Javascript code, as such you shouldn't blame jQuery Mobile for this.
Customization for different screen sizes should be done with CSS Media Queries instead, click the link for more examples than you'll ever need.

Centering Login Form Bootstrap

I'm having some trouble centering my Bootstrap login form.
Centering
I've tried many different ways of centering the form. The whole div is centered with the col-md-offset class, but I don't understand how to make the content (the form inputs) center in the div itself. For the text I know you can use text align, and for content I usually use margin: 0, auto;, but that isn't working for the form.
I also want to center it vertically, if possible, but given what I have researched on the internet, it seems very difficult to do so, and there is nothing I've found in the bootstrap references explaining how to do so.
Another random question, is why on the form are the left corners right angles whereas the right corners are rounded? Even when I change the corner-radius it only effects the right corners.
CODE:
http://jsbin.com/gamufagehu/edit?html
If you want to place the form in the center of the screen then use position: absolute and don't use the grid. You can use media queries to control other factors depending on what you ultimately want on smaller or larger viewports.
Also, you're use of input-group (Docs) doesn't really make sense and is the reason you're having adverse styling on your inputs (one being shorter than the other and the border-radius). Use form-group instead.
.myForm {
min-width: 500px;
position: absolute;
text-align: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2.5rem
}
#media (max-width: 500px) {
.myForm {
min-width: 90%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" id="logoText">Test</a>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-right" method="post">
<div class="form-group">
<input type="email" class="form-control" name="loginemail" id="loginemail" placeholder="email" />
</div>
<div class="form-group">
<input type="password" class="form-control" name="loginpassword" placeholder="password" />
</div>
<input type="submit" name="submit" class="btn btn-default" value="Log In" />
</form>
</div>
</div>
</div>
<div class="container">
<form class="myForm" method="post">
<div class="form-group">
<label for="email">Email</label>
<input class="form-control input-lg" type="email" name="email" id="email" placeholder="email" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input class="form-control input-lg" type="password" name="password" placeholder="password" />
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-success btn-lg" value="Sign Up" />
</div>
</form>
</div>
you can use
.input-group{
margin:0px auto;
}
here is a bin working fine with same rules.
the reason you input box has right-top and right-bottom radius but not the left-top and left-right is that it is excepting something on the left of it, like some button or something, let me throw a link to make it understand better. go to amount field on this link. we can always overwrite the bootstrap rules but it is not recommended when there is a problem with use of classes, good luck.
well well well, sorry for frequent edits, but check out the use of .input-group class, i guess you messed it up there
I would recommend using column layout in a proper way.
You could wrap your login elements in divs that are based on column layout grid with length 4 and offset equal 4 too. You would get elements centered on the page and fully responsible. Then you could style elements inside them as in normal form groups.
I'd also recommend not using input groups as they are designed to group inputs as the name suggests and this is the reason you have square corners on left side of the inputs (for other inputs on left to seamlessly integrate into one input group) :)
Just put every form row inside that structure:
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="input-group">(...)</div>
</div>
</div>
Look here:
JSBin example
Good note for future use of any library, including bootstrap - it is a good way to read all examples of use of particular library and its documentation, because otherwise you could end up overwriting functionalities that are already provided within it :)
You can use this:
.input-group {
position: relative;
border-collapse: separate;
display: block;
}

Resources